Skip to content

Commit

Permalink
fix storage PUT request
Browse files Browse the repository at this point in the history
  • Loading branch information
emilymye committed Apr 13, 2018
1 parent ada0fa6 commit cbb5b3b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions plugin/iamutil/iam_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

"github.com/hashicorp/go-gcp-common/gcputil"
"google.golang.org/api/googleapi"
"bytes"
"encoding/json"
)

const (
Expand Down Expand Up @@ -217,16 +219,20 @@ type ServiceConfig struct {
}

func (r *iamResourceImpl) SetIamPolicyRequest(p *Policy) (*http.Request, error) {
data := struct {
Policy *Policy `json:"policy,omitempty"`
}{Policy: p}

buf, err := googleapi.WithoutDataWrapper.JSONReader(data)
var buf []byte
var err error

switch strings.ToLower(r.config.Service.Name) {
case "storage":
buf, err = json.Marshal(p)
default:
buf, err = json.Marshal(struct{Policy *Policy `json:"policy,omitempty"`}{Policy: p})
}
if err != nil {
return nil, err
}

return r.constructRequest(r.config.SetIamPolicy, buf)
return r.constructRequest(r.config.SetIamPolicy, bytes.NewReader(buf))
}

func (r *iamResourceImpl) GetIamPolicyRequest() (*http.Request, error) {
Expand All @@ -240,6 +246,12 @@ func (r *iamResourceImpl) constructRequest(httpMtd *HttpMethodCfg, data io.Reade
return nil, err
}

if req.Header == nil {
req.Header = make(http.Header)
}
if data != nil {
req.Header.Set("Content-Type", "application/json")
}
replacementMap := make(map[string]string)
for cId, replaceK := range httpMtd.ReplacementKeys {
rId, ok := r.relativeId.IdTuples[cId]
Expand Down

0 comments on commit cbb5b3b

Please sign in to comment.