From 9e70d5267f7cee48865d3be3dc652423085a1f15 Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Thu, 19 Jan 2017 15:52:56 +0000 Subject: [PATCH] Switch Org > Project --- README.md | 2 +- keys/keys.go | 18 +++++++++--------- portcullis.go | 36 ++++++++++++++++++------------------ portcullis_test.go | 20 ++++++++++---------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index e815479..07983c3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ FromContext() accepts the context from your GRPC request ```go import "github.com/cubex/portcullis-go" -org := portcullis.FromContext(ctx).OrganisationID +project := portcullis.FromContext(ctx).ProjectID ``` Dependencies included in [Glide](https://glide.sh/).lock \ No newline at end of file diff --git a/keys/keys.go b/keys/keys.go index 856e496..2b6316a 100644 --- a/keys/keys.go +++ b/keys/keys.go @@ -5,12 +5,12 @@ import "strings" const ( keyprefix = "portc-" - organisationKey = "organisation" - usernameKey = "username" - userIDKey = "userid" - appIDkey = "appid" - vendorKey = "appvendor" - sigKey = "signature" + projectKey = "project" + usernameKey = "username" + userIDKey = "userid" + appIDkey = "appid" + vendorKey = "appvendor" + sigKey = "signature" firstNameKey = "first-name" lastNameKey = "last-name" @@ -36,9 +36,9 @@ func GetAppVendorKey() string { return keyprefix + vendorKey } -// GetOrganisationKey retrieves the key used for organisation -func GetOrganisationKey() string { - return keyprefix + organisationKey +// GetProjectKey retrieves the key used for project +func GetProjectKey() string { + return keyprefix + projectKey } // GetUsernameKey retrieves the key used for username diff --git a/portcullis.go b/portcullis.go index 77dbf80..174548a 100644 --- a/portcullis.go +++ b/portcullis.go @@ -16,15 +16,15 @@ import ( // ReqInfo is the structure for deserialised request information type ReqInfo struct { - OrganisationID string - UserID string - AppID string - VendorID string - Username string - FirstName string - LastName string - signature string - meta metadata.MD + ProjectID string + UserID string + AppID string + VendorID string + Username string + FirstName string + LastName string + signature string + meta metadata.MD } // Verify checks that the request signature matches using signature key @@ -64,15 +64,15 @@ func (r *ReqInfo) GlobalAppID() string { func FromContext(ctx context.Context) ReqInfo { md, _ := metadata.FromContext(ctx) res := ReqInfo{ - OrganisationID: safeGetMetaValString(keys.GetOrganisationKey(), md), - UserID: safeGetMetaValString(keys.GetUserIDKey(), md), - Username: safeGetMetaValString(keys.GetUsernameKey(), md), - FirstName: safeGetMetaValString(keys.GetFirstNameKey(), md), - LastName: safeGetMetaValString(keys.GetLastNameKey(), md), - AppID: safeGetMetaValString(keys.GetAppIDKey(), md), - VendorID: safeGetMetaValString(keys.GetAppVendorKey(), md), - signature: safeGetMetaValString(keys.GetSignatureKey(), md), - meta: md, + ProjectID: safeGetMetaValString(keys.GetProjectKey(), md), + UserID: safeGetMetaValString(keys.GetUserIDKey(), md), + Username: safeGetMetaValString(keys.GetUsernameKey(), md), + FirstName: safeGetMetaValString(keys.GetFirstNameKey(), md), + LastName: safeGetMetaValString(keys.GetLastNameKey(), md), + AppID: safeGetMetaValString(keys.GetAppIDKey(), md), + VendorID: safeGetMetaValString(keys.GetAppVendorKey(), md), + signature: safeGetMetaValString(keys.GetSignatureKey(), md), + meta: md, } return res } diff --git a/portcullis_test.go b/portcullis_test.go index 7cefdf3..52aae8e 100644 --- a/portcullis_test.go +++ b/portcullis_test.go @@ -12,7 +12,7 @@ import ( ) const ( - testOrg = "this-is-a-test-org-id" + testProject = "this-is-a-test-project-id" testUserID = "this-is-a-test-user-id" testUsername = "this-is-a-test-username" @@ -23,7 +23,7 @@ const ( // TestAuthDataExtraction tests for valid transaction of portcullis meta data values func TestAuthDataExtraction(t *testing.T) { metamap := map[string]string{} - metamap[keys.GetOrganisationKey()] = testOrg + metamap[keys.GetProjectKey()] = testProject metamap[keys.GetUserIDKey()] = testUserID metamap[keys.GetUsernameKey()] = testUsername metamap[keys.GetAppIDKey()] = testAppID @@ -37,8 +37,8 @@ func TestAuthDataExtraction(t *testing.T) { t.Error("Global app ID does not contain expected value") } - if in.OrganisationID != testOrg { - t.Error("Organisation does not contain expected value") + if in.ProjectID != testProject { + t.Error("Project does not contain expected value") } if in.Username != testUsername { @@ -57,7 +57,7 @@ func TestAuthDataExtractionWithMissingFields(t *testing.T) { meta := metadata.New(metamap) ctx := metadata.NewContext(context.Background(), meta) - org := portcullis.FromContext(ctx).OrganisationID + project := portcullis.FromContext(ctx).ProjectID username := portcullis.FromContext(ctx).Username userID := portcullis.FromContext(ctx).UserID @@ -65,8 +65,8 @@ func TestAuthDataExtractionWithMissingFields(t *testing.T) { t.Error("Username does not contain expected value") } - if org != "" { - t.Error("Organisation does not contain expected value") + if project != "" { + t.Error("Project does not contain expected value") } if userID != "" { @@ -77,9 +77,9 @@ func TestAuthDataExtractionWithMissingFields(t *testing.T) { // TestExtractionWithInvalidContext tests extraction result with context contains no metadata func TestExtractionWithInvalidContext(t *testing.T) { ctx := context.TODO() - org := portcullis.FromContext(ctx).OrganisationID + project := portcullis.FromContext(ctx).ProjectID - if org != "" { - t.Error("Organisation does not contain expected value") + if project != "" { + t.Error("Project does not contain expected value") } }