IBM / keyprotect-go-client

Go SDK for interacting with the IBM Cloud KeyProtect service.
Apache License 2.0
6 stars 29 forks source link

Support for Custom-Header #102

Closed harshit777 closed 1 year ago

harshit777 commented 1 year ago

Support for Adding Custom Header.

1) From ServiceClient

cc := kp.ClientConfig{
        BaseURL:    "",
        APIKey:     "",
        InstanceID: "",
        Headers: http.Header{
            "Custom-Header":  {"Custom-Value"},
        },
    }

2) 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 commented 1 year ago

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
harshit777 commented 1 year ago

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 commented 1 year ago

Issue : https://github.ibm.com/kms/kmk/issues/1485

dinesh-venkatraman-g commented 1 year ago

:tada: This PR is included in version 0.9.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: