Skip to content

Commit cb6c437

Browse files
committed
Fix empty parameter source and destination
1 parent f825a60 commit cb6c437

File tree

10 files changed

+110
-91
lines changed

10 files changed

+110
-91
lines changed

coderd/parameters.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616

1717
// CreateParameterValueRequest is used to create a new parameter value for a scope.
1818
type CreateParameterValueRequest struct {
19-
Name string `json:"name"`
20-
SourceValue string `json:"source_value"`
21-
SourceScheme database.ParameterSourceScheme `json:"source_scheme"`
22-
DestinationScheme database.ParameterDestinationScheme `json:"destination_scheme"`
23-
DestinationValue string `json:"destination_value"`
19+
Name string `json:"name" validate:"required"`
20+
SourceValue string `json:"source_value" validate:"required"`
21+
SourceScheme database.ParameterSourceScheme `json:"source_scheme" validate:"oneof=data,required"`
22+
DestinationScheme database.ParameterDestinationScheme `json:"destination_scheme" validate:"oneof=environment_variable provisioner_variable,required"`
23+
DestinationValue string `json:"destination_value" validate:"required"`
2424
}
2525

2626
// ParameterValue represents a set value for the scope.

coderd/projecthistory.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ type ProjectParameter struct {
3737
CreatedAt time.Time `json:"created_at"`
3838
ProjectHistoryID uuid.UUID `json:"project_history_id"`
3939
Name string `json:"name"`
40-
Description string `json:"description"`
41-
DefaultSourceScheme database.ParameterSourceScheme `json:"default_source_scheme"`
42-
DefaultSourceValue string `json:"default_source_value"`
40+
Description string `json:"description,omitempty"`
41+
DefaultSourceScheme database.ParameterSourceScheme `json:"default_source_scheme,omitempty"`
42+
DefaultSourceValue string `json:"default_source_value,omitempty"`
4343
AllowOverrideSource bool `json:"allow_override_source"`
44-
DefaultDestinationScheme database.ParameterDestinationScheme `json:"default_destination_scheme"`
45-
DefaultDestinationValue string `json:"default_destination_value"`
44+
DefaultDestinationScheme database.ParameterDestinationScheme `json:"default_destination_scheme,omitempty"`
45+
DefaultDestinationValue string `json:"default_destination_value,omitempty"`
4646
AllowOverrideDestination bool `json:"allow_override_destination"`
4747
DefaultRefresh string `json:"default_refresh"`
4848
RedisplayValue bool `json:"redisplay_value"`
49-
ValidationError string `json:"validation_error"`
50-
ValidationCondition string `json:"validation_condition"`
51-
ValidationTypeSystem database.ParameterTypeSystem `json:"validation_type_system"`
52-
ValidationValueType string `json:"validation_value_type"`
49+
ValidationError string `json:"validation_error,omitempty"`
50+
ValidationCondition string `json:"validation_condition,omitempty"`
51+
ValidationTypeSystem database.ParameterTypeSystem `json:"validation_type_system,omitempty"`
52+
ValidationValueType string `json:"validation_value_type,omitempty"`
5353
}
5454

5555
// CreateProjectHistoryRequest enables callers to create a new Project Version.

coderd/projects_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ func TestProjects(t *testing.T) {
140140
require.NoError(t, err)
141141
var buffer bytes.Buffer
142142
writer := tar.NewWriter(&buffer)
143-
content := `variable "example" {}`
143+
content := `variable "example" {
144+
default = "hi"
145+
}`
144146
err = writer.WriteHeader(&tar.Header{
145147
Name: "main.tf",
146148
Size: int64(len(content)),

coderd/provisionerdaemons.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
451451
ValidationValueType: protoParameter.ValidationValueType,
452452
ValidationTypeSystem: validationTypeSystem,
453453

454+
DefaultSourceScheme: database.ParameterSourceSchemeNone,
455+
DefaultDestinationScheme: database.ParameterDestinationSchemeNone,
456+
454457
AllowOverrideDestination: protoParameter.AllowOverrideDestination,
455458
AllowOverrideSource: protoParameter.AllowOverrideSource,
456459
}
@@ -574,6 +577,8 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
574577

575578
func convertValidationTypeSystem(typeSystem sdkproto.ParameterSchema_TypeSystem) (database.ParameterTypeSystem, error) {
576579
switch typeSystem {
580+
case sdkproto.ParameterSchema_None:
581+
return database.ParameterTypeSystemNone, nil
577582
case sdkproto.ParameterSchema_HCL:
578583
return database.ParameterTypeSystemHCL, nil
579584
default:

database/dump.sql

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/migrations/000002_projects.up.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ CREATE TABLE project_history (
4646
);
4747

4848
-- Types of parameters the automator supports.
49-
CREATE TYPE parameter_type_system AS ENUM ('hcl');
49+
CREATE TYPE parameter_type_system AS ENUM ('none', 'hcl');
5050

5151
-- Supported schemes for a parameter source.
52-
CREATE TYPE parameter_source_scheme AS ENUM('data');
52+
CREATE TYPE parameter_source_scheme AS ENUM('none', 'data');
5353

5454
-- Supported schemes for a parameter destination.
55-
CREATE TYPE parameter_destination_scheme AS ENUM('environment_variable', 'provisioner_variable');
55+
CREATE TYPE parameter_destination_scheme AS ENUM('none', 'environment_variable', 'provisioner_variable');
5656

5757
-- Stores project version parameters parsed on import.
5858
-- No secrets are stored here.

database/models.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/parse_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ func TestParse(t *testing.T) {
9595
Type: &proto.Parse_Response_Complete{
9696
Complete: &proto.Parse_Complete{
9797
ParameterSchemas: []*proto.ParameterSchema{{
98-
Name: "A",
99-
ValidationCondition: `var.A == "value"`,
98+
Name: "A",
99+
ValidationCondition: `var.A == "value"`,
100+
ValidationTypeSystem: proto.ParameterSchema_HCL,
100101
},
101102
},
102103
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy