mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add dry run for provisioners (#178)
* refactor: Rename ProjectParameter to ProjectVersionParameter This was confusing with ParameterValue before. It still is a bit, but this should help distinguish scope. * Add project version resources table * Allow project parameters to optionally have user and workspace * Add dry run for provisioners * Add resource detection on project import
This commit is contained in:
@@ -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.
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
||||
@@ -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 {
|
||||
@@ -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(),
|
||||
SourceScheme: database.ParameterSourceSchemeData,
|
||||
SourceValue: "nop",
|
||||
DestinationScheme: database.ParameterDestinationSchemeEnvironmentVariable,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user