Skip to content

Commit

Permalink
Add auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Viken Duedal authored and cypres committed Jun 27, 2019
1 parent b208e73 commit f7d41a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions ctxvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ type ctxMarker struct{}

// VmlHeaders contains vml http headers.
type VmlHeaders struct {
Username string
OcrCache string
Username string
OcrCache string
AuthMethod string
}

func (h VmlHeaders) OcrCacheAllow() bool {
Expand Down Expand Up @@ -65,6 +66,9 @@ func extractMetadataToContext(ctx context.Context) context.Context {
if mdValue, ok := md["vml-ocr-cache"]; ok && len(mdValue) != 0 {
headers.OcrCache = mdValue[0]
}
if mdValue, ok := md["vml-auth-method"]; ok && len(mdValue) != 0 {
headers.AuthMethod = mdValue[0]
}
if headers.Username != "" {
grpc_ctxtags.Extract(ctx).Set("username", headers.Username)
}
Expand Down Expand Up @@ -104,6 +108,7 @@ func packCallerMetadata(ctx context.Context) map[string]string {
headers := Extract(ctx)
md["vml-username"] = headers.Username
md["vml-ocr-cache"] = headers.OcrCache
md["vml-auth-method"] = headers.AuthMethod
return md
}

Expand Down
4 changes: 2 additions & 2 deletions ctxvml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestPackMetadata(t *testing.T) {
Username: "JohnDoe",
})
md := packCallerMetadata(ctx)
if md["x-ssn-username"] != "JohnDoe" {
t.Fatalf("Unexpected username %s", md["x-ssn-username"])
if md["vml-username"] != "JohnDoe" {
t.Fatalf("Unexpected username %s", md["vml-username"])
}
for k, v := range md {
ctx = metadata.AppendToOutgoingContext(ctx, k, v)
Expand Down

0 comments on commit f7d41a1

Please sign in to comment.