From 50653548bec33608c7a431da7ff70aba0322c110 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Thu, 27 Jun 2024 21:54:00 +0200 Subject: [PATCH] wip: space --- flake.nix | 2 +- go.mod | 3 + go.sum | 11 + internal/manager/manager.go | 9 +- internal/space/client.gen.go | 1685 ++++++++++++++++++++++++++++++++++ internal/space/space.go | 179 ++++ nix/module.nix | 1 + 7 files changed, 1888 insertions(+), 2 deletions(-) create mode 100644 internal/space/client.gen.go create mode 100644 internal/space/space.go diff --git a/flake.nix b/flake.nix index 64d6fdc..9da8b6f 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ ./main.go ]; }; - vendorHash = "sha256-9qObgfXvMkwE+1BVZNQXVhKhL6LqMqyIUhGnXf8q9SI="; + vendorHash = "sha256-Gt1FQWHp8yfSxS6IztRaQN07HjQg7qR9OOTA5oXpXdk="; ldflags = [ "-X github.com/nlewo/comin/cmd.version=${version}" ]; diff --git a/go.mod b/go.mod index bd40102..66bff6c 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,14 @@ require ( dario.cat/mergo v1.0.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect + github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cloudflare/circl v1.3.6 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-chi/chi/v5 v5.0.12 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect @@ -30,6 +32,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/oapi-codegen/runtime v1.1.1 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.19.0 // indirect diff --git a/go.sum b/go.sum index 5f95a38..9e0db25 100644 --- a/go.sum +++ b/go.sum @@ -6,14 +6,18 @@ github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5 github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE= github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= +github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= +github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df h1:GSoSVRLoBaFpOOds6QyY1L8AX7uoY+Ln3BHc22W40X0= github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -41,6 +45,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= +github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= +github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= @@ -83,6 +89,7 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -99,6 +106,8 @@ github.com/mmcloughlin/avo v0.5.0/go.mod h1:ChHFdoV7ql95Wi7vuq2YT1bwCJqiWdZrQ1im github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro= +github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= @@ -167,10 +176,12 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/internal/manager/manager.go b/internal/manager/manager.go index e3f7d34..021db49 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -10,6 +10,7 @@ import ( "github.com/nlewo/comin/internal/profile" "github.com/nlewo/comin/internal/prometheus" "github.com/nlewo/comin/internal/repository" + "github.com/nlewo/comin/internal/space" "github.com/nlewo/comin/internal/store" "github.com/nlewo/comin/internal/utils" "github.com/sirupsen/logrus" @@ -60,7 +61,10 @@ type Manager struct { triggerDeploymentCh chan generation.Generation prometheus prometheus.Prometheus - storage store.Store + + storage store.Store + + space space.Space } func New(r repository.Repository, s store.Store, p prometheus.Prometheus, path, dir, hostname, machineId string) Manager { @@ -157,6 +161,7 @@ func (m Manager) onDeployment(ctx context.Context, deploymentResult deployment.D } m.needToReboot = utils.NeedToReboot() m.prometheus.SetHostInfo(m.needToReboot) + m.space.AgentUpdate(m.needToReboot, m.deployment) return m } @@ -217,6 +222,8 @@ func (m Manager) Run() { m.needToReboot = utils.NeedToReboot() m.prometheus.SetHostInfo(m.needToReboot) + m.space = space.New(m.hostname, m.machineId) + m.space.AgentUpdate(m.needToReboot, m.deployment) for { select { diff --git a/internal/space/client.gen.go b/internal/space/client.gen.go new file mode 100644 index 0000000..53f5db4 --- /dev/null +++ b/internal/space/client.gen.go @@ -0,0 +1,1685 @@ +// Package space provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/deepmap/oapi-codegen/v2 version 2.1.0 DO NOT EDIT. +package space + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" + + "github.com/oapi-codegen/runtime" + openapi_types "github.com/oapi-codegen/runtime/types" +) + +// Agent defines model for Agent. +type Agent struct { + CreatedAt time.Time `json:"createdAt"` + DeletedAt time.Time `json:"deletedAt"` + Deployment *Deployment `json:"deployment,omitempty"` + DeploymentID *openapi_types.UUID `json:"deploymentID,omitempty"` + Id openapi_types.UUID `gorm:"type:uuid;primaryKey" json:"id"` + MachineID string `json:"machineID"` + Name string `json:"name"` + NeedToReboot *bool `json:"needToReboot,omitempty"` + ProjectID string `json:"projectID"` + UpdatedAt time.Time `json:"updatedAt"` +} + +// AgentPatchRequest defines model for AgentPatchRequest. +type AgentPatchRequest struct { + DeploymentID *openapi_types.UUID `json:"deploymentID,omitempty"` + NeedToReboot *bool `json:"needToReboot,omitempty"` +} + +// Agents defines model for Agents. +type Agents = []Agent + +// ApiKey defines model for ApiKey. +type ApiKey struct { + CreatedAt time.Time `json:"createdAt"` + DeletedAt time.Time `json:"deletedAt"` + Id openapi_types.UUID `gorm:"type:uuid;primaryKey" json:"id"` + Name string `json:"name"` + ProjectID string `json:"projectID"` + UpdatedAt time.Time `json:"updatedAt"` +} + +// ApiKeys defines model for ApiKeys. +type ApiKeys = []ApiKey + +// Deployment defines model for Deployment. +type Deployment struct { + Agent *Agent `json:"agent,omitempty"` + AgentID openapi_types.UUID `json:"agentID"` + BranchName string `json:"branchName"` + CommitDate time.Time `json:"commitDate"` + CommitID string `json:"commitID"` + CommitMessage string `json:"commitMessage"` + CreatedAt time.Time `json:"createdAt"` + DeletedAt time.Time `json:"deletedAt"` + EndedAt time.Time `json:"endedAt"` + Id openapi_types.UUID `gorm:"type:uuid;primaryKey" json:"id"` + Operation string `json:"operation"` + ProjectID string `json:"projectID"` + RemoteName string `json:"remoteName"` + RemoteUrl string `json:"remoteUrl"` + StartedAt time.Time `json:"startedAt"` + Status string `json:"status"` + UpdatedAt time.Time `json:"updatedAt"` +} + +// Deployments defines model for Deployments. +type Deployments = []Deployment + +// Login defines model for Login. +type Login struct { + Password string `json:"password"` + Username string `json:"username"` +} + +// NewAgent defines model for NewAgent. +type NewAgent struct { + MachineID string `json:"machineID"` + Name string `json:"name"` +} + +// NewApiKey defines model for NewApiKey. +type NewApiKey struct { + Name string `json:"name"` +} + +// NewDeployment defines model for NewDeployment. +type NewDeployment struct { + Agent *Agent `json:"agent,omitempty"` + AgentID openapi_types.UUID `json:"agentID"` + BranchName string `json:"branchName"` + CommitDate time.Time `json:"commitDate"` + CommitID string `json:"commitID"` + CommitMessage string `json:"commitMessage"` + EndedAt time.Time `json:"endedAt"` + Id openapi_types.UUID `gorm:"type:uuid;primaryKey" json:"id"` + Operation string `json:"operation"` + RemoteName string `json:"remoteName"` + RemoteUrl string `json:"remoteUrl"` + StartedAt time.Time `json:"startedAt"` + Status string `json:"status"` +} + +// User defines model for User. +type User struct { + Hash *string `json:"hash,omitempty"` + Id openapi_types.UUID `json:"id"` + Name string `json:"name"` + ProjectID string `json:"projectID"` +} + +// GetAgentsParams defines parameters for GetAgents. +type GetAgentsParams struct { + // MachineID Filter by machineID + MachineID *string `form:"machineID,omitempty" json:"machineID,omitempty"` +} + +// GetDeploymentsParams defines parameters for GetDeployments. +type GetDeploymentsParams struct { + // AgentID Filter by agentID + AgentID *openapi_types.UUID `form:"agentID,omitempty" json:"agentID,omitempty"` +} + +// PostAgentsJSONRequestBody defines body for PostAgents for application/json ContentType. +type PostAgentsJSONRequestBody = NewAgent + +// PatchAgentJSONRequestBody defines body for PatchAgent for application/json ContentType. +type PatchAgentJSONRequestBody = AgentPatchRequest + +// PutAgentJSONRequestBody defines body for PutAgent for application/json ContentType. +type PutAgentJSONRequestBody = NewAgent + +// PostApiKeysJSONRequestBody defines body for PostApiKeys for application/json ContentType. +type PostApiKeysJSONRequestBody = NewApiKey + +// PostDeploymentsJSONRequestBody defines body for PostDeployments for application/json ContentType. +type PostDeploymentsJSONRequestBody = NewDeployment + +// PostLoginJSONRequestBody defines body for PostLogin for application/json ContentType. +type PostLoginJSONRequestBody = Login + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // GetAgents request + GetAgents(ctx context.Context, params *GetAgentsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PostAgentsWithBody request with any body + PostAgentsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostAgents(ctx context.Context, body PostAgentsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetAgentById request + GetAgentById(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PatchAgentWithBody request with any body + PatchAgentWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PatchAgent(ctx context.Context, id openapi_types.UUID, body PatchAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PutAgentWithBody request with any body + PutAgentWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PutAgent(ctx context.Context, id string, body PutAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetApiKeys request + GetApiKeys(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PostApiKeysWithBody request with any body + PostApiKeysWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostApiKeys(ctx context.Context, body PostApiKeysJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetDeployments request + GetDeployments(ctx context.Context, params *GetDeploymentsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PostDeploymentsWithBody request with any body + PostDeploymentsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostDeployments(ctx context.Context, body PostDeploymentsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetDeploymentById request + GetDeploymentById(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PostLoginWithBody request with any body + PostLoginWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostLogin(ctx context.Context, body PostLoginJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) GetAgents(ctx context.Context, params *GetAgentsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetAgentsRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostAgentsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostAgentsRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostAgents(ctx context.Context, body PostAgentsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostAgentsRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetAgentById(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetAgentByIdRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PatchAgentWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPatchAgentRequestWithBody(c.Server, id, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PatchAgent(ctx context.Context, id openapi_types.UUID, body PatchAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPatchAgentRequest(c.Server, id, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PutAgentWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPutAgentRequestWithBody(c.Server, id, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PutAgent(ctx context.Context, id string, body PutAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPutAgentRequest(c.Server, id, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetApiKeys(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetApiKeysRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostApiKeysWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostApiKeysRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostApiKeys(ctx context.Context, body PostApiKeysJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostApiKeysRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetDeployments(ctx context.Context, params *GetDeploymentsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDeploymentsRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostDeploymentsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostDeploymentsRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostDeployments(ctx context.Context, body PostDeploymentsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostDeploymentsRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetDeploymentById(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDeploymentByIdRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostLoginWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostLoginRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostLogin(ctx context.Context, body PostLoginJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostLoginRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewGetAgentsRequest generates requests for GetAgents +func NewGetAgentsRequest(server string, params *GetAgentsParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/agents") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if params.MachineID != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "machineID", runtime.ParamLocationQuery, *params.MachineID); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPostAgentsRequest calls the generic PostAgents builder with application/json body +func NewPostAgentsRequest(server string, body PostAgentsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostAgentsRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostAgentsRequestWithBody generates requests for PostAgents with any type of body +func NewPostAgentsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/agents") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetAgentByIdRequest generates requests for GetAgentById +func NewGetAgentByIdRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/agents/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPatchAgentRequest calls the generic PatchAgent builder with application/json body +func NewPatchAgentRequest(server string, id openapi_types.UUID, body PatchAgentJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPatchAgentRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewPatchAgentRequestWithBody generates requests for PatchAgent with any type of body +func NewPatchAgentRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/agents/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PATCH", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewPutAgentRequest calls the generic PutAgent builder with application/json body +func NewPutAgentRequest(server string, id string, body PutAgentJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPutAgentRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewPutAgentRequestWithBody generates requests for PutAgent with any type of body +func NewPutAgentRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/agents/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PUT", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetApiKeysRequest generates requests for GetApiKeys +func NewGetApiKeysRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api-keys") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPostApiKeysRequest calls the generic PostApiKeys builder with application/json body +func NewPostApiKeysRequest(server string, body PostApiKeysJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostApiKeysRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostApiKeysRequestWithBody generates requests for PostApiKeys with any type of body +func NewPostApiKeysRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api-keys") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetDeploymentsRequest generates requests for GetDeployments +func NewGetDeploymentsRequest(server string, params *GetDeploymentsParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/deployments") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if params.AgentID != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "agentID", runtime.ParamLocationQuery, *params.AgentID); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPostDeploymentsRequest calls the generic PostDeployments builder with application/json body +func NewPostDeploymentsRequest(server string, body PostDeploymentsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostDeploymentsRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostDeploymentsRequestWithBody generates requests for PostDeployments with any type of body +func NewPostDeploymentsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/deployments") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetDeploymentByIdRequest generates requests for GetDeploymentById +func NewGetDeploymentByIdRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/deployments/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPostLoginRequest calls the generic PostLogin builder with application/json body +func NewPostLoginRequest(server string, body PostLoginJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostLoginRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostLoginRequestWithBody generates requests for PostLogin with any type of body +func NewPostLoginRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/login") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // GetAgentsWithResponse request + GetAgentsWithResponse(ctx context.Context, params *GetAgentsParams, reqEditors ...RequestEditorFn) (*GetAgentsResponse, error) + + // PostAgentsWithBodyWithResponse request with any body + PostAgentsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostAgentsResponse, error) + + PostAgentsWithResponse(ctx context.Context, body PostAgentsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostAgentsResponse, error) + + // GetAgentByIdWithResponse request + GetAgentByIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetAgentByIdResponse, error) + + // PatchAgentWithBodyWithResponse request with any body + PatchAgentWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PatchAgentResponse, error) + + PatchAgentWithResponse(ctx context.Context, id openapi_types.UUID, body PatchAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*PatchAgentResponse, error) + + // PutAgentWithBodyWithResponse request with any body + PutAgentWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutAgentResponse, error) + + PutAgentWithResponse(ctx context.Context, id string, body PutAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*PutAgentResponse, error) + + // GetApiKeysWithResponse request + GetApiKeysWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetApiKeysResponse, error) + + // PostApiKeysWithBodyWithResponse request with any body + PostApiKeysWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostApiKeysResponse, error) + + PostApiKeysWithResponse(ctx context.Context, body PostApiKeysJSONRequestBody, reqEditors ...RequestEditorFn) (*PostApiKeysResponse, error) + + // GetDeploymentsWithResponse request + GetDeploymentsWithResponse(ctx context.Context, params *GetDeploymentsParams, reqEditors ...RequestEditorFn) (*GetDeploymentsResponse, error) + + // PostDeploymentsWithBodyWithResponse request with any body + PostDeploymentsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostDeploymentsResponse, error) + + PostDeploymentsWithResponse(ctx context.Context, body PostDeploymentsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostDeploymentsResponse, error) + + // GetDeploymentByIdWithResponse request + GetDeploymentByIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetDeploymentByIdResponse, error) + + // PostLoginWithBodyWithResponse request with any body + PostLoginWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostLoginResponse, error) + + PostLoginWithResponse(ctx context.Context, body PostLoginJSONRequestBody, reqEditors ...RequestEditorFn) (*PostLoginResponse, error) +} + +type GetAgentsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Agents +} + +// Status returns HTTPResponse.Status +func (r GetAgentsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetAgentsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PostAgentsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *Agent +} + +// Status returns HTTPResponse.Status +func (r PostAgentsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostAgentsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetAgentByIdResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Agent +} + +// Status returns HTTPResponse.Status +func (r GetAgentByIdResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetAgentByIdResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PatchAgentResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Agent +} + +// Status returns HTTPResponse.Status +func (r PatchAgentResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PatchAgentResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PutAgentResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *Agent +} + +// Status returns HTTPResponse.Status +func (r PutAgentResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PutAgentResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetApiKeysResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *ApiKeys +} + +// Status returns HTTPResponse.Status +func (r GetApiKeysResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetApiKeysResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PostApiKeysResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *ApiKey +} + +// Status returns HTTPResponse.Status +func (r PostApiKeysResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostApiKeysResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetDeploymentsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Deployments +} + +// Status returns HTTPResponse.Status +func (r GetDeploymentsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDeploymentsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PostDeploymentsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *Deployment +} + +// Status returns HTTPResponse.Status +func (r PostDeploymentsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostDeploymentsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetDeploymentByIdResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Deployment +} + +// Status returns HTTPResponse.Status +func (r GetDeploymentByIdResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDeploymentByIdResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PostLoginResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *User +} + +// Status returns HTTPResponse.Status +func (r PostLoginResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostLoginResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// GetAgentsWithResponse request returning *GetAgentsResponse +func (c *ClientWithResponses) GetAgentsWithResponse(ctx context.Context, params *GetAgentsParams, reqEditors ...RequestEditorFn) (*GetAgentsResponse, error) { + rsp, err := c.GetAgents(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetAgentsResponse(rsp) +} + +// PostAgentsWithBodyWithResponse request with arbitrary body returning *PostAgentsResponse +func (c *ClientWithResponses) PostAgentsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostAgentsResponse, error) { + rsp, err := c.PostAgentsWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostAgentsResponse(rsp) +} + +func (c *ClientWithResponses) PostAgentsWithResponse(ctx context.Context, body PostAgentsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostAgentsResponse, error) { + rsp, err := c.PostAgents(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostAgentsResponse(rsp) +} + +// GetAgentByIdWithResponse request returning *GetAgentByIdResponse +func (c *ClientWithResponses) GetAgentByIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetAgentByIdResponse, error) { + rsp, err := c.GetAgentById(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetAgentByIdResponse(rsp) +} + +// PatchAgentWithBodyWithResponse request with arbitrary body returning *PatchAgentResponse +func (c *ClientWithResponses) PatchAgentWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PatchAgentResponse, error) { + rsp, err := c.PatchAgentWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePatchAgentResponse(rsp) +} + +func (c *ClientWithResponses) PatchAgentWithResponse(ctx context.Context, id openapi_types.UUID, body PatchAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*PatchAgentResponse, error) { + rsp, err := c.PatchAgent(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePatchAgentResponse(rsp) +} + +// PutAgentWithBodyWithResponse request with arbitrary body returning *PutAgentResponse +func (c *ClientWithResponses) PutAgentWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutAgentResponse, error) { + rsp, err := c.PutAgentWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePutAgentResponse(rsp) +} + +func (c *ClientWithResponses) PutAgentWithResponse(ctx context.Context, id string, body PutAgentJSONRequestBody, reqEditors ...RequestEditorFn) (*PutAgentResponse, error) { + rsp, err := c.PutAgent(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePutAgentResponse(rsp) +} + +// GetApiKeysWithResponse request returning *GetApiKeysResponse +func (c *ClientWithResponses) GetApiKeysWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetApiKeysResponse, error) { + rsp, err := c.GetApiKeys(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetApiKeysResponse(rsp) +} + +// PostApiKeysWithBodyWithResponse request with arbitrary body returning *PostApiKeysResponse +func (c *ClientWithResponses) PostApiKeysWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostApiKeysResponse, error) { + rsp, err := c.PostApiKeysWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostApiKeysResponse(rsp) +} + +func (c *ClientWithResponses) PostApiKeysWithResponse(ctx context.Context, body PostApiKeysJSONRequestBody, reqEditors ...RequestEditorFn) (*PostApiKeysResponse, error) { + rsp, err := c.PostApiKeys(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostApiKeysResponse(rsp) +} + +// GetDeploymentsWithResponse request returning *GetDeploymentsResponse +func (c *ClientWithResponses) GetDeploymentsWithResponse(ctx context.Context, params *GetDeploymentsParams, reqEditors ...RequestEditorFn) (*GetDeploymentsResponse, error) { + rsp, err := c.GetDeployments(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDeploymentsResponse(rsp) +} + +// PostDeploymentsWithBodyWithResponse request with arbitrary body returning *PostDeploymentsResponse +func (c *ClientWithResponses) PostDeploymentsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostDeploymentsResponse, error) { + rsp, err := c.PostDeploymentsWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostDeploymentsResponse(rsp) +} + +func (c *ClientWithResponses) PostDeploymentsWithResponse(ctx context.Context, body PostDeploymentsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostDeploymentsResponse, error) { + rsp, err := c.PostDeployments(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostDeploymentsResponse(rsp) +} + +// GetDeploymentByIdWithResponse request returning *GetDeploymentByIdResponse +func (c *ClientWithResponses) GetDeploymentByIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetDeploymentByIdResponse, error) { + rsp, err := c.GetDeploymentById(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDeploymentByIdResponse(rsp) +} + +// PostLoginWithBodyWithResponse request with arbitrary body returning *PostLoginResponse +func (c *ClientWithResponses) PostLoginWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostLoginResponse, error) { + rsp, err := c.PostLoginWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostLoginResponse(rsp) +} + +func (c *ClientWithResponses) PostLoginWithResponse(ctx context.Context, body PostLoginJSONRequestBody, reqEditors ...RequestEditorFn) (*PostLoginResponse, error) { + rsp, err := c.PostLogin(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostLoginResponse(rsp) +} + +// ParseGetAgentsResponse parses an HTTP response from a GetAgentsWithResponse call +func ParseGetAgentsResponse(rsp *http.Response) (*GetAgentsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetAgentsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Agents + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePostAgentsResponse parses an HTTP response from a PostAgentsWithResponse call +func ParsePostAgentsResponse(rsp *http.Response) (*PostAgentsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostAgentsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest Agent + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + +// ParseGetAgentByIdResponse parses an HTTP response from a GetAgentByIdWithResponse call +func ParseGetAgentByIdResponse(rsp *http.Response) (*GetAgentByIdResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetAgentByIdResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Agent + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePatchAgentResponse parses an HTTP response from a PatchAgentWithResponse call +func ParsePatchAgentResponse(rsp *http.Response) (*PatchAgentResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PatchAgentResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Agent + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePutAgentResponse parses an HTTP response from a PutAgentWithResponse call +func ParsePutAgentResponse(rsp *http.Response) (*PutAgentResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PutAgentResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest Agent + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + +// ParseGetApiKeysResponse parses an HTTP response from a GetApiKeysWithResponse call +func ParseGetApiKeysResponse(rsp *http.Response) (*GetApiKeysResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetApiKeysResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest ApiKeys + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePostApiKeysResponse parses an HTTP response from a PostApiKeysWithResponse call +func ParsePostApiKeysResponse(rsp *http.Response) (*PostApiKeysResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostApiKeysResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest ApiKey + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + +// ParseGetDeploymentsResponse parses an HTTP response from a GetDeploymentsWithResponse call +func ParseGetDeploymentsResponse(rsp *http.Response) (*GetDeploymentsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDeploymentsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Deployments + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePostDeploymentsResponse parses an HTTP response from a PostDeploymentsWithResponse call +func ParsePostDeploymentsResponse(rsp *http.Response) (*PostDeploymentsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostDeploymentsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest Deployment + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + +// ParseGetDeploymentByIdResponse parses an HTTP response from a GetDeploymentByIdWithResponse call +func ParseGetDeploymentByIdResponse(rsp *http.Response) (*GetDeploymentByIdResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDeploymentByIdResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Deployment + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePostLoginResponse parses an HTTP response from a PostLoginWithResponse call +func ParsePostLoginResponse(rsp *http.Response) (*PostLoginResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostLoginResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest User + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} diff --git a/internal/space/space.go b/internal/space/space.go new file mode 100644 index 0000000..05d69f3 --- /dev/null +++ b/internal/space/space.go @@ -0,0 +1,179 @@ +package space + +import ( + "context" + "fmt" + "github.com/google/uuid" + "github.com/nlewo/comin/internal/deployment" + "github.com/sirupsen/logrus" + "net/http" + "os" + "time" +) + +type Space struct { + url string + apiKey string + agentName string + agentMachineID string + agentID *uuid.UUID + client *ClientWithResponses +} + +func New(agentName, agentMachineID string) Space { + apiKeyFilepath := os.Getenv("COMIN_SPACE_API_KEY_FILEPATH") + apiKey, err := os.ReadFile(apiKeyFilepath) + if err != nil { + logrus.Errorf("space: could not read the password in the file %s: %s", apiKeyFilepath, err) + } + url := os.Getenv("COMIN_SPACE_URL") + return Space{ + url: url, + apiKey: string(apiKey), + agentName: agentName, + agentMachineID: agentMachineID, + } +} + +func (s *Space) agentRegister(name, machineID string) error { + if s.client == nil { + hc := http.Client{} + reqEditor := func(ctx context.Context, req *http.Request) error { + req.Header.Set("Authorization", "token "+s.apiKey) + return nil + } + c, err := NewClientWithResponses(s.url+"/api", WithHTTPClient(&hc), WithRequestEditorFn(reqEditor)) + if err != nil { + return fmt.Errorf("space: failed to NewClientWithResponses: %s", err) + } + s.client = c + } + if s.agentID != nil { + return nil + } + logrus.Infof("space: registering the agent with name %s and machineID %s", s.agentName, s.agentMachineID) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + resp, err := s.client.GetAgentsWithResponse(ctx, &GetAgentsParams{MachineID: &s.agentMachineID}) + if err != nil { + return fmt.Errorf("space: failed to GetAgentsWithResponse: %s", err) + } + if resp.StatusCode() != http.StatusOK { + return fmt.Errorf("space: expected HTTP 200 but received %d", resp.StatusCode()) + } + agents := *resp.JSON200 + if len(agents) == 1 { + s.agentID = &agents[0].Id + } else { + newAgent := NewAgent{ + Name: name, + MachineID: machineID, + } + resp, err := s.client.PostAgentsWithResponse(ctx, newAgent) + if err != nil { + return fmt.Errorf("space: failed to PostAgentsWithResponse: %s", err) + } + if resp.StatusCode() != http.StatusCreated { + return fmt.Errorf("space: expected HTTP 201 but received %d", resp.StatusCode()) + } + s.agentID = &resp.JSON201.Id + } + return nil +} + +func (s *Space) deploymentRegister(ctx context.Context, d deployment.Deployment) error { + resp, err := s.client.GetDeploymentById(ctx, d.UUID) + if err != nil { + return err + } + if resp.StatusCode == http.StatusOK { + return nil + } else if resp.StatusCode == http.StatusNotFound { + uuidStr, _ := uuid.Parse(d.UUID) + body := PostDeploymentsJSONRequestBody{ + Id: uuidStr, + AgentID: *s.agentID, + CommitID: d.Generation.SelectedCommitId, + CommitMessage: d.Generation.SelectedCommitMsg, + RemoteName: d.Generation.SelectedRemoteName, + RemoteUrl: d.Generation.SelectedRemoteUrl, + BranchName: d.Generation.SelectedBranchName, + Operation: d.Operation, + Status: deployment.StatusToString(d.Status), + EndedAt: d.EndAt, + } + _, err = s.client.PostDeploymentsWithResponse(ctx, body) + if err != nil { + return err + } + } + return nil +} + +func (s *Space) AgentNeedToReboot(needToReboot bool) { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + patchAgent := AgentPatchRequest{ + NeedToReboot: &needToReboot, + } + logrus.Debugf("space: PatchAgentWithResponse(%s, %#v)", s.agentID.String(), patchAgent) + respPatch, err := s.client.PatchAgentWithResponse(ctx, *s.agentID, patchAgent) + if err != nil { + logrus.Error(err) + return + } + if respPatch.StatusCode() != http.StatusOK { + logrus.Errorf("space: expected HTTP 200 while patching the agent but received %d", respPatch.StatusCode()) + return + } +} + +func (s *Space) AgentUpdate(needToReboot bool, d deployment.Deployment) { + if err := s.agentRegister(s.agentName, s.agentMachineID); err != nil { + logrus.Errorf("space: fail to update the agent: %s", err) + return + } + logrus.Infof("space: updating the agent with name %s and machineID %s", s.agentName, s.agentMachineID) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + newAgent := NewAgent{ + Name: s.agentName, + MachineID: s.agentMachineID, + } + + logrus.Debugf("space: PutAgentWithResponse(%s, %#v)", s.agentID.String(), newAgent) + resp, err := s.client.PutAgentWithResponse(ctx, s.agentID.String(), newAgent) + if err != nil { + logrus.Fatal(err) + return + } + if resp.StatusCode() != http.StatusCreated { + logrus.Errorf("space: expected HTTP 201 while updating the agent but received %d", resp.StatusCode()) + return + } + + var uuidStrPtr *uuid.UUID + if err := s.deploymentRegister(ctx, d); err != nil { + logrus.Errorf("space: failed to register the deployment %s: %s", d.UUID, err) + // TODO: convert deployment.UUID to uuid type + uuidStr, _ := uuid.Parse(d.UUID) + uuidStrPtr = &uuidStr + } + + patchAgent := AgentPatchRequest{ + DeploymentID: uuidStrPtr, + NeedToReboot: &needToReboot, + } + logrus.Debugf("space: PatchAgentWithResponse(%s, %#v)", s.agentID.String(), patchAgent) + respPatch, err := s.client.PatchAgentWithResponse(ctx, *s.agentID, patchAgent) + if err != nil { + logrus.Error(err) + return + } + if respPatch.StatusCode() != http.StatusOK { + logrus.Errorf("space: expected HTTP 200 while patching the agent but received %d", respPatch.StatusCode()) + return + } +} diff --git a/nix/module.nix b/nix/module.nix index 6b38c55..50740e3 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -32,6 +32,7 @@ in { + " run " + "--config ${cominConfigYaml}"; Restart = "always"; + Environment = [ "COMIN_SPACE_URL=https://comin.space" "COMIN_SPACE_API_KEY_FILEPATH=/run/secrets/comin_space/api_key" ]; }; }; };