Repository: milvus-io/milvus-sdk-go
Pull request #486 (2023-06-08 04:36:32)

Fix api token format
/kind bug

sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/486#" title="Author self-approved">congqixia</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/v2.2.x/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/486?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
> Merging [#486](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/486?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (37e7fe0) into [v2.2.x](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/b62bc3883e23d46ba68d806d98c186b5f86d3846?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (b62bc38) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/486/graphs/tree.svg?width=650&height=150&src=pr&token=WJK43PV390&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/486?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)

```diff
@@           Coverage Diff           @@
##           v2.2.x     #486   +/-   ##
=======================================
  Coverage   80.74%   80.74%           
=======================================
  Files          33       33           
  Lines        2727     2727           
=======================================
  Hits         2202     2202           
  Misses        419      419           
  Partials      106      106           
```


| [Impacted Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/486?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [client/interceptor.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/486?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L2ludGVyY2VwdG9yLmdv) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/client/interceptor.go b/client/interceptor.go
index 6ef9eeb..f2fcb10 100644
--- a/client/interceptor.go
+++ b/client/interceptor.go
@@ -25,7 +25,7 @@ func authenticationInterceptor(ctx context.Context, username, password string) c
 
 func apiKeyInterceptor(ctx context.Context, apiKey string) context.Context {
 	if apiKey != "" {
-		value := crypto.Base64Encode(fmt.Sprintf("Bearer: %s", apiKey))
+		value := crypto.Base64Encode(apiKey)
 		return metadata.AppendToOutgoingContext(ctx, authorizationHeader, value)
 	}
 	return ctx


Test patch:
diff --git a/client/interceptor_test.go b/client/interceptor_test.go
index cdd9379..b4b9d88 100644
--- a/client/interceptor_test.go
+++ b/client/interceptor_test.go
@@ -37,7 +37,7 @@ func TestAPIInterceptor(t *testing.T) {
 	ctx := context.Background()
 	ctx = apiKeyInterceptor(ctx, "test-token")
 	md, ok := metadata.FromOutgoingContext(ctx)
-	value := crypto.Base64Encode(fmt.Sprintf("Bearer: %s", "test-token"))
+	value := crypto.Base64Encode("test-token")
 	assert.True(t, ok)
 	assert.Equal(t, 1, len(md[authorizationHeader]))
 	assert.Equal(t, value, md[authorizationHeader][0])