Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cor-653): handle variable description #402

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/pkg/errors v0.9.1
github.com/qovery/qovery-client-go v0.0.0-20240625123858-611e64237ed4
github.com/qovery/qovery-client-go v0.0.0-20240704083949-6fb88200a466
github.com/schollz/progressbar/v3 v3.13.0
github.com/sethvargo/go-envconfig v0.9.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ github.com/qovery/qovery-client-go v0.0.0-20240618145737-8fd8c6389642 h1:zXFbs1K
github.com/qovery/qovery-client-go v0.0.0-20240618145737-8fd8c6389642/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240625123858-611e64237ed4 h1:xJJo8LX+5QrM7tUFttGusd36O+0VRrHhasK2iNO0cj8=
github.com/qovery/qovery-client-go v0.0.0-20240625123858-611e64237ed4/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240703082440-2080637688a4 h1:W5OIjJ6jP/LG4Y2yHQC+qkVJ2igqnIr8UNgmXLL0fH8=
github.com/qovery/qovery-client-go v0.0.0-20240703082440-2080637688a4/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240704083949-6fb88200a466 h1:YIrTKWQapfDGKTUh7ia8yDsYN+q1sIMSA+IdpF7zdBM=
github.com/qovery/qovery-client-go v0.0.0-20240704083949-6fb88200a466/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
32 changes: 18 additions & 14 deletions internal/domain/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func (s Secrets) IsValid() bool {
}

type Secret struct {
ID uuid.UUID `validate:"required"`
Scope variable.Scope `validate:"required"`
Key string `validate:"required"`
Type string
ID uuid.UUID `validate:"required"`
Scope variable.Scope `validate:"required"`
Key string `validate:"required"`
Type string
Description string
}

// Validate returns an error to tell whether the Secret domain model is valid or not.
Expand All @@ -75,10 +76,11 @@ func (s Secret) IsValid() bool {
// NewSecretParams represents the arguments needed to create a Secret.
type NewSecretsParams = []NewSecretParams
type NewSecretParams struct {
SecretID string
Scope string
Key string
Type string
SecretID string
Scope string
Key string
Type string
Description string
}

// NewSecret returns a new instance of a Secret domain model.
Expand All @@ -98,10 +100,11 @@ func NewSecret(params NewSecretParams) (*Secret, error) {
}

v := &Secret{
ID: secretsUUID,
Key: params.Key,
Scope: *scope,
Type: params.Type,
ID: secretsUUID,
Key: params.Key,
Scope: *scope,
Type: params.Type,
Description: params.Description,
}

if err := v.Validate(); err != nil {
Expand All @@ -113,8 +116,9 @@ func NewSecret(params NewSecretParams) (*Secret, error) {

// UpsertRequest represents the parameters needed to create & update a Secret.
type UpsertRequest struct {
Key string `validate:"required"`
Value string
Key string `validate:"required"`
Value string
Description string
}

// Validate returns an error to tell whether the UpsertRequest is valid or not.
Expand Down
38 changes: 21 additions & 17 deletions internal/domain/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func (vv Variables) IsValid() bool {
}

type Variable struct {
ID uuid.UUID `validate:"required"`
Scope Scope `validate:"required"`
Key string `validate:"required"`
Value string
Type string
ID uuid.UUID `validate:"required"`
Scope Scope `validate:"required"`
Key string `validate:"required"`
Value string
Type string
Description string
}

// Validate returns an error to tell whether the Variable domain model is valid or not.
Expand All @@ -68,11 +69,12 @@ func (v Variable) IsValid() bool {
// NewVariableParams represents the arguments needed to create a Variable.
type NewVariablesParams = []NewVariableParams
type NewVariableParams struct {
VariableID string
Scope string
Key string
Value string
Type string
VariableID string
Scope string
Key string
Value string
Type string
Description string
}

// NewVariable returns a new instance of a Variable domain model.
Expand All @@ -92,11 +94,12 @@ func NewVariable(params NewVariableParams) (*Variable, error) {
}

v := &Variable{
ID: variableUUID,
Key: params.Key,
Value: params.Value,
Scope: *scope,
Type: params.Type,
ID: variableUUID,
Key: params.Key,
Value: params.Value,
Scope: *scope,
Type: params.Type,
Description: params.Description,
}

if err := v.Validate(); err != nil {
Expand All @@ -108,8 +111,9 @@ func NewVariable(params NewVariableParams) (*Variable, error) {

// UpsertRequest represents the parameters needed to create & update a Variable.
type UpsertRequest struct {
Key string `validate:"required"`
Value string
Key string `validate:"required"`
Value string
Description string
}

// Validate returns an error to tell whether the UpsertRequest is valid or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (p containerEnvironmentVariablesQoveryAPI) Delete(ctx context.Context, cont
func (p containerEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context, containerID string, request variable.UpsertRequest, aliasedVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.ContainerEnvironmentVariableAPI.
CreateContainerEnvironmentVariableAlias(ctx, containerID, aliasedVariableId).
Key(qovery.Key{Key: request.Key}).
Key(qovery.Key{
Key: request.Key,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 400 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceContainerEnvironmentVariable, request.Key, resp, err)
Expand All @@ -92,7 +95,10 @@ func (p containerEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context,
func (p containerEnvironmentVariablesQoveryAPI) CreateOverride(ctx context.Context, containerID string, request variable.UpsertRequest, overriddenVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.ContainerEnvironmentVariableAPI.
CreateContainerEnvironmentVariableOverride(ctx, containerID, overriddenVariableId).
Value(qovery.Value{Value: &request.Value}).
Value(qovery.Value{
Value: &request.Value,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 400 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceContainerEnvironmentVariable, request.Key, resp, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func newQoveryEnvSecretVariableRequestFromDomain(request secret.UpsertRequest, p
IsSecret: true,
VariableScope: parentScope,
VariableParentId: parentId,
Description: *qovery.NewNullableString(&request.Description),
}
}

Expand All @@ -36,17 +37,19 @@ func newDomainEnvSecretFromQovery(v *qovery.VariableResponse) (*secret.Secret, e
}

return secret.NewSecret(secret.NewSecretParams{
SecretID: v.GetId(),
Scope: string(v.Scope),
Key: v.GetKey(),
Type: string(v.VariableType),
SecretID: v.GetId(),
Scope: string(v.Scope),
Key: v.GetKey(),
Type: string(v.VariableType),
Description: *v.Description,
})
}

func newQoveryEnvSecretEditRequestFromDomain(request secret.UpsertRequest) qovery.VariableEditRequest {
return qovery.VariableEditRequest{
Key: request.Key,
Value: request.Value,
Key: request.Key,
Value: request.Value,
Description: *qovery.NewNullableString(&request.Description),
}
}

Expand All @@ -55,6 +58,7 @@ func newQoveryEnvSecretCreateAliasRequestFromDomain(request secret.UpsertRequest
Key: request.Key,
AliasScope: parentScope,
AliasParentId: parentId,
Description: *qovery.NewNullableString(&request.Description),
}
}

Expand All @@ -63,5 +67,6 @@ func newQoveryEnvSecretCreateOverrideRequestFromDomain(request secret.UpsertRequ
Value: request.Value,
OverrideScope: parentScope,
OverrideParentId: parentId,
Description: *qovery.NewNullableString(&request.Description),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ func newQoveryEnvVariableRequestFromDomain(request variable.UpsertRequest, isSec
return qovery.VariableRequest{
Key: request.Key,
Value: request.Value,
MountPath: qovery.NullableString{},
MountPath: qovery.NullableString{}, //TODO: no mountpath?
IsSecret: isSecret,
VariableScope: parentScope,
VariableParentId: parentId,
Description: *qovery.NewNullableString(&request.Description),
}
}

Expand All @@ -21,6 +22,7 @@ func newQoveryEnvVariableCreateAliasRequestFromDomain(request variable.UpsertReq
Key: request.Key,
AliasScope: parentScope,
AliasParentId: parentId,
Description: *qovery.NewNullableString(&request.Description),
}
}

Expand All @@ -29,6 +31,7 @@ func newQoveryEnvVariableCreateOverrideRequestFromDomain(request variable.Upsert
Value: request.Value,
OverrideScope: parentScope,
OverrideParentId: parentId,
Description: *qovery.NewNullableString(&request.Description),
}
}

Expand Down Expand Up @@ -57,17 +60,19 @@ func newDomainEnvVariableFromQovery(v *qovery.VariableResponse) (*variable.Varia
}

return variable.NewVariable(variable.NewVariableParams{
VariableID: v.GetId(),
Scope: string(v.Scope),
Key: v.Key,
Value: value,
Type: string(v.VariableType),
VariableID: v.GetId(),
Scope: string(v.Scope),
Key: v.Key,
Value: value,
Type: string(v.VariableType),
Description: *v.Description,
})
}

func newQoveryEnvVariableEditRequestFromDomain(request variable.UpsertRequest) qovery.VariableEditRequest {
return qovery.VariableEditRequest{
Key: request.Key,
Value: request.Value,
Key: request.Key,
Value: request.Value,
Description: *qovery.NewNullableString(&request.Description),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (p environmentEnvironmentVariablesQoveryAPI) Delete(ctx context.Context, en
func (p environmentEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context, environmentID string, request variable.UpsertRequest, aliasedVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.EnvironmentVariableAPI.
CreateEnvironmentEnvironmentVariableAlias(ctx, environmentID, aliasedVariableId).
Key(qovery.Key{Key: request.Key}).
Key(qovery.Key{
Key: request.Key,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceEnvironmentEnvironmentVariable, environmentID, resp, err)
Expand All @@ -92,7 +95,10 @@ func (p environmentEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Contex
func (p environmentEnvironmentVariablesQoveryAPI) CreateOverride(ctx context.Context, environmentID string, request variable.UpsertRequest, overriddenVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.EnvironmentVariableAPI.
CreateEnvironmentEnvironmentVariableOverride(ctx, environmentID, overriddenVariableId).
Value(qovery.Value{Value: &request.Value}).
Value(qovery.Value{
Value: &request.Value,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceEnvironmentEnvironmentVariable, environmentID, resp, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (p jobEnvironmentVariablesQoveryAPI) Delete(ctx context.Context, jobID stri
func (p jobEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context, jobID string, request variable.UpsertRequest, aliasedVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.JobEnvironmentVariableAPI.
CreateJobEnvironmentVariableAlias(ctx, jobID, aliasedVariableId).
Key(qovery.Key{Key: request.Key}).
Key(qovery.Key{
Key: request.Key,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceJobEnvironmentVariable, jobID, resp, err)
Expand All @@ -92,7 +95,10 @@ func (p jobEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context, jobID
func (p jobEnvironmentVariablesQoveryAPI) CreateOverride(ctx context.Context, jobID string, request variable.UpsertRequest, overriddenVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.JobEnvironmentVariableAPI.
CreateJobEnvironmentVariableOverride(ctx, jobID, overriddenVariableId).
Value(qovery.Value{Value: &request.Value}).
Value(qovery.Value{
Value: &request.Value,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceJobEnvironmentVariable, jobID, resp, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (p jobSecretsQoveryAPI) Delete(ctx context.Context, jobID string, credentia
func (p jobSecretsQoveryAPI) CreateAlias(ctx context.Context, jobID string, request secret.UpsertRequest, aliasedSecretId string) (*secret.Secret, error) {
v, resp, err := p.client.JobSecretAPI.
CreateJobSecretAlias(ctx, jobID, aliasedSecretId).
Key(qovery.Key{Key: request.Key}).
Key(qovery.Key{
Key: request.Key,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceJobSecret, jobID, resp, err)
Expand All @@ -93,7 +96,10 @@ func (p jobSecretsQoveryAPI) CreateAlias(ctx context.Context, jobID string, requ
func (p jobSecretsQoveryAPI) CreateOverride(ctx context.Context, jobID string, request secret.UpsertRequest, overriddenSecretId string) (*secret.Secret, error) {
v, resp, err := p.client.JobSecretAPI.
CreateJobSecretOverride(ctx, jobID, overriddenSecretId).
Value(qovery.Value{Value: &request.Value}).
Value(qovery.Value{
Value: &request.Value,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceJobSecret, jobID, resp, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (p projectEnvironmentVariablesQoveryAPI) Delete(ctx context.Context, projec
func (p projectEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context, projectID string, request variable.UpsertRequest, aliasedVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.ProjectEnvironmentVariableAPI.
CreateProjectEnvironmentVariableAlias(ctx, projectID, aliasedVariableId).
Key(qovery.Key{Key: request.Key}).
Key(qovery.Key{
Key: request.Key,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceProjectEnvironmentVariable, projectID, resp, err)
Expand All @@ -92,7 +95,10 @@ func (p projectEnvironmentVariablesQoveryAPI) CreateAlias(ctx context.Context, p
func (p projectEnvironmentVariablesQoveryAPI) CreateOverride(ctx context.Context, projectID string, request variable.UpsertRequest, overriddenVariableId string) (*variable.Variable, error) {
v, resp, err := p.client.ProjectEnvironmentVariableAPI.
CreateProjectEnvironmentVariableOverride(ctx, projectID, overriddenVariableId).
Value(qovery.Value{Value: &request.Value}).
Value(qovery.Value{
Value: &request.Value,
Description: *qovery.NewNullableString(&request.Description),
}).
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceProjectEnvironmentVariable, projectID, resp, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (p projectSecretsQoveryAPI) CreateAlias(ctx context.Context, projectId stri
v, resp, err := p.client.ProjectSecretAPI.
CreateProjectSecretAlias(ctx, projectId, aliasedSecretId).
Key(qovery.Key{Key: request.Key}).
// missing description here
Execute()
if err != nil || resp.StatusCode >= 300 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceProjectSecret, projectId, resp, err)
Expand Down
Loading
Loading