Skip to content

Commit 3cf6193

Browse files
committed
fix pr feedback
1 parent 24d757b commit 3cf6193

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

internal/config/schemas/schema-1.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ definitions:
112112
type: string
113113
enum:
114114
- aws
115-
- gcp
116115
- azure
117-
- terraform_cloud
116+
- gcp
117+
- http
118118
- local
119+
- terraform_cloud
119120
- $ref: "#/definitions/RemoteState"
120121

121122
RemoteState:

internal/state/http.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
// HttpState HTTP backend configuration.
88
type HttpState struct {
99
Address string `mapstructure:"address"`
10-
UpdateMethod string `mapstructure:"update_method" default:"POST"`
10+
UpdateMethod string `mapstructure:"update_method"`
1111
LockAddress string `mapstructure:"lock_address"`
12-
LockMethod string `mapstructure:"lock_method" default:"LOCK"`
12+
LockMethod string `mapstructure:"lock_method"`
1313
UnlockAddress string `mapstructure:"unlock_address"`
14-
UnlockMethod string `mapstructure:"unlock_method" default:"UNLOCK"`
14+
UnlockMethod string `mapstructure:"unlock_method"`
1515
Username string `mapstructure:"username"`
1616
Password string `mapstructure:"password"`
1717
SkipCertVerification bool `mapstructure:"skip_cert_verification" default:"false"`
18-
RetryMax int `mapstructure:"retry_max" default:"2"`
19-
RetryWaitMin int `mapstructure:"retry_wait_min" default:"1"`
20-
RetryWaitMax int `mapstructure:"retry_wait_max" default:"30"`
18+
RetryMax int `mapstructure:"retry_max"`
19+
RetryWaitMin int `mapstructure:"retry_wait_min"`
20+
RetryWaitMax int `mapstructure:"retry_wait_max"`
2121
ClientCertificatePEM string `mapstructure:"client_certificate_pem"`
2222
ClientPrivateKeyPEM string `mapstructure:"client_private_key_pem"`
2323
ClientCACertificatePEM string `mapstructure:"client_ca_certificate_pem"`
@@ -110,22 +110,8 @@ func (hr *HttpRenderer) RemoteState() (string, error) {
110110
111111
config = {
112112
address = "{{ .State.Address }}"
113+
{{- if .State.UpdateMethod }}
113114
update_method = "{{ .State.UpdateMethod }}"
114-
{{- if .State.Username }}
115-
username = "{{ .State.Username }}"
116-
{{- end }}
117-
{{- if .State.Password }}
118-
password = "{{ .State.Password }}"
119-
{{- end }}
120-
skip_cert_verification = {{ .State.SkipCertVerification }}
121-
{{- if gt .State.RetryMax 0 }}
122-
retry_max = {{ .State.RetryMax }}
123-
{{- end }}
124-
{{- if gt .State.RetryWaitMin 0 }}
125-
retry_wait_min = {{ .State.RetryWaitMin }}
126-
{{- end }}
127-
{{- if gt .State.RetryWaitMax 0 }}
128-
retry_wait_max = {{ .State.RetryWaitMax }}
129115
{{- end }}
130116
}
131117
}

internal/state/http_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ import (
55
"testing"
66
)
77

8+
func TestHttpRendererBackendMinimal(t *testing.T) {
9+
r := HttpRenderer{
10+
state: &HttpState{
11+
Address: "https://example.com/state",
12+
},
13+
BaseRenderer: BaseRenderer{
14+
identifier: "test-1/component-1",
15+
},
16+
}
17+
18+
b, err := r.Backend()
19+
assert.NoError(t, err)
20+
assert.Equal(t, `
21+
backend "http" {
22+
address = "https://example.com/state"
23+
}
24+
`, b)
25+
}
26+
827
func TestHttpRendererBackend(t *testing.T) {
928
r := HttpRenderer{
1029
state: &HttpState{
@@ -61,11 +80,7 @@ EOT
6180
func TestHttpRendererRemoteState(t *testing.T) {
6281
r := HttpRenderer{
6382
state: &HttpState{
64-
Address: "https://example.com/state",
65-
UpdateMethod: "POST",
66-
Username: "user",
67-
Password: "pass",
68-
SkipCertVerification: false,
83+
Address: "https://example.com/state",
6984
},
7085
BaseRenderer: BaseRenderer{
7186
identifier: "test-1/component-1",
@@ -81,10 +96,6 @@ func TestHttpRendererRemoteState(t *testing.T) {
8196
8297
config = {
8398
address = "https://example.com/state"
84-
update_method = "POST"
85-
username = "user"
86-
password = "pass"
87-
skip_cert_verification = false
8899
}
89100
}
90101
`, rs)

internal/state/schemas/http.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"address"
77
],
88
"properties": {
9+
"plugin": {
10+
"type": "string"
11+
},
912
"address": {
1013
"type": "string",
1114
"description": "The address of the REST endpoint."

0 commit comments

Comments
 (0)