Skip to content

feat: Add dry run for provisioners #178

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

Merged
merged 8 commits into from
Feb 8, 2022
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
Prev Previous commit
Next Next commit
Allow project parameters to optionally have user and workspace
  • Loading branch information
kylecarbs committed Feb 7, 2022
commit 0e7f3807468e4ee7a659d70a1656027c429c07d9
43 changes: 23 additions & 20 deletions coderd/projectparameter/projectparameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import (

// Scope targets identifiers to pull parameters from.
type Scope struct {
OrganizationID string
ProjectID uuid.UUID
ProjectVersionID uuid.UUID
UserID string
WorkspaceID uuid.UUID
WorkspaceHistoryID uuid.UUID
OrganizationID string
ProjectID uuid.UUID
ProjectVersionID uuid.UUID
UserID sql.NullString
WorkspaceID uuid.NullUUID
}

// Value represents a computed parameter.
Expand Down Expand Up @@ -106,22 +105,26 @@ func Compute(ctx context.Context, db database.Store, scope Scope) ([]Value, erro
return nil, err
}

// User parameters come fourth!
err = compute.inject(ctx, database.GetParameterValuesByScopeParams{
Scope: database.ParameterScopeUser,
ScopeID: scope.UserID,
})
if err != nil {
return nil, err
if scope.UserID.Valid {
// User parameters come fourth!
err = compute.inject(ctx, database.GetParameterValuesByScopeParams{
Scope: database.ParameterScopeUser,
ScopeID: scope.UserID.String,
})
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be wrapped?

I think there's a linter that can check for that too.

}
}

// Workspace parameters come last!
err = compute.inject(ctx, database.GetParameterValuesByScopeParams{
Scope: database.ParameterScopeWorkspace,
ScopeID: scope.WorkspaceID.String(),
})
if err != nil {
return nil, err
if scope.WorkspaceID.Valid {
// Workspace parameters come last!
err = compute.inject(ctx, database.GetParameterValuesByScopeParams{
Scope: database.ParameterScopeWorkspace,
ScopeID: scope.WorkspaceID.UUID.String(),
})
if err != nil {
return nil, err
}
}

for _, projectVersionParameter := range compute.projectVersionParametersByName {
Expand Down
13 changes: 10 additions & 3 deletions coderd/projectparameter/projectparameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ func TestCompute(t *testing.T) {
OrganizationID: uuid.New().String(),
ProjectID: uuid.New(),
ProjectVersionID: uuid.New(),
UserID: uuid.NewString(),
WorkspaceID: uuid.NullUUID{
UUID: uuid.New(),
Valid: true,
},
UserID: sql.NullString{
String: uuid.NewString(),
Valid: true,
},
}
}
type projectParameterOptions struct {
Expand Down Expand Up @@ -163,7 +170,7 @@ func TestCompute(t *testing.T) {
ID: uuid.New(),
Name: parameter.Name,
Scope: database.ParameterScopeWorkspace,
ScopeID: scope.WorkspaceID.String(),
ScopeID: scope.WorkspaceID.UUID.String(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since ID is typed as a uuid.UUID, why is it that we can't do the same for ScopeID, to avoid the need to call .String?

Copy link
Member Author

@kylecarbs kylecarbs Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish! We're supporting v1 user and organization IDs, so we have to use string, unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to do a one-time migration? Seems unfortunate that we have to support our past decisions indefinitely 😬

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why not. We could probably just add a UUID column to the users and organizations tables in v1, and use them in v2.

SourceScheme: database.ParameterSourceSchemeData,
SourceValue: "nop",
DestinationScheme: database.ParameterDestinationSchemeEnvironmentVariable,
Expand All @@ -189,7 +196,7 @@ func TestCompute(t *testing.T) {
ID: uuid.New(),
Name: parameter.Name,
Scope: database.ParameterScopeWorkspace,
ScopeID: scope.WorkspaceID.String(),
ScopeID: scope.WorkspaceID.UUID.String(),
SourceScheme: database.ParameterSourceSchemeData,
SourceValue: "nop",
DestinationScheme: database.ParameterDestinationSchemeEnvironmentVariable,
Expand Down