Skip to content

Commit a3ec0f4

Browse files
committed
fix: Add auth header on delete operations
1 parent 153d734 commit a3ec0f4

8 files changed

+43
-19
lines changed

applications.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ import (
2424
)
2525

2626
// DataSourcesType creates this block:
27-
// "dataSources": {
28-
// "disabled": [],
29-
// "enabled": ["canaryConfigs"]
30-
// }
27+
//
28+
// "dataSources": {
29+
// "disabled": [],
30+
// "enabled": ["canaryConfigs"]
31+
// }
3132
type DataSourcesType struct {
3233
Enabled []string `json:"enabled" mapstructure:"enabled" yaml:"enabled" hcl:"enabled"`
3334
Disabled []string `json:"disabled" mapstructure:"disabled" yaml:"disabled" hcl:"disabled"`
3435
}
3536

3637
// PermissionsType creates this block:
37-
// "permissions": {
38-
// "READ": ["armory-io", "core"],
39-
// "WRITE": ["armory-io", "core"]
40-
// }
38+
//
39+
// "permissions": {
40+
// "READ": ["armory-io", "core"],
41+
// "WRITE": ["armory-io", "core"]
42+
// }
4143
type PermissionsType struct {
4244
Read []string `json:"READ" mapstructure:"READ" yaml:"READ" hcl:"READ"`
4345
Write []string `json:"WRITE" mapstructure:"WRITE" yaml:"WRITE" hcl:"WRITE"`

applications_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,12 @@ func TestCreateAppWithGate(t *testing.T) {
122122
assert.Nil(t, err)
123123
}
124124

125-
126-
func TestApplicationMarshalJSON (t *testing.T){
125+
func TestApplicationMarshalJSON(t *testing.T) {
127126
app := Application{
128127
Name: "appname",
129128
Email: "useremail",
130129
Description: "appdescription",
131-
AppMetadata: map[string]interface{}{"testkey" : "testval", "testkey2" : "testval2"},
130+
AppMetadata: map[string]interface{}{"testkey": "testval", "testkey2": "testval2"},
132131
}
133132
jsonbytes, err := json.Marshal(app)
134133
if err != nil {
@@ -138,7 +137,7 @@ func TestApplicationMarshalJSON (t *testing.T){
138137
validate := make(map[string]interface{})
139138
json.Unmarshal(jsonbytes, &validate)
140139

141-
if _, ok := validate["testkey"]; !ok{
140+
if _, ok := validate["testkey"]; !ok {
142141
t.Fail()
143142
}
144-
}
143+
}

client.go

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ func (c *Client) Delete(url, traceparent string) error {
280280
if err != nil {
281281
return err
282282
}
283+
if "" != c.FiatUser {
284+
request.Header.Set(SpinFiatUserHeader, c.FiatUser)
285+
}
283286
if traceparent != "" {
284287
request.Header.Set("traceparent", traceparent)
285288
}

client_test.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ func TestGet(t *testing.T) {
5858
assert.Equal(t, "value1", val["key1"])
5959
}
6060

61+
func TestDelete(t *testing.T) {
62+
mockBody := ``
63+
client := NewTestClient(func(req *http.Request) *http.Response {
64+
authHeader := req.Header.Get("X-Spinnaker-User")
65+
assert.Equal(t, "FiatUser", authHeader)
66+
return &http.Response{
67+
StatusCode: 200,
68+
Body: ioutil.NopCloser(bytes.NewBufferString(mockBody)),
69+
Header: make(http.Header),
70+
}
71+
})
72+
var c = New(WithClient(client), WithFiatUser("FiatUser"))
73+
assert.NotNil(t, c)
74+
err := c.Delete("/", "")
75+
assert.Nil(t, err)
76+
}
77+
6178
func TestDefaultClient(t *testing.T) {
6279
client := New()
6380
assert.NotNil(t, client)
@@ -71,7 +88,7 @@ func TestURLMapCopy(t *testing.T) {
7188
}
7289

7390
func TestOptions(t *testing.T) {
74-
test_transport := New(WithTransport(&http.Transport{MaxIdleConns:5}))
91+
test_transport := New(WithTransport(&http.Transport{MaxIdleConns: 5}))
7592
assert.Equal(t, &http.Transport{MaxIdleConns: 5}, test_transport.http.Transport)
7693

7794
test_client := New(WithClient(&http.Client{}))

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/armory/plank/v4
33
require (
44
github.com/armory/go-yaml-tools v1.0.2
55
github.com/mitchellh/mapstructure v1.5.0
6-
github.com/stretchr/testify v1.8.4
6+
github.com/stretchr/testify v1.9.0
77
)
88

99
require (

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
245245
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
246246
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
247247
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
248+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
248249
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
249250
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
250251
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
@@ -255,6 +256,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
255256
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
256257
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
257258
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
259+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
260+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
258261
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
259262
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
260263
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

notifications_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ func TestNotificationsType_ValidateAppNotification_nil(t *testing.T) {
127127
if err != nil {
128128
t.Fail()
129129
}
130-
}
130+
}

tasks.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ExecutionStatusResponse struct {
3838

3939
func (c *Client) GetTask(refURL, traceparent string) (*ExecutionStatusResponse, error) {
4040
var body ExecutionStatusResponse
41-
err := c.Get(c.URLs["orca"]+refURL,traceparent, &body)
41+
err := c.Get(c.URLs["orca"]+refURL, traceparent, &body)
4242
return &body, err
4343
}
4444

@@ -74,11 +74,11 @@ func (c *Client) CreateTask(app, desc, traceparent string, payload interface{})
7474
task := Task{Application: app, Description: desc, Job: []interface{}{payload}}
7575
var ref TaskRefResponse
7676
if c.UseGate {
77-
if err := c.Post(c.URLs["gate"]+"/plank/ops",traceparent, ApplicationContextJson, task, &ref); err != nil {
77+
if err := c.Post(c.URLs["gate"]+"/plank/ops", traceparent, ApplicationContextJson, task, &ref); err != nil {
7878
return nil, err
7979
}
8080
} else {
81-
if err := c.Post(c.URLs["orca"]+"/ops",traceparent, ApplicationContextJson, task, &ref); err != nil {
81+
if err := c.Post(c.URLs["orca"]+"/ops", traceparent, ApplicationContextJson, task, &ref); err != nil {
8282
return nil, err
8383
}
8484
}

0 commit comments

Comments
 (0)