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

Support for Custom-Header #102

Merged
merged 4 commits into from
Dec 14, 2022
Merged

Conversation

harshit777
Copy link
Contributor

@harshit777 harshit777 commented Nov 30, 2022

Support for Adding Custom Header.

  1. From ServiceClient
cc := kp.ClientConfig{
		BaseURL:    "",
		APIKey:     "",
		InstanceID: "",
		Headers: http.Header{
			"Custom-Header":  {"Custom-Value"},
		},
	}
  1. From ServiceCall (Per API)

Define Header just before the API Call and clear it after call

client.Config.Headers = make(http.Header)
	client.Config.Headers.Set("Custom-Header", "Custom-Header-Value")

	key, err := client.CreateKey(context.Background(), "NewKey", nil, true)
	if err != nil {
		panic(err)
	}
	client.Config.Headers = http.Header{}

@harshit777
Copy link
Contributor Author

harshit777 commented Nov 30, 2022

Test Results

1) API Calls
Screenshot 2022-11-30 at 4 33 21 PM
2) Client Call
Screenshot 2022-11-30 at 5 11 36 PM

Copy link
Member

@dinesh-venkatraman-g dinesh-venkatraman-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @harshit777 .. few minor comments

  1. Update the example section of Readme on how to set custom headers
  2. Run all the integration test cases and attach the evidence
  3. Also, test if setting the empty interface for headers (instead of nil) clears off the header

@harshit777
Copy link
Contributor Author

harshit777 commented Dec 6, 2022

Integration Test :

go test -v -tags=integration ./...

--- PASS: TestWrapUnwrap (9.95s)
    integration_test.go:210: CRK created successfully: id=4b15b0bb-8241-460a-836c-c914b6b68128
--- PASS: TestExtractableKey (10.02s)
=== RUN   TestRotationInstancePolicy
--- PASS: TestRotationInstancePolicy (13.10s)
=== RUN   TestKeyRotationPolicy
--- PASS: TestKeyRotationPolicy (9.77s)
=== RUN   TestCreateKeyWithPolicyOverrides
--- PASS: TestCreateKeyWithPolicyOverrides (12.24s)
=== RUN   TestListKeysWithFilter
--- PASS: TestListKeysWithFilter (8.04s)
=== RUN   TestKeys
=== RUN   TestKeys/New_API
=== RUN   TestKeys/New_API_with_Logger
=== RUN   TestKeys/Timeout
=== RUN   TestKeys/Get_Keys
=== RUN   TestKeys/Wrap_Create_DEK
=== RUN   TestKeys/Wrap_Unwrap_v2
=== RUN   TestKeys/Unwrap_on_Deleted_should_return_err_with_410_Gone
=== RUN   TestKeys/Imported_Create_Delete
=== RUN   TestKeys/Create_Delete
=== RUN   TestKeys/Imported_Rotate
=== RUN   TestKeys/Imported_Rotate_Unwrap
=== RUN   TestKeys/Rotate_Unwrap
=== RUN   TestKeys/Timeout#01
=== RUN   TestKeys/Auth_Context
=== RUN   TestKeys/Auth_in_Config
=== RUN   TestKeys/Wrap_and_Unwrap_AAD
=== RUN   TestKeys/API_Key_Timeout
=== RUN   TestKeys/Bad_Config
=== RUN   TestKeys/Bad_API_Key
=== RUN   TestKeys/Create_Key_Without_Expiration
=== RUN   TestKeys/Create
=== RUN   TestKeys/Rotate
=== RUN   TestKeys/Get_Key
=== RUN   TestKeys/Get_Key_Metadata
=== RUN   TestKeys/List_Key_Versions
=== RUN   TestKeys/Wrap_Unwrap
=== RUN   TestKeys/Delete_Key
=== RUN   TestKeys/Create_Standard_Key
=== RUN   TestKeys/Create_Imported_Standard_Key
--- PASS: TestKeys (0.02s)
    --- PASS: TestKeys/New_API (0.00s)
    --- PASS: TestKeys/New_API_with_Logger (0.00s)
    --- PASS: TestKeys/Timeout (0.00s)
    --- PASS: TestKeys/Get_Keys (0.00s)
    --- PASS: TestKeys/Wrap_Create_DEK (0.00s)
    --- PASS: TestKeys/Wrap_Unwrap_v2 (0.00s)
    --- PASS: TestKeys/Unwrap_on_Deleted_should_return_err_with_410_Gone (0.00s)
    --- PASS: TestKeys/Imported_Create_Delete (0.00s)
    --- PASS: TestKeys/Create_Delete (0.00s)
    --- PASS: TestKeys/Imported_Rotate (0.00s)
    --- PASS: TestKeys/Imported_Rotate_Unwrap (0.00s)
    --- PASS: TestKeys/Rotate_Unwrap (0.00s)
    --- PASS: TestKeys/Timeout#01 (0.00s)
    --- PASS: TestKeys/Auth_Context (0.00s)
    --- PASS: TestKeys/Auth_in_Config (0.00s)
    --- PASS: TestKeys/Wrap_and_Unwrap_AAD (0.00s)
    --- PASS: TestKeys/API_Key_Timeout (0.00s)
    --- PASS: TestKeys/Bad_Config (0.00s)
    --- PASS: TestKeys/Bad_API_Key (0.00s)
    --- PASS: TestKeys/Create_Key_Without_Expiration (0.00s)
    --- PASS: TestKeys/Create (0.00s)
    --- PASS: TestKeys/Rotate (0.00s)
    --- PASS: TestKeys/Get_Key (0.00s)
    --- PASS: TestKeys/Get_Key_Metadata (0.00s)
    --- PASS: TestKeys/List_Key_Versions (0.00s)
    --- PASS: TestKeys/Wrap_Unwrap (0.00s)
    --- PASS: TestKeys/Delete_Key (0.00s)
    --- PASS: TestKeys/Create_Standard_Key (0.00s)
    --- PASS: TestKeys/Create_Imported_Standard_Key (0.00s)
=== RUN   TestKeyWithPolicyOverrides
=== RUN   TestKeyWithPolicyOverrides/Create_Key_With_Policy_Overrides
=== RUN   TestKeyWithPolicyOverrides/Create_Key_With_Policy_Overrides_Error_Case
--- PASS: TestKeyWithPolicyOverrides (0.00s)
    --- PASS: TestKeyWithPolicyOverrides/Create_Key_With_Policy_Overrides (0.00s)
    --- PASS: TestKeyWithPolicyOverrides/Create_Key_With_Policy_Overrides_Error_Case (0.00s)
=== RUN   TestMisc
=== RUN   TestMisc/Redact_Values
--- PASS: TestMisc (0.00s)
    --- PASS: TestMisc/Redact_Values (0.00s)
=== RUN   TestImportTokens
=== RUN   TestImportTokens/ImportToken_Create
=== RUN   TestImportTokens/ImportToken_Get
=== RUN   TestImportTokens/Assert_context_authorization_override
=== RUN   TestImportTokens/Dump_Implementations
--- PASS: TestImportTokens (0.00s)
    --- PASS: TestImportTokens/ImportToken_Create (0.00s)
    --- PASS: TestImportTokens/ImportToken_Get (0.00s)
    --- PASS: TestImportTokens/Assert_context_authorization_override (0.00s)
    --- PASS: TestImportTokens/Dump_Implementations (0.00s)
=== RUN   TestKPCheckRetry
=== RUN   TestKPCheckRetry/No_retry_on_successful_codes
=== RUN   TestKPCheckRetry/No_retry_on_400-level_codes
=== RUN   TestKPCheckRetry/Retry_on_429
=== RUN   TestKPCheckRetry/Retry_on_500+
=== RUN   TestKPCheckRetry/No_retry_on_501
=== RUN   TestKPCheckRetry/Retry_on_connection_failures
=== RUN   TestKPCheckRetry/No_retry_on_context_failures
--- PASS: TestKPCheckRetry (0.00s)
    --- PASS: TestKPCheckRetry/No_retry_on_successful_codes (0.00s)
    --- PASS: TestKPCheckRetry/No_retry_on_400-level_codes (0.00s)
    --- PASS: TestKPCheckRetry/Retry_on_429 (0.00s)
    --- PASS: TestKPCheckRetry/Retry_on_500+ (0.00s)
    --- PASS: TestKPCheckRetry/No_retry_on_501 (0.00s)
    --- PASS: TestKPCheckRetry/Retry_on_connection_failures (0.00s)
    --- PASS: TestKPCheckRetry/No_retry_on_context_failures (0.00s)
=== RUN   TestDo_ConnectionError_HasCorrelationID
--- PASS: TestDo_ConnectionError_HasCorrelationID (0.00s)
=== RUN   TestDo_CorrelationID_Set
--- PASS: TestDo_CorrelationID_Set (0.00s)
=== RUN   TestDo_KPErrorResponseWithReasons_IsErrorStruct
--- PASS: TestDo_KPErrorResponseWithReasons_IsErrorStruct (0.00s)
=== RUN   TestDo_KPErrorResponseWithoutReasons_IsErrorStruct
--- PASS: TestDo_KPErrorResponseWithoutReasons_IsErrorStruct (0.00s)
=== RUN   TestDeleteKey_ForceOptTrue_URLHasForce
--- PASS: TestDeleteKey_ForceOptTrue_URLHasForce (0.00s)
=== RUN   TestDeleteKey_WithRegistrations_ErrorCases
--- PASS: TestDeleteKey_WithRegistrations_ErrorCases (0.00s)
=== RUN   TestRegistrationsList
--- PASS: TestRegistrationsList (0.00s)
=== RUN   TestRestoreKey
--- PASS: TestRestoreKey (0.00s)
=== RUN   TestSetAndGetMultipleInstancePolicies
--- PASS: TestSetAndGetMultipleInstancePolicies (0.00s)
=== RUN   TestSetAndGetDualAuthInstancePolicy
--- PASS: TestSetAndGetDualAuthInstancePolicy (0.00s)
=== RUN   TestSetAndGetRotationInstancePolicy
--- PASS: TestSetAndGetRotationInstancePolicy (0.00s)
=== RUN   TestSetAndGetAllowedNetworkPolicy
--- PASS: TestSetAndGetAllowedNetworkPolicy (0.00s)
=== RUN   TestSetAndGetAllowedIPInstancePolicy
--- PASS: TestSetAndGetAllowedIPInstancePolicy (0.00s)
=== RUN   TestSetAndGetKeyCreateImportAccessInstancePolicy
--- PASS: TestSetAndGetKeyCreateImportAccessInstancePolicy (0.00s)
=== RUN   TestSetMetricsPolicy
--- PASS: TestSetMetricsPolicy (0.00s)
=== RUN   TestSetAllowedIPPolicyError
--- PASS: TestSetAllowedIPPolicyError (0.00s)
=== RUN   TestGetPrivateEndpointPortNumber
--- PASS: TestGetPrivateEndpointPortNumber (0.00s)
=== RUN   TestSetInstanceDualAuthPolicyError
--- PASS: TestSetInstanceDualAuthPolicyError (0.00s)
=== RUN   TestSetRotationInstancePolicyError
--- PASS: TestSetRotationInstancePolicyError (0.00s)
=== RUN   TestSetKeyPolicies
--- PASS: TestSetKeyPolicies (0.00s)
=== RUN   TestEnabeOrDisableRotationPolicy
--- PASS: TestEnabeOrDisableRotationPolicy (0.00s)
=== RUN   TestGetKeyPolicies
--- PASS: TestGetKeyPolicies (0.00s)
=== RUN   TestDisableKey
--- PASS: TestDisableKey (0.00s)
=== RUN   TestEnableKey
--- PASS: TestEnableKey (0.00s)
=== RUN   TestInitiate_DualAuthDelete
--- PASS: TestInitiate_DualAuthDelete (0.00s)
=== RUN   TestCancel_DualAuthDelete
--- PASS: TestCancel_DualAuthDelete (0.00s)
=== RUN   TestCreateKeyRing
--- PASS: TestCreateKeyRing (0.00s)
=== RUN   TestDeleteKeyRing
--- PASS: TestDeleteKeyRing (0.00s)
=== RUN   TestGetKeyRings
--- PASS: TestGetKeyRings (0.00s)
=== RUN   TestSetKeyRing
--- PASS: TestSetKeyRing (0.00s)
=== RUN   TestGetKeyVerifyKeyRingDetail
--- PASS: TestGetKeyVerifyKeyRingDetail (0.00s)
=== RUN   TestCreateKeyWithAliases
--- PASS: TestCreateKeyWithAliases (0.00s)
=== RUN   TestCreateImportedKeyWithAliases
--- PASS: TestCreateImportedKeyWithAliases (0.00s)
=== RUN   TestCreateKeyAlias
--- PASS: TestCreateKeyAlias (0.00s)
=== RUN   TestDeleteKeyAlias
--- PASS: TestDeleteKeyAlias (0.00s)
=== RUN   TestPurgeKey
--- PASS: TestPurgeKey (0.00s)
=== RUN   TestGetPurgeKey
--- PASS: TestGetPurgeKey (0.00s)
=== RUN   TestWrapWithAlias
    kp_test.go:3984: wrap value 
--- PASS: TestWrapWithAlias (0.00s)
=== RUN   TestUnWrapWithAlias
--- PASS: TestUnWrapWithAlias (0.00s)
=== RUN   TestGetKeyWithAlias
--- PASS: TestGetKeyWithAlias (0.00s)
=== RUN   TestGetKeyMetadataWithAlias
--- PASS: TestGetKeyMetadataWithAlias (0.00s)
=== RUN   TestListKeyVersions
--- PASS: TestListKeyVersions (0.00s)
=== RUN   TestListKeys
--- PASS: TestListKeys (0.00s)
=== RUN   TestRotate2WithoutPayload
--- PASS: TestRotate2WithoutPayload (0.00s)
=== RUN   TestRotate2WithPayload
--- PASS: TestRotate2WithPayload (0.00s)
=== RUN   TestRotate2SecurelyImport
--- PASS: TestRotate2SecurelyImport (0.00s)
=== RUN   TestRotate2GeneratedKeyWithPayload
--- PASS: TestRotate2GeneratedKeyWithPayload (0.00s)
=== RUN   TestRotate2ImportedKeyWithoutPayload
--- PASS: TestRotate2ImportedKeyWithoutPayload (0.00s)
=== RUN   TestSyncAssociatedResources
--- PASS: TestSyncAssociatedResources (0.00s)
=== RUN   TestSyncAssociatedResourcesError
--- PASS: TestSyncAssociatedResourcesError (0.00s)
=== RUN   TestListKeySort
--- PASS: TestListKeySort (0.00s)
=== RUN   TestListKeySearch
--- PASS: TestListKeySearch (0.00s)
=== RUN   TestListKeyFilter
--- PASS: TestListKeyFilter (0.00s)
PASS
ok  	github.com/IBM/keyprotect-go-client	(cached)
?   	github.com/IBM/keyprotect-go-client/cmd/kp-token	[no test files]
=== RUN   TestToken_EmptyAPIKey_ReturnsError
--- PASS: TestToken_EmptyAPIKey_ReturnsError (0.00s)
=== RUN   TestToken_ValidToken_ReturnsCachedCopy
--- PASS: TestToken_ValidToken_ReturnsCachedCopy (0.00s)
=== RUN   TestToken_InvalidToken_ReturnsNewToken
--- PASS: TestToken_InvalidToken_ReturnsNewToken (0.00s)
=== RUN   TestValid_NotExpired_ReturnsTrue
--- PASS: TestValid_NotExpired_ReturnsTrue (0.00s)
=== RUN   TestValid_Expired_ReturnsFalse
--- PASS: TestValid_Expired_ReturnsFalse (0.00s)
=== RUN   TestValid_EmptyAccessToken_ReturnsFalse
--- PASS: TestValid_EmptyAccessToken_ReturnsFalse (0.00s)
=== RUN   TestValid_NilToken_ReturnsFalse
--- PASS: TestValid_NilToken_ReturnsFalse (0.00s)
=== RUN   TestError_NilContextOrResp_NoNilDeref
--- PASS: TestError_NilContextOrResp_NoNilDeref (0.00s)
PASS
ok  	github.com/IBM/keyprotect-go-client/iam	(cached)


@harshit777 harshit777 force-pushed the SupportHeader branch 8 times, most recently from 12451a2 to 0d44812 Compare December 12, 2022 07:11
Copy link
Contributor

@ankitchahal20 ankitchahal20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could pls also add testcases for this.

kp.go Outdated Show resolved Hide resolved
kp.go Outdated Show resolved Hide resolved
kp.go Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@harshit777 harshit777 force-pushed the SupportHeader branch 5 times, most recently from 5c0ff8b to 5e33e38 Compare December 13, 2022 08:48
@harshit777
Copy link
Contributor Author

Signed-off-by: Harshit Gupta <harshitgupta@Harshits-MacBook-Pro.local>
Signed-off-by: Harshit Gupta <harshitgupta@harshits-mbp.in.ibm.com>
@harshit777 harshit777 force-pushed the SupportHeader branch 4 times, most recently from 3f9df68 to 7a86f61 Compare December 13, 2022 09:52
Signed-off-by: Harshit Gupta <harshitgupta@harshits-mbp.in.ibm.com>
@dinesh-venkatraman-g dinesh-venkatraman-g merged commit d6df84a into IBM:master Dec 14, 2022
dinesh-venkatraman-g pushed a commit that referenced this pull request Dec 14, 2022
## [0.9.2](v0.9.1...v0.9.2) (2022-12-14)

### Bug Fixes

* **build:**  Support for Custom-Header ([#102](#102)) & wrap() with key version ([d6df84a](d6df84a))
@dinesh-venkatraman-g
Copy link
Member

🎉 This PR is included in version 0.9.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants