Skip to content

Commit

Permalink
fix(delete): Add auth header on delete operations (#92)
Browse files Browse the repository at this point in the history
* fix: Add auth header on delete operations

* Add parallel code coverage GHA config
  • Loading branch information
jasonmcintosh authored Jun 26, 2024
1 parent 153d734 commit c46934e
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 20 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ jobs:
key: go-${{ hashFiles('**/go.sum') }}
- name: Checkout Code
uses: actions/checkout@v2

- name: Test Plank
run: go test -v -race -covermode atomic -coverprofile=profile.cov ./...
run: go test -v -race -covermode atomic -coverprofile=profile.cov ./...

- name: Send Coverage
uses: shogo82148/actions-goveralls@v1
with:
parallel: true
flag-name: Go-${{ matrix.go-version }}
path-to-profile: profile.cov

finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true
18 changes: 10 additions & 8 deletions applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ import (
)

// DataSourcesType creates this block:
// "dataSources": {
// "disabled": [],
// "enabled": ["canaryConfigs"]
// }
//
// "dataSources": {
// "disabled": [],
// "enabled": ["canaryConfigs"]
// }
type DataSourcesType struct {
Enabled []string `json:"enabled" mapstructure:"enabled" yaml:"enabled" hcl:"enabled"`
Disabled []string `json:"disabled" mapstructure:"disabled" yaml:"disabled" hcl:"disabled"`
}

// PermissionsType creates this block:
// "permissions": {
// "READ": ["armory-io", "core"],
// "WRITE": ["armory-io", "core"]
// }
//
// "permissions": {
// "READ": ["armory-io", "core"],
// "WRITE": ["armory-io", "core"]
// }
type PermissionsType struct {
Read []string `json:"READ" mapstructure:"READ" yaml:"READ" hcl:"READ"`
Write []string `json:"WRITE" mapstructure:"WRITE" yaml:"WRITE" hcl:"WRITE"`
Expand Down
9 changes: 4 additions & 5 deletions applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ func TestCreateAppWithGate(t *testing.T) {
assert.Nil(t, err)
}


func TestApplicationMarshalJSON (t *testing.T){
func TestApplicationMarshalJSON(t *testing.T) {
app := Application{
Name: "appname",
Email: "useremail",
Description: "appdescription",
AppMetadata: map[string]interface{}{"testkey" : "testval", "testkey2" : "testval2"},
AppMetadata: map[string]interface{}{"testkey": "testval", "testkey2": "testval2"},
}
jsonbytes, err := json.Marshal(app)
if err != nil {
Expand All @@ -138,7 +137,7 @@ func TestApplicationMarshalJSON (t *testing.T){
validate := make(map[string]interface{})
json.Unmarshal(jsonbytes, &validate)

if _, ok := validate["testkey"]; !ok{
if _, ok := validate["testkey"]; !ok {
t.Fail()
}
}
}
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func (c *Client) Delete(url, traceparent string) error {
if err != nil {
return err
}
if "" != c.FiatUser {
request.Header.Set(SpinFiatUserHeader, c.FiatUser)
}
if traceparent != "" {
request.Header.Set("traceparent", traceparent)
}
Expand Down
19 changes: 18 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ func TestGet(t *testing.T) {
assert.Equal(t, "value1", val["key1"])
}

func TestDelete(t *testing.T) {
mockBody := ``
client := NewTestClient(func(req *http.Request) *http.Response {
authHeader := req.Header.Get("X-Spinnaker-User")
assert.Equal(t, "FiatUser", authHeader)
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(mockBody)),
Header: make(http.Header),
}
})
var c = New(WithClient(client), WithFiatUser("FiatUser"))
assert.NotNil(t, c)
err := c.Delete("/", "")
assert.Nil(t, err)
}

func TestDefaultClient(t *testing.T) {
client := New()
assert.NotNil(t, client)
Expand All @@ -71,7 +88,7 @@ func TestURLMapCopy(t *testing.T) {
}

func TestOptions(t *testing.T) {
test_transport := New(WithTransport(&http.Transport{MaxIdleConns:5}))
test_transport := New(WithTransport(&http.Transport{MaxIdleConns: 5}))
assert.Equal(t, &http.Transport{MaxIdleConns: 5}, test_transport.http.Transport)

test_client := New(WithClient(&http.Client{}))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/armory/plank/v4
require (
github.com/armory/go-yaml-tools v1.0.2
github.com/mitchellh/mapstructure v1.5.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
Expand All @@ -255,6 +256,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
2 changes: 1 addition & 1 deletion notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ func TestNotificationsType_ValidateAppNotification_nil(t *testing.T) {
if err != nil {
t.Fail()
}
}
}
6 changes: 3 additions & 3 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ExecutionStatusResponse struct {

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

Expand Down Expand Up @@ -74,11 +74,11 @@ func (c *Client) CreateTask(app, desc, traceparent string, payload interface{})
task := Task{Application: app, Description: desc, Job: []interface{}{payload}}
var ref TaskRefResponse
if c.UseGate {
if err := c.Post(c.URLs["gate"]+"/plank/ops",traceparent, ApplicationContextJson, task, &ref); err != nil {
if err := c.Post(c.URLs["gate"]+"/plank/ops", traceparent, ApplicationContextJson, task, &ref); err != nil {
return nil, err
}
} else {
if err := c.Post(c.URLs["orca"]+"/ops",traceparent, ApplicationContextJson, task, &ref); err != nil {
if err := c.Post(c.URLs["orca"]+"/ops", traceparent, ApplicationContextJson, task, &ref); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit c46934e

Please sign in to comment.