diff --git a/infrastructure/persistence/dispatcher/dispatcher.gen.go b/infrastructure/persistence/dispatcher/dispatcher.gen.go index 1718e445..14eecddd 100644 --- a/infrastructure/persistence/dispatcher/dispatcher.gen.go +++ b/infrastructure/persistence/dispatcher/dispatcher.gen.go @@ -1,4 +1,4 @@ -// Package dispatcher provides primitives to interact the openapi HTTP API. +// Package dispatcher provides primitives to interact with the openapi HTTP API. // // Code generated by github.com/deepmap/oapi-codegen DO NOT EDIT. package dispatcher @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -63,7 +62,7 @@ func NewClient(server string, opts ...ClientOption) (*Client, error) { } // create httpClient, if not already present if client.Client == nil { - client.Client = http.DefaultClient + client.Client = &http.Client{} } return &client, nil } @@ -88,10 +87,33 @@ func WithRequestEditorFn(fn RequestEditorFn) ClientOption { // The interface specification for the client above. type ClientInterface interface { - // ApiInternalRunsCreate request with any body + // ApiInternalRunsCreate request with any body ApiInternalRunsCreateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) ApiInternalRunsCreate(ctx context.Context, body ApiInternalRunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ApiInternalV2RunsCancel request with any body + ApiInternalV2RunsCancelWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ApiInternalV2RunsCancel(ctx context.Context, body ApiInternalV2RunsCancelJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ApiInternalHighlevelConnectionStatus request with any body + ApiInternalHighlevelConnectionStatusWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ApiInternalHighlevelConnectionStatus(ctx context.Context, body ApiInternalHighlevelConnectionStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ApiInternalV2RunsCreate request with any body + ApiInternalV2RunsCreateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ApiInternalV2RunsCreate(ctx context.Context, body ApiInternalV2RunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ApiInternalV2RecipientsStatus request with any body + ApiInternalV2RecipientsStatusWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ApiInternalV2RecipientsStatus(ctx context.Context, body ApiInternalV2RecipientsStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ApiInternalVersion request + ApiInternalVersion(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) } func (c *Client) ApiInternalRunsCreateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { @@ -99,6 +121,7 @@ func (c *Client) ApiInternalRunsCreateWithBody(ctx context.Context, contentType if err != nil { return nil, err } + req = req.WithContext(ctx) if err := c.applyEditors(ctx, req, reqEditors); err != nil { return nil, err } @@ -110,6 +133,115 @@ func (c *Client) ApiInternalRunsCreate(ctx context.Context, body ApiInternalRuns 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) ApiInternalV2RunsCancelWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalV2RunsCancelRequestWithBody(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) ApiInternalV2RunsCancel(ctx context.Context, body ApiInternalV2RunsCancelJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalV2RunsCancelRequest(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) ApiInternalHighlevelConnectionStatusWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalHighlevelConnectionStatusRequestWithBody(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) ApiInternalHighlevelConnectionStatus(ctx context.Context, body ApiInternalHighlevelConnectionStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalHighlevelConnectionStatusRequest(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) ApiInternalV2RunsCreateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalV2RunsCreateRequestWithBody(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) ApiInternalV2RunsCreate(ctx context.Context, body ApiInternalV2RunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalV2RunsCreateRequest(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) ApiInternalV2RecipientsStatusWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalV2RecipientsStatusRequestWithBody(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) ApiInternalV2RecipientsStatus(ctx context.Context, body ApiInternalV2RecipientsStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalV2RecipientsStatusRequest(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) ApiInternalVersion(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewApiInternalVersionRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) if err := c.applyEditors(ctx, req, reqEditors); err != nil { return nil, err } @@ -131,22 +263,22 @@ func NewApiInternalRunsCreateRequest(server string, body ApiInternalRunsCreateJS func NewApiInternalRunsCreateRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { var err error - queryUrl, err := url.Parse(server) + serverURL, err := url.Parse(server) if err != nil { return nil, err } - basePath := fmt.Sprintf("/internal/dispatch") - if basePath[0] == '/' { - basePath = basePath[1:] + operationPath := fmt.Sprintf("/internal/dispatch") + if operationPath[0] == '/' { + operationPath = "." + operationPath } - queryUrl, err = queryUrl.Parse(basePath) + queryURL, err := serverURL.Parse(operationPath) if err != nil { return nil, err } - req, err := http.NewRequest("POST", queryUrl.String(), body) + req, err := http.NewRequest("POST", queryURL.String(), body) if err != nil { return nil, err } @@ -156,8 +288,194 @@ func NewApiInternalRunsCreateRequestWithBody(server string, contentType string, return req, nil } +// NewApiInternalV2RunsCancelRequest calls the generic ApiInternalV2RunsCancel builder with application/json body +func NewApiInternalV2RunsCancelRequest(server string, body ApiInternalV2RunsCancelJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewApiInternalV2RunsCancelRequestWithBody(server, "application/json", bodyReader) +} + +// NewApiInternalV2RunsCancelRequestWithBody generates requests for ApiInternalV2RunsCancel with any type of body +func NewApiInternalV2RunsCancelRequestWithBody(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("/internal/v2/cancel") + 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 +} + +// NewApiInternalHighlevelConnectionStatusRequest calls the generic ApiInternalHighlevelConnectionStatus builder with application/json body +func NewApiInternalHighlevelConnectionStatusRequest(server string, body ApiInternalHighlevelConnectionStatusJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewApiInternalHighlevelConnectionStatusRequestWithBody(server, "application/json", bodyReader) +} + +// NewApiInternalHighlevelConnectionStatusRequestWithBody generates requests for ApiInternalHighlevelConnectionStatus with any type of body +func NewApiInternalHighlevelConnectionStatusRequestWithBody(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("/internal/v2/connection_status") + 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 +} + +// NewApiInternalV2RunsCreateRequest calls the generic ApiInternalV2RunsCreate builder with application/json body +func NewApiInternalV2RunsCreateRequest(server string, body ApiInternalV2RunsCreateJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewApiInternalV2RunsCreateRequestWithBody(server, "application/json", bodyReader) +} + +// NewApiInternalV2RunsCreateRequestWithBody generates requests for ApiInternalV2RunsCreate with any type of body +func NewApiInternalV2RunsCreateRequestWithBody(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("/internal/v2/dispatch") + 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 +} + +// NewApiInternalV2RecipientsStatusRequest calls the generic ApiInternalV2RecipientsStatus builder with application/json body +func NewApiInternalV2RecipientsStatusRequest(server string, body ApiInternalV2RecipientsStatusJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewApiInternalV2RecipientsStatusRequestWithBody(server, "application/json", bodyReader) +} + +// NewApiInternalV2RecipientsStatusRequestWithBody generates requests for ApiInternalV2RecipientsStatus with any type of body +func NewApiInternalV2RecipientsStatusRequestWithBody(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("/internal/v2/recipients/status") + 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 +} + +// NewApiInternalVersionRequest generates requests for ApiInternalVersion +func NewApiInternalVersionRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/internal/version") + 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 +} + func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { - req = req.WithContext(ctx) for _, r := range c.RequestEditors { if err := r(ctx, req); err != nil { return err @@ -200,16 +518,40 @@ func WithBaseURL(baseURL string) ClientOption { // ClientWithResponsesInterface is the interface specification for the client with responses above. type ClientWithResponsesInterface interface { - // ApiInternalRunsCreate request with any body - ApiInternalRunsCreateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader) (*ApiInternalRunsCreateResponse, error) + // ApiInternalRunsCreate request with any body + ApiInternalRunsCreateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalRunsCreateResponse, error) + + ApiInternalRunsCreateWithResponse(ctx context.Context, body ApiInternalRunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalRunsCreateResponse, error) + + // ApiInternalV2RunsCancel request with any body + ApiInternalV2RunsCancelWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCancelResponse, error) + + ApiInternalV2RunsCancelWithResponse(ctx context.Context, body ApiInternalV2RunsCancelJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCancelResponse, error) - ApiInternalRunsCreateWithResponse(ctx context.Context, body ApiInternalRunsCreateJSONRequestBody) (*ApiInternalRunsCreateResponse, error) + // ApiInternalHighlevelConnectionStatus request with any body + ApiInternalHighlevelConnectionStatusWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalHighlevelConnectionStatusResponse, error) + + ApiInternalHighlevelConnectionStatusWithResponse(ctx context.Context, body ApiInternalHighlevelConnectionStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalHighlevelConnectionStatusResponse, error) + + // ApiInternalV2RunsCreate request with any body + ApiInternalV2RunsCreateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCreateResponse, error) + + ApiInternalV2RunsCreateWithResponse(ctx context.Context, body ApiInternalV2RunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCreateResponse, error) + + // ApiInternalV2RecipientsStatus request with any body + ApiInternalV2RecipientsStatusWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalV2RecipientsStatusResponse, error) + + ApiInternalV2RecipientsStatusWithResponse(ctx context.Context, body ApiInternalV2RecipientsStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalV2RecipientsStatusResponse, error) + + // ApiInternalVersion request + ApiInternalVersionWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ApiInternalVersionResponse, error) } type ApiInternalRunsCreateResponse struct { Body []byte HTTPResponse *http.Response JSON207 *RunsCreated + JSON400 *Error } // Status returns HTTPResponse.Status @@ -228,27 +570,217 @@ func (r ApiInternalRunsCreateResponse) StatusCode() int { return 0 } +type ApiInternalV2RunsCancelResponse struct { + Body []byte + HTTPResponse *http.Response + JSON207 *RunsCanceled + JSON400 *Error +} + +// Status returns HTTPResponse.Status +func (r ApiInternalV2RunsCancelResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ApiInternalV2RunsCancelResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ApiInternalHighlevelConnectionStatusResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *HighLevelRecipientStatus + JSON400 *Error +} + +// Status returns HTTPResponse.Status +func (r ApiInternalHighlevelConnectionStatusResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ApiInternalHighlevelConnectionStatusResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ApiInternalV2RunsCreateResponse struct { + Body []byte + HTTPResponse *http.Response + JSON207 *RunsCreated +} + +// Status returns HTTPResponse.Status +func (r ApiInternalV2RunsCreateResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ApiInternalV2RunsCreateResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ApiInternalV2RecipientsStatusResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *[]RecipientStatus + JSON400 *Error +} + +// Status returns HTTPResponse.Status +func (r ApiInternalV2RecipientsStatusResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ApiInternalV2RecipientsStatusResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ApiInternalVersionResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Version +} + +// Status returns HTTPResponse.Status +func (r ApiInternalVersionResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ApiInternalVersionResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + // ApiInternalRunsCreateWithBodyWithResponse request with arbitrary body returning *ApiInternalRunsCreateResponse -func (c *ClientWithResponses) ApiInternalRunsCreateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader) (*ApiInternalRunsCreateResponse, error) { - rsp, err := c.ApiInternalRunsCreateWithBody(ctx, contentType, body) +func (c *ClientWithResponses) ApiInternalRunsCreateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalRunsCreateResponse, error) { + rsp, err := c.ApiInternalRunsCreateWithBody(ctx, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseApiInternalRunsCreateResponse(rsp) } -func (c *ClientWithResponses) ApiInternalRunsCreateWithResponse(ctx context.Context, body ApiInternalRunsCreateJSONRequestBody) (*ApiInternalRunsCreateResponse, error) { - rsp, err := c.ApiInternalRunsCreate(ctx, body) +func (c *ClientWithResponses) ApiInternalRunsCreateWithResponse(ctx context.Context, body ApiInternalRunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalRunsCreateResponse, error) { + rsp, err := c.ApiInternalRunsCreate(ctx, body, reqEditors...) if err != nil { return nil, err } return ParseApiInternalRunsCreateResponse(rsp) } +// ApiInternalV2RunsCancelWithBodyWithResponse request with arbitrary body returning *ApiInternalV2RunsCancelResponse +func (c *ClientWithResponses) ApiInternalV2RunsCancelWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCancelResponse, error) { + rsp, err := c.ApiInternalV2RunsCancelWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalV2RunsCancelResponse(rsp) +} + +func (c *ClientWithResponses) ApiInternalV2RunsCancelWithResponse(ctx context.Context, body ApiInternalV2RunsCancelJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCancelResponse, error) { + rsp, err := c.ApiInternalV2RunsCancel(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalV2RunsCancelResponse(rsp) +} + +// ApiInternalHighlevelConnectionStatusWithBodyWithResponse request with arbitrary body returning *ApiInternalHighlevelConnectionStatusResponse +func (c *ClientWithResponses) ApiInternalHighlevelConnectionStatusWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalHighlevelConnectionStatusResponse, error) { + rsp, err := c.ApiInternalHighlevelConnectionStatusWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalHighlevelConnectionStatusResponse(rsp) +} + +func (c *ClientWithResponses) ApiInternalHighlevelConnectionStatusWithResponse(ctx context.Context, body ApiInternalHighlevelConnectionStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalHighlevelConnectionStatusResponse, error) { + rsp, err := c.ApiInternalHighlevelConnectionStatus(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalHighlevelConnectionStatusResponse(rsp) +} + +// ApiInternalV2RunsCreateWithBodyWithResponse request with arbitrary body returning *ApiInternalV2RunsCreateResponse +func (c *ClientWithResponses) ApiInternalV2RunsCreateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCreateResponse, error) { + rsp, err := c.ApiInternalV2RunsCreateWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalV2RunsCreateResponse(rsp) +} + +func (c *ClientWithResponses) ApiInternalV2RunsCreateWithResponse(ctx context.Context, body ApiInternalV2RunsCreateJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalV2RunsCreateResponse, error) { + rsp, err := c.ApiInternalV2RunsCreate(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalV2RunsCreateResponse(rsp) +} + +// ApiInternalV2RecipientsStatusWithBodyWithResponse request with arbitrary body returning *ApiInternalV2RecipientsStatusResponse +func (c *ClientWithResponses) ApiInternalV2RecipientsStatusWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ApiInternalV2RecipientsStatusResponse, error) { + rsp, err := c.ApiInternalV2RecipientsStatusWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalV2RecipientsStatusResponse(rsp) +} + +func (c *ClientWithResponses) ApiInternalV2RecipientsStatusWithResponse(ctx context.Context, body ApiInternalV2RecipientsStatusJSONRequestBody, reqEditors ...RequestEditorFn) (*ApiInternalV2RecipientsStatusResponse, error) { + rsp, err := c.ApiInternalV2RecipientsStatus(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalV2RecipientsStatusResponse(rsp) +} + +// ApiInternalVersionWithResponse request returning *ApiInternalVersionResponse +func (c *ClientWithResponses) ApiInternalVersionWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ApiInternalVersionResponse, error) { + rsp, err := c.ApiInternalVersion(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseApiInternalVersionResponse(rsp) +} + // ParseApiInternalRunsCreateResponse parses an HTTP response from a ApiInternalRunsCreateWithResponse call func ParseApiInternalRunsCreateResponse(rsp *http.Response) (*ApiInternalRunsCreateResponse, error) { - bodyBytes, err := ioutil.ReadAll(rsp.Body) - defer rsp.Body.Close() + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } @@ -266,6 +798,164 @@ func ParseApiInternalRunsCreateResponse(rsp *http.Response) (*ApiInternalRunsCre } response.JSON207 = &dest + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + +// ParseApiInternalV2RunsCancelResponse parses an HTTP response from a ApiInternalV2RunsCancelWithResponse call +func ParseApiInternalV2RunsCancelResponse(rsp *http.Response) (*ApiInternalV2RunsCancelResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ApiInternalV2RunsCancelResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 207: + var dest RunsCanceled + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON207 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + +// ParseApiInternalHighlevelConnectionStatusResponse parses an HTTP response from a ApiInternalHighlevelConnectionStatusWithResponse call +func ParseApiInternalHighlevelConnectionStatusResponse(rsp *http.Response) (*ApiInternalHighlevelConnectionStatusResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ApiInternalHighlevelConnectionStatusResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest HighLevelRecipientStatus + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + +// ParseApiInternalV2RunsCreateResponse parses an HTTP response from a ApiInternalV2RunsCreateWithResponse call +func ParseApiInternalV2RunsCreateResponse(rsp *http.Response) (*ApiInternalV2RunsCreateResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ApiInternalV2RunsCreateResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 207: + var dest RunsCreated + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON207 = &dest + + } + + return response, nil +} + +// ParseApiInternalV2RecipientsStatusResponse parses an HTTP response from a ApiInternalV2RecipientsStatusWithResponse call +func ParseApiInternalV2RecipientsStatusResponse(rsp *http.Response) (*ApiInternalV2RecipientsStatusResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ApiInternalV2RecipientsStatusResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest []RecipientStatus + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + +// ParseApiInternalVersionResponse parses an HTTP response from a ApiInternalVersionWithResponse call +func ParseApiInternalVersionResponse(rsp *http.Response) (*ApiInternalVersionResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ApiInternalVersionResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Version + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + } return response, nil diff --git a/infrastructure/persistence/dispatcher/dispatcher.go b/infrastructure/persistence/dispatcher/dispatcher.go index e8f968b4..f4b39c35 100644 --- a/infrastructure/persistence/dispatcher/dispatcher.go +++ b/infrastructure/persistence/dispatcher/dispatcher.go @@ -26,7 +26,7 @@ import ( // DispatcherClient provides REST client API methods to interact with the // platform playbook-dispatcher application. type DispatcherClient interface { - Dispatch(ctx context.Context, inputs []RunInput) ([]RunCreated, error) + Dispatch(ctx context.Context, inputs []RunInputV2) ([]RunCreated, error) } // dispatcherClientImpl implements DispatcherClient interface. @@ -67,10 +67,10 @@ func NewDispatcherClient() DispatcherClient { // Dispatch performs the CreateWithResponse API method of the // playbook-dispatcher service. -func (dc *dispatcherClientImpl) Dispatch(ctx context.Context, inputs []RunInput) ([]RunCreated, error) { +func (dc *dispatcherClientImpl) Dispatch(ctx context.Context, inputs []RunInputV2) ([]RunCreated, error) { logger := log.With().Str("http_client", "playbook-dispatcher").Logger() - res, err := dc.client.ApiInternalRunsCreateWithResponse(ctx, inputs) + res, err := dc.client.ApiInternalV2RunsCreateWithResponse(ctx, inputs) if err != nil { logger.Error().Err(err).Msg("cannot create runs with response") return nil, err diff --git a/infrastructure/persistence/dispatcher/dispatcher_test.go b/infrastructure/persistence/dispatcher/dispatcher_test.go index e08742d5..0a49254a 100644 --- a/infrastructure/persistence/dispatcher/dispatcher_test.go +++ b/infrastructure/persistence/dispatcher/dispatcher_test.go @@ -9,13 +9,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/uuid" ) func TestDispatch(t *testing.T) { tests := []struct { description string input struct { - runs []RunInput + runs []RunInputV2 response []byte } want []RunCreated @@ -23,28 +24,28 @@ func TestDispatch(t *testing.T) { { description: "two responses", input: struct { - runs []RunInput + runs []RunInputV2 response []byte }{ - runs: []RunInput{ + runs: []RunInputV2{ { - Recipient: "276c4685-fdfb-4172-930f-4148b8340c2e", - Account: "0000001", + Recipient: uuid.MustParse("276c4685-fdfb-4172-930f-4148b8340c2e"), + OrgId: "0000001", + Principal: "test_user", Url: "https://cloud.redhat.com/api/config-manager/v1/states/e417581a-d649-4cdc-9506-6eb7fdbfd66d/playbook", - Labels: &RunInput_Labels{ - AdditionalProperties: map[string]string{ - "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", - }, + Name: "Apply fix", + Labels: &Labels{ + "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", }, }, { - Recipient: "9a76b28b-0e09-41c8-bf01-79d1bef72646", - Account: "0000001", + Recipient: uuid.MustParse("9a76b28b-0e09-41c8-bf01-79d1bef72646"), + OrgId: "0000001", + Principal: "test_user", Url: "https://cloud.redhat.com/api/config-manager/v1/states/e417581a-d649-4cdc-9506-6eb7fdbfd66d/playbook", - Labels: &RunInput_Labels{ - AdditionalProperties: map[string]string{ - "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", - }, + Name: "Apply fix", + Labels: &Labels{ + "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", }, }, }, @@ -53,39 +54,39 @@ func TestDispatch(t *testing.T) { want: []RunCreated{ { Code: 200, - Id: func(s string) *string { return &s }("3d711f8b-77d0-4ed5-a5b5-1d282bf930c7"), + Id: func(s uuid.UUID) *uuid.UUID { return &s }(uuid.MustParse("3d711f8b-77d0-4ed5-a5b5-1d282bf930c7")), }, { Code: 200, - Id: func(s string) *string { return &s }("74368f32-4e6d-4ea2-9b8f-22dac89f9ae4"), + Id: func(s uuid.UUID) *uuid.UUID { return &s }(uuid.MustParse("74368f32-4e6d-4ea2-9b8f-22dac89f9ae4")), }, }, }, { description: "missing responses", input: struct { - runs []RunInput + runs []RunInputV2 response []byte }{ - runs: []RunInput{ + runs: []RunInputV2{ { - Recipient: "276c4685-fdfb-4172-930f-4148b8340c2e", - Account: "0000001", + Recipient: uuid.MustParse("276c4685-fdfb-4172-930f-4148b8340c2e"), + OrgId: "0000001", + Principal: "test_user", Url: "https://cloud.redhat.com/api/config-manager/v1/states/e417581a-d649-4cdc-9506-6eb7fdbfd66d/playbook", - Labels: &RunInput_Labels{ - AdditionalProperties: map[string]string{ - "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", - }, + Name: "Apply Fix", + Labels: &Labels{ + "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", }, }, { - Recipient: "9a76b28b-0e09-41c8-bf01-79d1bef72646", - Account: "0000001", + Recipient: uuid.MustParse("9a76b28b-0e09-41c8-bf01-79d1bef72646"), + OrgId: "0000001", + Principal: "test_user", Url: "https://cloud.redhat.com/api/config-manager/v1/states/e417581a-d649-4cdc-9506-6eb7fdbfd66d/playbook", - Labels: &RunInput_Labels{ - AdditionalProperties: map[string]string{ - "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", - }, + Name: "Apply Fix", + Labels: &Labels{ + "test": "e417581a-d649-4cdc-9506-6eb7fdbfd66d", }, }, }, @@ -107,7 +108,7 @@ func TestDispatch(t *testing.T) { mux := staticmux.StaticMux{} responseBody := test.input.response headers := map[string][]string{"Content-Type": {"application/json"}} - mux.AddResponse("/internal/dispatch", 207, responseBody, headers) + mux.AddResponse("/internal/v2/dispatch", 207, responseBody, headers) server := httptest.NewServer(&mux) defer server.Close() diff --git a/infrastructure/persistence/dispatcher/dispatcher_types.gen.go b/infrastructure/persistence/dispatcher/dispatcher_types.gen.go index 5393e37b..126a4398 100644 --- a/infrastructure/persistence/dispatcher/dispatcher_types.gen.go +++ b/infrastructure/persistence/dispatcher/dispatcher_types.gen.go @@ -1,123 +1,279 @@ -// Package dispatcher provides primitives to interact the openapi HTTP API. +// Package dispatcher provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/deepmap/oapi-codegen DO NOT EDIT. +// Code generated by unknown module path version unknown version DO NOT EDIT. package dispatcher import ( - "encoding/json" - "fmt" + openapi_types "github.com/deepmap/oapi-codegen/pkg/types" +) + +// Defines values for RecipientType. +const ( + DirectConnect RecipientType = "directConnect" + None RecipientType = "none" + Satellite RecipientType = "satellite" +) - "github.com/pkg/errors" +// Defines values for RecipientWithConnectionInfoStatus. +const ( + Connected RecipientWithConnectionInfoStatus = "connected" + Disconnected RecipientWithConnectionInfoStatus = "disconnected" + RhcNotConfigured RecipientWithConnectionInfoStatus = "rhc_not_configured" ) +// Account Identifier of the tenant +type Account = string + +// CancelInputV2 defines model for CancelInputV2. +type CancelInputV2 struct { + // OrgId Identifies the organization that the given resource belongs to + OrgId OrgId `json:"org_id"` + + // Principal Username of the user interacting with the service + Principal Principal `json:"principal"` + + // RunId Unique identifier of a Playbook run + RunId RunId `json:"run_id"` +} + +// Error defines model for Error. +type Error struct { + // Message Human readable error message + Message string `json:"message"` +} + +// HighLevelRecipientStatus defines model for HighLevelRecipientStatus. +type HighLevelRecipientStatus = []RecipientWithConnectionInfo + +// HostId Identifies a record of the Host-Inventory service +type HostId = string + +// HostsWithOrgId defines model for HostsWithOrgId. +type HostsWithOrgId struct { + Hosts []string `json:"hosts"` + + // OrgId Identifies the organization that the given resource belongs to + OrgId OrgId `json:"org_id"` +} + +// Labels Additional metadata about the Playbook run. Can be used for filtering purposes. +type Labels map[string]string + +// OrgId Identifies the organization that the given resource belongs to +type OrgId = string + +// PlaybookName Human readable name of the playbook run. Used to present the given playbook run in external systems (Satellite). +type PlaybookName = string + +// Principal Username of the user interacting with the service +type Principal = string + +// RecipientConfig recipient-specific configuration options +type RecipientConfig struct { + // SatId Identifier of the Satellite instance in the uuid v4/v5 format + SatId *string `json:"sat_id,omitempty"` + + // SatOrgId Identifier of the organization within Satellite + SatOrgId *string `json:"sat_org_id,omitempty"` +} + +// RecipientStatus defines model for RecipientStatus. +type RecipientStatus struct { + // Connected Indicates whether a connection is established with the recipient + Connected bool `json:"connected"` + + // OrgId Identifies the organization that the given resource belongs to + OrgId OrgId `json:"org_id"` + + // Recipient Identifier of the host to which a given Playbook is addressed + Recipient RunRecipient `json:"recipient"` +} + +// RecipientType Identifies the type of recipient [Satellite, Direct Connected, None] +type RecipientType string + +// RecipientWithConnectionInfo defines model for RecipientWithConnectionInfo. +type RecipientWithConnectionInfo struct { + // OrgId Identifies the organization that the given resource belongs to + OrgId OrgId `json:"org_id"` + + // Recipient Identifier of the host to which a given Playbook is addressed + Recipient RunRecipient `json:"recipient"` + + // RecipientType Identifies the type of recipient [Satellite, Direct Connected, None] + RecipientType RecipientType `json:"recipient_type"` + + // SatId Identifier of the Satellite instance in the uuid v4/v5 format + SatId SatelliteId `json:"sat_id"` + + // SatOrgId Identifier of the organization within Satellite + SatOrgId SatelliteOrgId `json:"sat_org_id"` + + // Status Indicates the current run status of the recipient + Status RecipientWithConnectionInfoStatus `json:"status"` + Systems []HostId `json:"systems"` +} + +// RecipientWithConnectionInfoStatus Indicates the current run status of the recipient +type RecipientWithConnectionInfoStatus string + +// RecipientWithOrg defines model for RecipientWithOrg. +type RecipientWithOrg struct { + // OrgId Identifies the organization that the given resource belongs to + OrgId OrgId `json:"org_id"` + + // Recipient Identifier of the host to which a given Playbook is addressed + Recipient RunRecipient `json:"recipient"` +} + +// RunCanceled defines model for RunCanceled. +type RunCanceled struct { + // Code status code of the request + Code int `json:"code"` + + // RunId Unique identifier of a Playbook run + RunId RunId `json:"run_id"` +} + // RunCreated defines model for RunCreated. type RunCreated struct { - - // status code of the request + // Code status code of the request Code int `json:"code"` - // Unique identifier of a Playbook run - Id *string `json:"id,omitempty"` + // Id Unique identifier of a Playbook run + Id *RunId `json:"id,omitempty"` } +// RunId Unique identifier of a Playbook run +type RunId = openapi_types.UUID + // RunInput defines model for RunInput. type RunInput struct { + // Account Identifier of the tenant + // Deprecated: + Account Account `json:"account"` - // Identifier of the tenant - Account string `json:"account"` - - // Optionally, information about hosts involved in the Playbook run can be provided. + // Hosts Optionally, information about hosts involved in the Playbook run can be provided. // This information is used to pre-allocate run_host resources. // Moreover, it can be used to create a connection between a run_host resource and host inventory. Hosts *RunInputHosts `json:"hosts,omitempty"` - // Additional metadata about the Playbook run. Can be used for filtering purposes. - Labels *RunInput_Labels `json:"labels,omitempty"` + // Labels Additional metadata about the Playbook run. Can be used for filtering purposes. + Labels *Labels `json:"labels,omitempty"` - // Identifier of the host to which a given Playbook is addressed - Recipient string `json:"recipient"` + // Recipient Identifier of the host to which a given Playbook is addressed + Recipient RunRecipient `json:"recipient"` - // Amount of seconds after which the run is considered failed due to timeout - Timeout *int `json:"timeout,omitempty"` + // Timeout Amount of seconds after which the run is considered failed due to timeout + Timeout *RunTimeout `json:"timeout,omitempty"` - // URL hosting the Playbook - Url string `json:"url"` + // Url URL hosting the Playbook + Url Url `json:"url"` } -// RunInput_Labels defines model for RunInput.Labels. -type RunInput_Labels struct { - AdditionalProperties map[string]string `json:"-"` +// RunInputHosts Optionally, information about hosts involved in the Playbook run can be provided. +// This information is used to pre-allocate run_host resources. +// Moreover, it can be used to create a connection between a run_host resource and host inventory. +type RunInputHosts = []struct { + // AnsibleHost Host name as known to Ansible inventory. + // Used to identify the host in status reports. + AnsibleHost *string `json:"ansible_host,omitempty"` + + // InventoryId Inventory id of the given host + InventoryId *openapi_types.UUID `json:"inventory_id,omitempty"` } -// RunInputHosts defines model for RunInputHosts. -type RunInputHosts []struct { +// RunInputV2 defines model for RunInputV2. +type RunInputV2 struct { + // Hosts Optionally, information about hosts involved in the Playbook run can be provided. + // This information is used to pre-allocate run_host resources. + // Moreover, it can be used to create a connection between a run_host resource and host inventory. + Hosts *RunInputHosts `json:"hosts,omitempty"` - // Host name as known to Ansible inventory. - // Used to identify the host in status reports. - AnsibleHost string `json:"ansible_host"` + // Labels Additional metadata about the Playbook run. Can be used for filtering purposes. + Labels *Labels `json:"labels,omitempty"` + + // Name Human readable name of the playbook run. Used to present the given playbook run in external systems (Satellite). + Name PlaybookName `json:"name"` + + // OrgId Identifier of the tenant + OrgId SchemasOrgId `json:"org_id"` + + // Principal Username of the user interacting with the service + Principal Principal `json:"principal"` + + // Recipient Identifier of the host to which a given Playbook is addressed + Recipient RunRecipient `json:"recipient"` + + // RecipientConfig recipient-specific configuration options + RecipientConfig *RecipientConfig `json:"recipient_config,omitempty"` + + // Timeout Amount of seconds after which the run is considered failed due to timeout + Timeout *RunTimeout `json:"timeout,omitempty"` - // Inventory id of the given host - InventoryId *string `json:"inventory_id,omitempty"` + // Url URL hosting the Playbook + Url Url `json:"url"` + + // WebConsoleUrl URL that points to the section of the web console where the user find more information about the playbook run. The field is optional but highly suggested. + WebConsoleUrl *WebConsoleUrl `json:"web_console_url,omitempty"` } +// RunRecipient Identifier of the host to which a given Playbook is addressed +type RunRecipient = openapi_types.UUID + +// RunTimeout Amount of seconds after which the run is considered failed due to timeout +type RunTimeout = int + +// RunsCanceled defines model for RunsCanceled. +type RunsCanceled = []RunCanceled + // RunsCreated defines model for RunsCreated. -type RunsCreated []RunCreated +type RunsCreated = []RunCreated + +// SatelliteId Identifier of the Satellite instance in the uuid v4/v5 format +type SatelliteId = string + +// SatelliteOrgId Identifier of the organization within Satellite +type SatelliteOrgId = string + +// Url URL hosting the Playbook +type Url = string + +// Version Version of the API +type Version = string + +// WebConsoleUrl URL that points to the section of the web console where the user find more information about the playbook run. The field is optional but highly suggested. +type WebConsoleUrl = string + +// SchemasOrgId Identifier of the tenant +type SchemasOrgId = string + +// BadRequest defines model for BadRequest. +type BadRequest = Error // ApiInternalRunsCreateJSONBody defines parameters for ApiInternalRunsCreate. -type ApiInternalRunsCreateJSONBody []RunInput +type ApiInternalRunsCreateJSONBody = []RunInput + +// ApiInternalV2RunsCancelJSONBody defines parameters for ApiInternalV2RunsCancel. +type ApiInternalV2RunsCancelJSONBody = []CancelInputV2 + +// ApiInternalV2RunsCreateJSONBody defines parameters for ApiInternalV2RunsCreate. +type ApiInternalV2RunsCreateJSONBody = []RunInputV2 + +// ApiInternalV2RecipientsStatusJSONBody defines parameters for ApiInternalV2RecipientsStatus. +type ApiInternalV2RecipientsStatusJSONBody = []RecipientWithOrg // ApiInternalRunsCreateJSONRequestBody defines body for ApiInternalRunsCreate for application/json ContentType. -type ApiInternalRunsCreateJSONRequestBody ApiInternalRunsCreateJSONBody - -// Getter for additional properties for RunInput_Labels. Returns the specified -// element and whether it was found -func (a RunInput_Labels) Get(fieldName string) (value string, found bool) { - if a.AdditionalProperties != nil { - value, found = a.AdditionalProperties[fieldName] - } - return -} +type ApiInternalRunsCreateJSONRequestBody = ApiInternalRunsCreateJSONBody -// Setter for additional properties for RunInput_Labels -func (a *RunInput_Labels) Set(fieldName string, value string) { - if a.AdditionalProperties == nil { - a.AdditionalProperties = make(map[string]string) - } - a.AdditionalProperties[fieldName] = value -} +// ApiInternalV2RunsCancelJSONRequestBody defines body for ApiInternalV2RunsCancel for application/json ContentType. +type ApiInternalV2RunsCancelJSONRequestBody = ApiInternalV2RunsCancelJSONBody -// Override default JSON handling for RunInput_Labels to handle AdditionalProperties -func (a *RunInput_Labels) UnmarshalJSON(b []byte) error { - object := make(map[string]json.RawMessage) - err := json.Unmarshal(b, &object) - if err != nil { - return err - } - - if len(object) != 0 { - a.AdditionalProperties = make(map[string]string) - for fieldName, fieldBuf := range object { - var fieldVal string - err := json.Unmarshal(fieldBuf, &fieldVal) - if err != nil { - return errors.Wrap(err, fmt.Sprintf("error unmarshaling field %s", fieldName)) - } - a.AdditionalProperties[fieldName] = fieldVal - } - } - return nil -} +// ApiInternalHighlevelConnectionStatusJSONRequestBody defines body for ApiInternalHighlevelConnectionStatus for application/json ContentType. +type ApiInternalHighlevelConnectionStatusJSONRequestBody = HostsWithOrgId -// Override default JSON handling for RunInput_Labels to handle AdditionalProperties -func (a RunInput_Labels) MarshalJSON() ([]byte, error) { - var err error - object := make(map[string]json.RawMessage) - - for fieldName, field := range a.AdditionalProperties { - object[fieldName], err = json.Marshal(field) - if err != nil { - return nil, errors.Wrap(err, fmt.Sprintf("error marshaling '%s'", fieldName)) - } - } - return json.Marshal(object) -} +// ApiInternalV2RunsCreateJSONRequestBody defines body for ApiInternalV2RunsCreate for application/json ContentType. +type ApiInternalV2RunsCreateJSONRequestBody = ApiInternalV2RunsCreateJSONBody + +// ApiInternalV2RecipientsStatusJSONRequestBody defines body for ApiInternalV2RecipientsStatus for application/json ContentType. +type ApiInternalV2RecipientsStatusJSONRequestBody = ApiInternalV2RecipientsStatusJSONBody diff --git a/internal/cmd/inventoryconsumer/cmd.go b/internal/cmd/inventoryconsumer/cmd.go index d681053e..697faea9 100644 --- a/internal/cmd/inventoryconsumer/cmd.go +++ b/internal/cmd/inventoryconsumer/cmd.go @@ -39,13 +39,17 @@ var Command ffcli.Command = ffcli.Command{ } type requestIDkey string +type identityKey string // InventoryEvent represents a message read off the inventory.events // topic. type InventoryEvent struct { - Type string `json:"type"` - Timestamp time.Time `json:"timestamp"` - Host internal.Host `json:"host"` + Type string `json:"type"` + Timestamp time.Time `json:"timestamp"` + Host internal.Host `json:"host"` + PlatformMetadata struct { + B64Identity string `json:"b64_identity"` + } `json:"platform_metadata"` } func handler(ctx context.Context, msg kafka.Message) { @@ -72,6 +76,8 @@ func handler(ctx context.Context, msg kafka.Message) { return } + ctx = context.WithValue(ctx, identityKey("identity"), event.PlatformMetadata.B64Identity) + switch eventType { case "created": logger.Info().Msg("setting up new host for remote host configuration") diff --git a/internal/host.go b/internal/host.go index a781c3ba..84b3cf96 100644 --- a/internal/host.go +++ b/internal/host.go @@ -7,10 +7,12 @@ import ( "config-manager/internal/db" "config-manager/internal/util" "context" + "encoding/base64" "encoding/json" "fmt" "time" + "github.com/google/uuid" "github.com/rs/zerolog/log" ) @@ -29,6 +31,14 @@ type Host struct { } `json:"system_profile"` } +type IdentityData struct { + Identity struct { + User struct { + Username string `json:"username"` + } `json:"user"` + } `json:"identity"` +} + // ApplyProfile applies the current profile to the specified hosts. func ApplyProfile(ctx context.Context, profile *db.Profile, hosts []Host, fn func(resp []dispatcher.RunCreated)) { logger := log.With().Logger() @@ -42,24 +52,42 @@ func ApplyProfile(ctx context.Context, profile *db.Profile, hosts []Host, fn fun return } + identity, ok := ctx.Value("identity").(string) + username := "" + if ok { + rawIdentity, err := base64.StdEncoding.DecodeString(identity) + + if err != nil { + fmt.Println("Error decoding identity:", err) + return + } + identityData := &IdentityData{} + + if err := json.Unmarshal(rawIdentity, &identityData); err != nil { + fmt.Println("Error parsing JSON:", err) + return + } + username = identityData.Identity.User.Username + } + logger.Debug().Int("num_hosts", len(hosts)).Msg("applying profile for hosts") - runs := make([]dispatcher.RunInput, 0, len(hosts)) + runs := make([]dispatcher.RunInputV2, 0, len(hosts)) for _, host := range hosts { if _, has := host.PerReporterStaleness["cloud-connector"]; !has { logger.Warn().Str("client_id", host.SystemProfile.RHCID).Msg("detected host without cloud-connector as a reporter") continue } logger.Debug().Str("client_id", host.SystemProfile.RHCID).Msg("creating run for host") - run := dispatcher.RunInput{ - Recipient: host.SystemProfile.RHCID, - Account: db.JSONNullStringSafeValue(profile.AccountID), + run := dispatcher.RunInputV2{ + Recipient: uuid.MustParse(host.SystemProfile.RHCID), + OrgId: host.OrgID, + Principal: username, Url: config.DefaultConfig.PlaybookHost.String() + fmt.Sprintf(config.DefaultConfig.PlaybookPath, profile.ID), - Labels: &dispatcher.RunInput_Labels{ - AdditionalProperties: map[string]string{ - "state_id": profile.ID.String(), - "id": host.ID, - }, + Name: profile.Name.String, + Labels: &dispatcher.Labels{ + "state_id": profile.ID.String(), + "id": host.ID, }, } runs = append(runs, run)