Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws/awsutils: Update not to render sensitive fields for StringValue #2310

Merged
merged 3 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions aws/awsutil/string_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,27 @@ func stringValue(v reflect.Value, indent int, buf *bytes.Buffer) {
case reflect.Struct:
buf.WriteString("{\n")

names := []string{}
for i := 0; i < v.Type().NumField(); i++ {
name := v.Type().Field(i).Name
f := v.Field(i)
if name[0:1] == strings.ToLower(name[0:1]) {
ft := v.Type().Field(i)
fv := v.Field(i)

if ft.Name[0:1] == strings.ToLower(ft.Name[0:1]) {
continue // ignore unexported fields
}
if (f.Kind() == reflect.Ptr || f.Kind() == reflect.Slice) && f.IsNil() {
if (fv.Kind() == reflect.Ptr || fv.Kind() == reflect.Slice) && fv.IsNil() {
continue // ignore unset fields
}
names = append(names, name)
}

for i, n := range names {
val := v.FieldByName(n)
buf.WriteString(strings.Repeat(" ", indent+2))
buf.WriteString(n + ": ")
stringValue(val, indent+2, buf)
buf.WriteString(ft.Name + ": ")

if i < len(names)-1 {
buf.WriteString(",\n")
if tag := ft.Tag.Get("sensitive"); tag == "true" {
buf.WriteString("<sensitive>")
} else {
stringValue(fv, indent+2, buf)
}

buf.WriteString(",\n")
}

buf.WriteString("\n" + strings.Repeat(" ", indent) + "}")
Expand Down
51 changes: 51 additions & 0 deletions aws/awsutil/string_value_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// +build go1.7

package awsutil

import (
"testing"

"github.com/aws/aws-sdk-go/aws"
)

type testStruct struct {
Field1 string
Field2 *string
Field3 []byte `sensitive:"true"`
Value []*string
}

func TestStringValue(t *testing.T) {
cases := map[string]struct {
Value interface{}
Expect string
}{
"general": {
Value: testStruct{
Field1: "abc123",
Field2: aws.String("abc123"),
Field3: []byte("don't show me"),
Value: []*string{
aws.String("first"),
aws.String("second"),
},
},
Expect: `{
Field1: "abc123",
Field2: "abc123",
Field3: <sensitive>,
Value: ["first","second"],

}`,
},
}

for d, c := range cases {
t.Run(d, func(t *testing.T) {
actual := StringValue(c.Value)
if e, a := c.Expect, actual; e != a {
t.Errorf("expect:\n%v\nactual:\n%v\n", e, a)
}
})
}
}
7 changes: 7 additions & 0 deletions private/model/api/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ type Shape struct {
// Flags that the shape cannot be rename. Prevents the shape from being
// renamed further by the Input/Output.
AliasedShapeName bool

// Sensitive types should not be logged by SDK type loggers.
Sensitive bool `json:"sensitive"`
}

// CanBeEmpty returns if the shape value can sent request as an empty value.
Expand Down Expand Up @@ -514,6 +517,10 @@ func (ref *ShapeRef) GoTags(toplevel bool, isRequired bool) string {
tags = append(tags, ShapeTag{"ignore", "true"})
}

if ref.Shape.Sensitive {
tags = append(tags, ShapeTag{"sensitive", "true"})
}

return fmt.Sprintf("`%s`", tags)
}

Expand Down
6 changes: 3 additions & 3 deletions service/acm/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/alexaforbusiness/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions service/appstream/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/budgets/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions service/chime/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions service/codepipeline/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading