Skip to content

Commit

Permalink
move target from body to uri
Browse files Browse the repository at this point in the history
  • Loading branch information
lhns committed Mar 31, 2022
1 parent 001a1f2 commit d5a0072
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
A vendor-neutral and modular way to deploy your App with `curl` from a CI/CD-Pipeline to your Container Cluster of
choice.

## Example

```shell
curl -sSf -H "Authorization: Bearer <secret>" -d "{
\"resource\": \"my-app\",
\"value\": \"ghcr.io/my/app:1.0.0\"
}" http:https://localhost:8080/deploy/<target>
```

## Supported

- Docker Swarm via Portainer API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package de.lolhens.kubedeploy.model

import cats.syntax.functor._
import de.lolhens.kubedeploy.model.DeployRequest.Locator
import de.lolhens.kubedeploy.model.DeployTarget.DeployTargetId
import io.circe.generic.semiauto._
import io.circe.{Codec, Decoder, Encoder, Json}

case class DeployRequest(
target: DeployTargetId,
resource: String,
value: String,
locator: Option[Locator],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import de.lolhens.http4s.errors.{ErrorResponseEncoder, ErrorResponseLogger}
import de.lolhens.kubedeploy.JsonOf
import de.lolhens.kubedeploy.deploy.PortainerDeploy
import de.lolhens.kubedeploy.model.DeployResult.DeployFailure
import de.lolhens.kubedeploy.model.DeployTarget.DeployTargetId
import de.lolhens.kubedeploy.model.{DeployRequest, DeployResult, DeployTarget}
import de.lolhens.kubedeploy.repo.DeployTargetRepo
import org.http4s.client.Client
Expand All @@ -29,15 +30,15 @@ class KubedeployRoutes(client: Client[IO], deployTargetRepo: DeployTargetRepo[IO

def toRoutes: HttpRoutes[IO] = HttpRoutes.of {
case GET -> Root / "health" => Ok()
case request@POST -> Root / "deploy" =>
case request@POST -> Root / "deploy" / target =>
(for {
deployRequest <- request.as[JsonOf[DeployRequest]].map(_.value).orErrorResponse(BadRequest)
deployTarget <- OptionT(deployTargetRepo.get(deployRequest.target))
deployTarget <- OptionT(deployTargetRepo.get(DeployTargetId(target)))
.toRight(DeployFailure("target not found")).toErrorResponse(NotFound)
_ <- EitherT.fromOption[IO](request.headers.get[Authorization].collect {
case Authorization(Credentials.Token(AuthScheme.Bearer, secret)) if secret == deployTarget.secret.value =>
()
}, "not authorized").toErrorResponse(Unauthorized)
deployRequest <- request.as[JsonOf[DeployRequest]].map(_.value).orErrorResponse(BadRequest)
deploy <- IO(deployTarget match {
case DeployTarget(_, _, Some(portainerDeployTarget)) =>
new PortainerDeploy(client, portainerDeployTarget)
Expand Down

0 comments on commit d5a0072

Please sign in to comment.