mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
feat: Add "coder projects create" command (#246)
* Refactor parameter parsing to return nil values if none computed * Refactor parameter to allow for hiding redisplay * Refactor parameters to enable schema matching * Refactor provisionerd to dynamically update parameter schemas * Refactor job update for provisionerd * Handle multiple states correctly when provisioning a project * Add project import job resource table * Basic creation flow works! * Create project fully works!!! * Only show job status if completed * Add create workspace support * Replace Netflix/go-expect with ActiveState * Fix linting errors * Use forked chzyer/readline * Add create workspace CLI * Add CLI test * Move jobs to their own APIs * Remove go-expect * Fix requested changes * Skip workspacecreate test on windows
This commit is contained in:
@ -271,7 +271,7 @@ func (q *sqlQuerier) GetOrganizationsByUserID(ctx context.Context, userID string
|
||||
|
||||
const getParameterSchemasByJobID = `-- name: GetParameterSchemasByJobID :many
|
||||
SELECT
|
||||
id, created_at, job_id, name, description, default_source_scheme, default_source_value, allow_override_source, default_destination_scheme, default_destination_value, allow_override_destination, default_refresh, redisplay_value, validation_error, validation_condition, validation_type_system, validation_value_type
|
||||
id, created_at, job_id, name, description, default_source_scheme, default_source_value, allow_override_source, default_destination_scheme, allow_override_destination, default_refresh, redisplay_value, validation_error, validation_condition, validation_type_system, validation_value_type
|
||||
FROM
|
||||
parameter_schema
|
||||
WHERE
|
||||
@ -297,7 +297,6 @@ func (q *sqlQuerier) GetParameterSchemasByJobID(ctx context.Context, jobID uuid.
|
||||
&i.DefaultSourceValue,
|
||||
&i.AllowOverrideSource,
|
||||
&i.DefaultDestinationScheme,
|
||||
&i.DefaultDestinationValue,
|
||||
&i.AllowOverrideDestination,
|
||||
&i.DefaultRefresh,
|
||||
&i.RedisplayValue,
|
||||
@ -321,7 +320,7 @@ func (q *sqlQuerier) GetParameterSchemasByJobID(ctx context.Context, jobID uuid.
|
||||
|
||||
const getParameterValuesByScope = `-- name: GetParameterValuesByScope :many
|
||||
SELECT
|
||||
id, name, created_at, updated_at, scope, scope_id, source_scheme, source_value, destination_scheme, destination_value
|
||||
id, name, created_at, updated_at, scope, scope_id, source_scheme, source_value, destination_scheme
|
||||
FROM
|
||||
parameter_value
|
||||
WHERE
|
||||
@ -353,7 +352,6 @@ func (q *sqlQuerier) GetParameterValuesByScope(ctx context.Context, arg GetParam
|
||||
&i.SourceScheme,
|
||||
&i.SourceValue,
|
||||
&i.DestinationScheme,
|
||||
&i.DestinationValue,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -426,6 +424,45 @@ func (q *sqlQuerier) GetProjectByOrganizationAndName(ctx context.Context, arg Ge
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getProjectImportJobResourcesByJobID = `-- name: GetProjectImportJobResourcesByJobID :many
|
||||
SELECT
|
||||
id, created_at, job_id, transition, type, name
|
||||
FROM
|
||||
project_import_job_resource
|
||||
WHERE
|
||||
job_id = $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetProjectImportJobResourcesByJobID(ctx context.Context, jobID uuid.UUID) ([]ProjectImportJobResource, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getProjectImportJobResourcesByJobID, jobID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ProjectImportJobResource
|
||||
for rows.Next() {
|
||||
var i ProjectImportJobResource
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.JobID,
|
||||
&i.Transition,
|
||||
&i.Type,
|
||||
&i.Name,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getProjectVersionByID = `-- name: GetProjectVersionByID :one
|
||||
SELECT
|
||||
id, project_id, created_at, updated_at, name, description, import_job_id
|
||||
@ -1378,7 +1415,6 @@ INSERT INTO
|
||||
default_source_value,
|
||||
allow_override_source,
|
||||
default_destination_scheme,
|
||||
default_destination_value,
|
||||
allow_override_destination,
|
||||
default_refresh,
|
||||
redisplay_value,
|
||||
@ -1404,9 +1440,8 @@ VALUES
|
||||
$13,
|
||||
$14,
|
||||
$15,
|
||||
$16,
|
||||
$17
|
||||
) RETURNING id, created_at, job_id, name, description, default_source_scheme, default_source_value, allow_override_source, default_destination_scheme, default_destination_value, allow_override_destination, default_refresh, redisplay_value, validation_error, validation_condition, validation_type_system, validation_value_type
|
||||
$16
|
||||
) RETURNING id, created_at, job_id, name, description, default_source_scheme, default_source_value, allow_override_source, default_destination_scheme, allow_override_destination, default_refresh, redisplay_value, validation_error, validation_condition, validation_type_system, validation_value_type
|
||||
`
|
||||
|
||||
type InsertParameterSchemaParams struct {
|
||||
@ -1416,10 +1451,9 @@ type InsertParameterSchemaParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
DefaultSourceScheme ParameterSourceScheme `db:"default_source_scheme" json:"default_source_scheme"`
|
||||
DefaultSourceValue sql.NullString `db:"default_source_value" json:"default_source_value"`
|
||||
DefaultSourceValue string `db:"default_source_value" json:"default_source_value"`
|
||||
AllowOverrideSource bool `db:"allow_override_source" json:"allow_override_source"`
|
||||
DefaultDestinationScheme ParameterDestinationScheme `db:"default_destination_scheme" json:"default_destination_scheme"`
|
||||
DefaultDestinationValue sql.NullString `db:"default_destination_value" json:"default_destination_value"`
|
||||
AllowOverrideDestination bool `db:"allow_override_destination" json:"allow_override_destination"`
|
||||
DefaultRefresh string `db:"default_refresh" json:"default_refresh"`
|
||||
RedisplayValue bool `db:"redisplay_value" json:"redisplay_value"`
|
||||
@ -1440,7 +1474,6 @@ func (q *sqlQuerier) InsertParameterSchema(ctx context.Context, arg InsertParame
|
||||
arg.DefaultSourceValue,
|
||||
arg.AllowOverrideSource,
|
||||
arg.DefaultDestinationScheme,
|
||||
arg.DefaultDestinationValue,
|
||||
arg.AllowOverrideDestination,
|
||||
arg.DefaultRefresh,
|
||||
arg.RedisplayValue,
|
||||
@ -1460,7 +1493,6 @@ func (q *sqlQuerier) InsertParameterSchema(ctx context.Context, arg InsertParame
|
||||
&i.DefaultSourceValue,
|
||||
&i.AllowOverrideSource,
|
||||
&i.DefaultDestinationScheme,
|
||||
&i.DefaultDestinationValue,
|
||||
&i.AllowOverrideDestination,
|
||||
&i.DefaultRefresh,
|
||||
&i.RedisplayValue,
|
||||
@ -1483,11 +1515,10 @@ INSERT INTO
|
||||
scope_id,
|
||||
source_scheme,
|
||||
source_value,
|
||||
destination_scheme,
|
||||
destination_value
|
||||
destination_scheme
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id, name, created_at, updated_at, scope, scope_id, source_scheme, source_value, destination_scheme, destination_value
|
||||
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id, name, created_at, updated_at, scope, scope_id, source_scheme, source_value, destination_scheme
|
||||
`
|
||||
|
||||
type InsertParameterValueParams struct {
|
||||
@ -1500,7 +1531,6 @@ type InsertParameterValueParams struct {
|
||||
SourceScheme ParameterSourceScheme `db:"source_scheme" json:"source_scheme"`
|
||||
SourceValue string `db:"source_value" json:"source_value"`
|
||||
DestinationScheme ParameterDestinationScheme `db:"destination_scheme" json:"destination_scheme"`
|
||||
DestinationValue string `db:"destination_value" json:"destination_value"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertParameterValue(ctx context.Context, arg InsertParameterValueParams) (ParameterValue, error) {
|
||||
@ -1514,7 +1544,6 @@ func (q *sqlQuerier) InsertParameterValue(ctx context.Context, arg InsertParamet
|
||||
arg.SourceScheme,
|
||||
arg.SourceValue,
|
||||
arg.DestinationScheme,
|
||||
arg.DestinationValue,
|
||||
)
|
||||
var i ParameterValue
|
||||
err := row.Scan(
|
||||
@ -1527,7 +1556,6 @@ func (q *sqlQuerier) InsertParameterValue(ctx context.Context, arg InsertParamet
|
||||
&i.SourceScheme,
|
||||
&i.SourceValue,
|
||||
&i.DestinationScheme,
|
||||
&i.DestinationValue,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -1580,6 +1608,43 @@ func (q *sqlQuerier) InsertProject(ctx context.Context, arg InsertProjectParams)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertProjectImportJobResource = `-- name: InsertProjectImportJobResource :one
|
||||
INSERT INTO
|
||||
project_import_job_resource (id, created_at, job_id, transition, type, name)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6) RETURNING id, created_at, job_id, transition, type, name
|
||||
`
|
||||
|
||||
type InsertProjectImportJobResourceParams struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
Transition WorkspaceTransition `db:"transition" json:"transition"`
|
||||
Type string `db:"type" json:"type"`
|
||||
Name string `db:"name" json:"name"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertProjectImportJobResource(ctx context.Context, arg InsertProjectImportJobResourceParams) (ProjectImportJobResource, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertProjectImportJobResource,
|
||||
arg.ID,
|
||||
arg.CreatedAt,
|
||||
arg.JobID,
|
||||
arg.Transition,
|
||||
arg.Type,
|
||||
arg.Name,
|
||||
)
|
||||
var i ProjectImportJobResource
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.JobID,
|
||||
&i.Transition,
|
||||
&i.Type,
|
||||
&i.Name,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertProjectVersion = `-- name: InsertProjectVersion :one
|
||||
INSERT INTO
|
||||
project_version (
|
||||
|
Reference in New Issue
Block a user