Support pushed CarrierNode credentials
This commit is contained in:
1 parent
4b0566ea46
commit
e4c1826d6a
3 files changed
+43
-5
No files matched your search
@@ -41,6 +41,12 @@ type Client struct {
|
||||
// calls from public traffic. Empty means no header is sent.
|
||||
InternalServiceSecret string
|
||||
|
||||
// InternalServiceSecretFunc, when set, resolves the current secret for
|
||||
// each request. This lets callers use ProjectConfigurator's live
|
||||
// per-service secret while retaining InternalServiceSecret as the
|
||||
// bootstrap/fallback value.
|
||||
InternalServiceSecretFunc func(ctx context.Context) string
|
||||
|
||||
// BaseURL resolves CarrierNode's current base URL for a request. It is a
|
||||
// function rather than a fixed string because CarrierNode's URL is
|
||||
// configured live through ProjectConfigurator's Projects workspace
|
||||
@@ -123,8 +129,12 @@ func (c *Client) newRequest(ctx context.Context, baseURL, method, path string, b
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.InternalServiceSecret != "" {
|
||||
request.Header.Set("X-Internal-Auth", c.InternalServiceSecret)
|
||||
secret := c.InternalServiceSecret
|
||||
if c.InternalServiceSecretFunc != nil {
|
||||
secret = strings.TrimSpace(c.InternalServiceSecretFunc(ctx))
|
||||
}
|
||||
if secret != "" {
|
||||
request.Header.Set("X-Internal-Auth", secret)
|
||||
}
|
||||
return request, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user