From 6b09617e98b206d3180bee4bf673fa284dc7c436 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Wed, 16 Apr 2025 18:10:59 +0100 Subject: [PATCH 1/2] feat: add deploy validations report --- go/models/deploy.go | 25 +++ go/models/deploy_validations_report.go | 77 +++++++++ ...y_validations_report_secret_scan_result.go | 46 +++++ .../update_deploy_validations_params_body.go | 43 +++++ go/plumbing/operations/operations_client.go | 37 +++++ .../update_deploy_validations_parameters.go | 157 ++++++++++++++++++ .../update_deploy_validations_responses.go | 70 ++++++++ swagger.yml | 54 ++++++ 8 files changed, 509 insertions(+) create mode 100644 go/models/deploy_validations_report.go create mode 100644 go/models/deploy_validations_report_secret_scan_result.go create mode 100644 go/models/update_deploy_validations_params_body.go create mode 100644 go/plumbing/operations/update_deploy_validations_parameters.go create mode 100644 go/plumbing/operations/update_deploy_validations_responses.go diff --git a/go/models/deploy.go b/go/models/deploy.go index 72d6e1ee..3c05495b 100644 --- a/go/models/deploy.go +++ b/go/models/deploy.go @@ -45,6 +45,9 @@ type Deploy struct { // deploy url DeployURL string `json:"deploy_url,omitempty"` + // deploy validations report + DeployValidationsReport *DeployValidationsReport `json:"deploy_validations_report,omitempty"` + // draft Draft bool `json:"draft,omitempty"` @@ -113,6 +116,10 @@ type Deploy struct { func (m *Deploy) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateDeployValidationsReport(formats); err != nil { + res = append(res, err) + } + if err := m.validateFunctionSchedules(formats); err != nil { res = append(res, err) } @@ -123,6 +130,24 @@ func (m *Deploy) Validate(formats strfmt.Registry) error { return nil } +func (m *Deploy) validateDeployValidationsReport(formats strfmt.Registry) error { + + if swag.IsZero(m.DeployValidationsReport) { // not required + return nil + } + + if m.DeployValidationsReport != nil { + if err := m.DeployValidationsReport.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("deploy_validations_report") + } + return err + } + } + + return nil +} + func (m *Deploy) validateFunctionSchedules(formats strfmt.Registry) error { if swag.IsZero(m.FunctionSchedules) { // not required diff --git a/go/models/deploy_validations_report.go b/go/models/deploy_validations_report.go new file mode 100644 index 00000000..64db65e7 --- /dev/null +++ b/go/models/deploy_validations_report.go @@ -0,0 +1,77 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// DeployValidationsReport deploy validations report +// +// swagger:model DeployValidationsReport +type DeployValidationsReport struct { + + // The id of the deploy + DeployID string `json:"deploy_id,omitempty"` + + // The id of the deploy validations report + ID string `json:"id,omitempty"` + + // secret scan result + SecretScanResult *DeployValidationsReportSecretScanResult `json:"secret_scan_result,omitempty"` +} + +// Validate validates this deploy validations report +func (m *DeployValidationsReport) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateSecretScanResult(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *DeployValidationsReport) validateSecretScanResult(formats strfmt.Registry) error { + + if swag.IsZero(m.SecretScanResult) { // not required + return nil + } + + if m.SecretScanResult != nil { + if err := m.SecretScanResult.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("secret_scan_result") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *DeployValidationsReport) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *DeployValidationsReport) UnmarshalBinary(b []byte) error { + var res DeployValidationsReport + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/go/models/deploy_validations_report_secret_scan_result.go b/go/models/deploy_validations_report_secret_scan_result.go new file mode 100644 index 00000000..eb365fd9 --- /dev/null +++ b/go/models/deploy_validations_report_secret_scan_result.go @@ -0,0 +1,46 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// DeployValidationsReportSecretScanResult deploy validations report secret scan result +// +// swagger:model DeployValidationsReport_SecretScanResult +type DeployValidationsReportSecretScanResult struct { + + // The number of files scanned + ScannedFilesCount int64 `json:"scannedFilesCount,omitempty"` + + // The list of secrets scan matches + SecretsScanMatches []string `json:"secretsScanMatches"` +} + +// Validate validates this deploy validations report secret scan result +func (m *DeployValidationsReportSecretScanResult) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *DeployValidationsReportSecretScanResult) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *DeployValidationsReportSecretScanResult) UnmarshalBinary(b []byte) error { + var res DeployValidationsReportSecretScanResult + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/go/models/update_deploy_validations_params_body.go b/go/models/update_deploy_validations_params_body.go new file mode 100644 index 00000000..d945faf1 --- /dev/null +++ b/go/models/update_deploy_validations_params_body.go @@ -0,0 +1,43 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// UpdateDeployValidationsParamsBody update deploy validations params body +// +// swagger:model updateDeployValidationsParamsBody +type UpdateDeployValidationsParamsBody struct { + + // secrets scan + SecretsScan interface{} `json:"secrets_scan,omitempty"` +} + +// Validate validates this update deploy validations params body +func (m *UpdateDeployValidationsParamsBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *UpdateDeployValidationsParamsBody) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UpdateDeployValidationsParamsBody) UnmarshalBinary(b []byte) error { + var res UpdateDeployValidationsParamsBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/go/plumbing/operations/operations_client.go b/go/plumbing/operations/operations_client.go index ef6f16ba..b9353d48 100644 --- a/go/plumbing/operations/operations_client.go +++ b/go/plumbing/operations/operations_client.go @@ -265,6 +265,8 @@ type ClientService interface { UpdateAccountMember(params *UpdateAccountMemberParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateAccountMemberOK, error) + UpdateDeployValidations(params *UpdateDeployValidationsParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateDeployValidationsOK, error) + UpdateEnvVar(params *UpdateEnvVarParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateEnvVarOK, error) UpdateHook(params *UpdateHookParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateHookOK, error) @@ -4355,6 +4357,41 @@ func (a *Client) UpdateAccountMember(params *UpdateAccountMemberParams, authInfo return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +UpdateDeployValidations Updates the deploy validations report for a deploy. +*/ +func (a *Client) UpdateDeployValidations(params *UpdateDeployValidationsParams, authInfo runtime.ClientAuthInfoWriter) (*UpdateDeployValidationsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewUpdateDeployValidationsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "updateDeployValidations", + Method: "PATCH", + PathPattern: "/deploys/{deploy_id}/validations_report", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &UpdateDeployValidationsReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*UpdateDeployValidationsOK) + if ok { + return success, nil + } + // unexpected success response + // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue + msg := fmt.Sprintf("unexpected success response for updateDeployValidations: API contract not enforced by server. Client expected to get an error, but got: %T", result) + panic(msg) +} + /* UpdateEnvVar Updates an existing environment variable and all of its values. Existing values will be replaced by values provided. */ diff --git a/go/plumbing/operations/update_deploy_validations_parameters.go b/go/plumbing/operations/update_deploy_validations_parameters.go new file mode 100644 index 00000000..549a8bb4 --- /dev/null +++ b/go/plumbing/operations/update_deploy_validations_parameters.go @@ -0,0 +1,157 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + + "github.com/netlify/open-api/v2/go/models" +) + +// NewUpdateDeployValidationsParams creates a new UpdateDeployValidationsParams object +// with the default values initialized. +func NewUpdateDeployValidationsParams() *UpdateDeployValidationsParams { + var () + return &UpdateDeployValidationsParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewUpdateDeployValidationsParamsWithTimeout creates a new UpdateDeployValidationsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewUpdateDeployValidationsParamsWithTimeout(timeout time.Duration) *UpdateDeployValidationsParams { + var () + return &UpdateDeployValidationsParams{ + + timeout: timeout, + } +} + +// NewUpdateDeployValidationsParamsWithContext creates a new UpdateDeployValidationsParams object +// with the default values initialized, and the ability to set a context for a request +func NewUpdateDeployValidationsParamsWithContext(ctx context.Context) *UpdateDeployValidationsParams { + var () + return &UpdateDeployValidationsParams{ + + Context: ctx, + } +} + +// NewUpdateDeployValidationsParamsWithHTTPClient creates a new UpdateDeployValidationsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewUpdateDeployValidationsParamsWithHTTPClient(client *http.Client) *UpdateDeployValidationsParams { + var () + return &UpdateDeployValidationsParams{ + HTTPClient: client, + } +} + +/* +UpdateDeployValidationsParams contains all the parameters to send to the API endpoint +for the update deploy validations operation typically these are written to a http.Request +*/ +type UpdateDeployValidationsParams struct { + + /*DeployID + The ID of the deploy + + */ + DeployID string + /*Report*/ + Report *models.UpdateDeployValidationsParamsBody + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the update deploy validations params +func (o *UpdateDeployValidationsParams) WithTimeout(timeout time.Duration) *UpdateDeployValidationsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the update deploy validations params +func (o *UpdateDeployValidationsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the update deploy validations params +func (o *UpdateDeployValidationsParams) WithContext(ctx context.Context) *UpdateDeployValidationsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the update deploy validations params +func (o *UpdateDeployValidationsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the update deploy validations params +func (o *UpdateDeployValidationsParams) WithHTTPClient(client *http.Client) *UpdateDeployValidationsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the update deploy validations params +func (o *UpdateDeployValidationsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithDeployID adds the deployID to the update deploy validations params +func (o *UpdateDeployValidationsParams) WithDeployID(deployID string) *UpdateDeployValidationsParams { + o.SetDeployID(deployID) + return o +} + +// SetDeployID adds the deployId to the update deploy validations params +func (o *UpdateDeployValidationsParams) SetDeployID(deployID string) { + o.DeployID = deployID +} + +// WithReport adds the report to the update deploy validations params +func (o *UpdateDeployValidationsParams) WithReport(report *models.UpdateDeployValidationsParamsBody) *UpdateDeployValidationsParams { + o.SetReport(report) + return o +} + +// SetReport adds the report to the update deploy validations params +func (o *UpdateDeployValidationsParams) SetReport(report *models.UpdateDeployValidationsParamsBody) { + o.Report = report +} + +// WriteToRequest writes these params to a swagger request +func (o *UpdateDeployValidationsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param deploy_id + if err := r.SetPathParam("deploy_id", o.DeployID); err != nil { + return err + } + + if o.Report != nil { + if err := r.SetBodyParam(o.Report); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/go/plumbing/operations/update_deploy_validations_responses.go b/go/plumbing/operations/update_deploy_validations_responses.go new file mode 100644 index 00000000..ad2c1ace --- /dev/null +++ b/go/plumbing/operations/update_deploy_validations_responses.go @@ -0,0 +1,70 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/netlify/open-api/v2/go/models" +) + +// UpdateDeployValidationsReader is a Reader for the UpdateDeployValidations structure. +type UpdateDeployValidationsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *UpdateDeployValidationsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewUpdateDeployValidationsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewUpdateDeployValidationsOK creates a UpdateDeployValidationsOK with default headers values +func NewUpdateDeployValidationsOK() *UpdateDeployValidationsOK { + return &UpdateDeployValidationsOK{} +} + +/* +UpdateDeployValidationsOK handles this case with default header values. + +OK +*/ +type UpdateDeployValidationsOK struct { + Payload *models.DeployValidationsReport +} + +func (o *UpdateDeployValidationsOK) Error() string { + return fmt.Sprintf("[PATCH /deploys/{deploy_id}/validations_report][%d] updateDeployValidationsOK %+v", 200, o.Payload) +} + +func (o *UpdateDeployValidationsOK) GetPayload() *models.DeployValidationsReport { + return o.Payload +} + +func (o *UpdateDeployValidationsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.DeployValidationsReport) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/swagger.yml b/swagger.yml index e9c65be8..8b7c8a27 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1411,6 +1411,34 @@ paths: description: No content default: $ref: '#/responses/error' + /deploys/{deploy_id}/validations_report: + patch: + operationId: updateDeployValidations + tags: [deploy] + description: Updates the deploy validations report for a deploy. + x-internal: true + x-controller: api/v1/deploys + x-action: validations_report + parameters: + - name: deploy_id + description: The ID of the deploy + type: string + in: path + required: true + - name: report + in: body + required: true + schema: + type: object + properties: + secrets_scan: + type: object + responses: + '200': + description: OK + schema: + $ref: '#/definitions/DeployValidationsReport' + /deploys/{deploy_id}/lock: post: operationId: lockDeploy @@ -2727,6 +2755,30 @@ paths: default: $ref: '#/responses/error' definitions: + DeployValidationsReport: + type: object + properties: + id: + type: string + description: The id of the deploy validations report + deploy_id: + type: string + description: The id of the deploy + secret_scan_result: + $ref: '#/definitions/DeployValidationsReport_SecretScanResult' + + DeployValidationsReport_SecretScanResult: + type: object + properties: + scannedFilesCount: + type: integer + description: The number of files scanned + secretsScanMatches: + type: array + items: + type: string + description: The list of secrets scan matches + splitTestSetup: type: object properties: @@ -3226,6 +3278,8 @@ definitions: type: string error_message: type: string + deploy_validations_report: + $ref: '#/definitions/DeployValidationsReport' branch: type: string commit_ref: From a37a2f728704d0c183b138a2510ecff87b44af4a Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Wed, 16 Apr 2025 18:27:29 +0100 Subject: [PATCH 2/2] feat: tweak deploy validations report --- go/models/deploy.go | 25 ------------------------- swagger.yml | 2 -- 2 files changed, 27 deletions(-) diff --git a/go/models/deploy.go b/go/models/deploy.go index 3c05495b..72d6e1ee 100644 --- a/go/models/deploy.go +++ b/go/models/deploy.go @@ -45,9 +45,6 @@ type Deploy struct { // deploy url DeployURL string `json:"deploy_url,omitempty"` - // deploy validations report - DeployValidationsReport *DeployValidationsReport `json:"deploy_validations_report,omitempty"` - // draft Draft bool `json:"draft,omitempty"` @@ -116,10 +113,6 @@ type Deploy struct { func (m *Deploy) Validate(formats strfmt.Registry) error { var res []error - if err := m.validateDeployValidationsReport(formats); err != nil { - res = append(res, err) - } - if err := m.validateFunctionSchedules(formats); err != nil { res = append(res, err) } @@ -130,24 +123,6 @@ func (m *Deploy) Validate(formats strfmt.Registry) error { return nil } -func (m *Deploy) validateDeployValidationsReport(formats strfmt.Registry) error { - - if swag.IsZero(m.DeployValidationsReport) { // not required - return nil - } - - if m.DeployValidationsReport != nil { - if err := m.DeployValidationsReport.Validate(formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("deploy_validations_report") - } - return err - } - } - - return nil -} - func (m *Deploy) validateFunctionSchedules(formats strfmt.Registry) error { if swag.IsZero(m.FunctionSchedules) { // not required diff --git a/swagger.yml b/swagger.yml index 8b7c8a27..e54459cf 100644 --- a/swagger.yml +++ b/swagger.yml @@ -3278,8 +3278,6 @@ definitions: type: string error_message: type: string - deploy_validations_report: - $ref: '#/definitions/DeployValidationsReport' branch: type: string commit_ref: