diff --git a/api/jobs/v1alpha1/jobs_sdk.go b/api/jobs/v1alpha1/jobs_sdk.go index 8153dd570..38dc2cb77 100644 --- a/api/jobs/v1alpha1/jobs_sdk.go +++ b/api/jobs/v1alpha1/jobs_sdk.go @@ -162,6 +162,16 @@ func (enum *ListJobRunsRequestOrderBy) UnmarshalJSON(data []byte) error { return nil } +// SecretEnvVar: secret env var. +type SecretEnvVar struct { + Name string `json:"name"` +} + +// SecretFile: secret file. +type SecretFile struct { + Path string `json:"path"` +} + // CronSchedule: cron schedule. type CronSchedule struct { // Schedule: uNIX cron schedule to run job (e.g., '* * * * *'). @@ -178,6 +188,34 @@ type CreateJobDefinitionRequestCronScheduleConfig struct { Timezone string `json:"timezone"` } +// CreateJobDefinitionSecretsRequestSecretConfig: create job definition secrets request secret config. +type CreateJobDefinitionSecretsRequestSecretConfig struct { + SecretManagerID string `json:"secret_manager_id"` + + SecretManagerVersion string `json:"secret_manager_version"` + + // Precisely one of Path, EnvVarName must be set. + Path *string `json:"path,omitempty"` + + // Precisely one of Path, EnvVarName must be set. + EnvVarName *string `json:"env_var_name,omitempty"` +} + +// Secret: secret. +type Secret struct { + SecretID string `json:"secret_id"` + + SecretManagerID string `json:"secret_manager_id"` + + SecretManagerVersion string `json:"secret_manager_version"` + + // Precisely one of File, EnvVar must be set. + File *SecretFile `json:"file,omitempty"` + + // Precisely one of File, EnvVar must be set. + EnvVar *SecretEnvVar `json:"env_var,omitempty"` +} + // JobDefinition: job definition. type JobDefinition struct { ID string `json:"id"` @@ -302,6 +340,23 @@ type CreateJobDefinitionRequest struct { CronSchedule *CreateJobDefinitionRequestCronScheduleConfig `json:"cron_schedule,omitempty"` } +// CreateJobDefinitionSecretsRequest: create job definition secrets request. +type CreateJobDefinitionSecretsRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + // JobDefinitionID: UUID of the job definition to get. + JobDefinitionID string `json:"-"` + + // Secrets: secrets to inject into the job. + Secrets []*CreateJobDefinitionSecretsRequestSecretConfig `json:"secrets"` +} + +// CreateJobDefinitionSecretsResponse: create job definition secrets response. +type CreateJobDefinitionSecretsResponse struct { + Secrets []*Secret `json:"secrets"` +} + // DeleteJobDefinitionRequest: delete job definition request. type DeleteJobDefinitionRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -311,6 +366,16 @@ type DeleteJobDefinitionRequest struct { JobDefinitionID string `json:"-"` } +// DeleteJobDefinitionSecretRequest: delete job definition secret request. +type DeleteJobDefinitionSecretRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + JobDefinitionID string `json:"-"` + + SecretID string `json:"-"` +} + // GetJobDefinitionRequest: get job definition request. type GetJobDefinitionRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -320,6 +385,16 @@ type GetJobDefinitionRequest struct { JobDefinitionID string `json:"-"` } +// GetJobDefinitionSecretRequest: get job definition secret request. +type GetJobDefinitionSecretRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + JobDefinitionID string `json:"-"` + + SecretID string `json:"-"` +} + // GetJobRunRequest: get job run request. type GetJobRunRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -329,6 +404,40 @@ type GetJobRunRequest struct { JobRunID string `json:"-"` } +// ListJobDefinitionSecretsRequest: list job definition secrets request. +type ListJobDefinitionSecretsRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + JobDefinitionID string `json:"-"` +} + +// ListJobDefinitionSecretsResponse: list job definition secrets response. +type ListJobDefinitionSecretsResponse struct { + Secrets []*Secret `json:"secrets"` + + TotalCount uint64 `json:"total_count"` +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListJobDefinitionSecretsResponse) UnsafeGetTotalCount() uint64 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListJobDefinitionSecretsResponse) UnsafeAppend(res interface{}) (uint64, error) { + results, ok := res.(*ListJobDefinitionSecretsResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Secrets = append(r.Secrets, results.Secrets...) + r.TotalCount += uint64(len(results.Secrets)) + return uint64(len(results.Secrets)), nil +} + // ListJobDefinitionsRequest: list job definitions request. type ListJobDefinitionsRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -498,6 +607,24 @@ type UpdateJobDefinitionRequest struct { CronSchedule *UpdateJobDefinitionRequestCronScheduleConfig `json:"cron_schedule,omitempty"` } +// UpdateJobDefinitionSecretRequest: update job definition secret request. +type UpdateJobDefinitionSecretRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + JobDefinitionID string `json:"-"` + + SecretID string `json:"-"` + + SecretManagerVersion *string `json:"secret_manager_version,omitempty"` + + // Precisely one of Path, EnvVarName must be set. + Path *string `json:"path,omitempty"` + + // Precisely one of Path, EnvVarName must be set. + EnvVarName *string `json:"env_var_name,omitempty"` +} + // This API allows you to manage your Serverless Jobs. type API struct { client *scw.Client @@ -726,6 +853,181 @@ func (s *API) StartJobDefinition(req *StartJobDefinitionRequest, opts ...scw.Req return &resp, nil } +// CreateJobDefinitionSecrets: +func (s *API) CreateJobDefinitionSecrets(req *CreateJobDefinitionSecretsRequest, opts ...scw.RequestOption) (*CreateJobDefinitionSecretsResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.JobDefinitionID) == "" { + return nil, errors.New("field JobDefinitionID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/serverless-jobs/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/job-definitions/" + fmt.Sprint(req.JobDefinitionID) + "/secrets", + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp CreateJobDefinitionSecretsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// GetJobDefinitionSecret: +func (s *API) GetJobDefinitionSecret(req *GetJobDefinitionSecretRequest, opts ...scw.RequestOption) (*Secret, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.JobDefinitionID) == "" { + return nil, errors.New("field JobDefinitionID cannot be empty in request") + } + + if fmt.Sprint(req.SecretID) == "" { + return nil, errors.New("field SecretID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/serverless-jobs/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/job-definitions/" + fmt.Sprint(req.JobDefinitionID) + "/secrets/" + fmt.Sprint(req.SecretID) + "", + } + + var resp Secret + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// ListJobDefinitionSecrets: +func (s *API) ListJobDefinitionSecrets(req *ListJobDefinitionSecretsRequest, opts ...scw.RequestOption) (*ListJobDefinitionSecretsResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.JobDefinitionID) == "" { + return nil, errors.New("field JobDefinitionID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/serverless-jobs/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/job-definitions/" + fmt.Sprint(req.JobDefinitionID) + "/secrets", + } + + var resp ListJobDefinitionSecretsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UpdateJobDefinitionSecret: +func (s *API) UpdateJobDefinitionSecret(req *UpdateJobDefinitionSecretRequest, opts ...scw.RequestOption) (*Secret, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.JobDefinitionID) == "" { + return nil, errors.New("field JobDefinitionID cannot be empty in request") + } + + if fmt.Sprint(req.SecretID) == "" { + return nil, errors.New("field SecretID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PATCH", + Path: "/serverless-jobs/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/job-definitions/" + fmt.Sprint(req.JobDefinitionID) + "/secrets/" + fmt.Sprint(req.SecretID) + "", + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Secret + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// DeleteJobDefinitionSecret: +func (s *API) DeleteJobDefinitionSecret(req *DeleteJobDefinitionSecretRequest, opts ...scw.RequestOption) error { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.JobDefinitionID) == "" { + return errors.New("field JobDefinitionID cannot be empty in request") + } + + if fmt.Sprint(req.SecretID) == "" { + return errors.New("field SecretID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/serverless-jobs/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/job-definitions/" + fmt.Sprint(req.JobDefinitionID) + "/secrets/" + fmt.Sprint(req.SecretID) + "", + } + + err = s.client.Do(scwReq, nil, opts...) + if err != nil { + return err + } + return nil +} + // GetJobRun: Get a job run by its unique identifier. func (s *API) GetJobRun(req *GetJobRunRequest, opts ...scw.RequestOption) (*JobRun, error) { var err error