From 6db3513ef56ff6a1e05f4c6f4f88d04baadffe0b Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 17 Jun 2020 17:45:39 +0900 Subject: [PATCH] :fire: remove serviceAccountFile option and revise functions Signed-off-by: Rintaro Okamura --- charts/vald/templates/_helpers.tpl | 1 - charts/vald/values.yaml | 3 - .../observability/client/google/option.go | 89 +++++++++++++++---- 3 files changed, 70 insertions(+), 23 deletions(-) diff --git a/charts/vald/templates/_helpers.tpl b/charts/vald/templates/_helpers.tpl index 53e08f62d40..bf175af006d 100755 --- a/charts/vald/templates/_helpers.tpl +++ b/charts/vald/templates/_helpers.tpl @@ -621,7 +621,6 @@ stackdriver: {{- else }} scopes: [] {{- end }} - service_account_file: {{ default .default.stackdriver.client.service_account_file .Values.stackdriver.client.service_account_file | quote }} user_agent: {{ default .default.stackdriver.client.user_agent .Values.stackdriver.client.user_agent | quote }} telemetry_enabled: {{ default .default.stackdriver.client.telemetry_enabled .Values.stackdriver.client.telemetry_enabled }} authentication_enabled: {{ default .default.stackdriver.client.authentication_enabled .Values.stackdriver.client.authentication_enabled }} diff --git a/charts/vald/values.yaml b/charts/vald/values.yaml index e4d291774cf..ddc5177b8cc 100644 --- a/charts/vald/values.yaml +++ b/charts/vald/values.yaml @@ -651,9 +651,6 @@ defaults: # @schema {"name": "defaults.observability.stackdriver.client.scopes", "type": "array", "items": {"type": "string"}} # defaults.observability.stackdriver.client.scopes -- overrides the default OAuth2 scopes to be used for a service. scopes: [] - # @schema {"name": "defaults.observability.stackdriver.client.service_account_file", "type": "string"} - # defaults.observability.stackdriver.client.service_account_file -- a Google service account credentials file to authenticate. - service_account_file: "" # @schema {"name": "defaults.observability.stackdriver.client.user_agent", "type": "string"} # defaults.observability.stackdriver.client.user_agent -- sets the User-Agent. user_agent: "" diff --git a/internal/observability/client/google/option.go b/internal/observability/client/google/option.go index 8056581d31f..4ec89161d47 100644 --- a/internal/observability/client/google/option.go +++ b/internal/observability/client/google/option.go @@ -23,25 +23,76 @@ import ( type Option = option.ClientOption -var ( - WithAPIKey = option.WithAPIKey - WithAudiences = option.WithAudiences - WithCredentialsFile = option.WithCredentialsFile - WithEndpoint = option.WithEndpoint - WithQuotaProject = option.WithQuotaProject - WithRequestReason = option.WithRequestReason - WithScopes = option.WithScopes - WithServiceAccountFile = option.WithServiceAccountFile - WithUserAgent = option.WithUserAgent - - // WithClientCertSource(s ClientCertSource) ClientOption - // WithCredentials(creds *google.Credentials) ClientOption - // WithGRPCConn(conn *grpc.ClientConn) ClientOption - // WithGRPCConnectionPool(size int) ClientOption - // WithGRPCDialOption(opt grpc.DialOption) ClientOption - // WithHTTPClient(client *http.Client) ClientOption - // WithTokenSource(s oauth2.TokenSource) ClientOption -) +// WithClientCertSource(s ClientCertSource) ClientOption +// WithCredentials(creds *google.Credentials) ClientOption +// WithGRPCConn(conn *grpc.ClientConn) ClientOption +// WithGRPCConnectionPool(size int) ClientOption +// WithGRPCDialOption(opt grpc.DialOption) ClientOption +// WithHTTPClient(client *http.Client) ClientOption +// WithTokenSource(s oauth2.TokenSource) ClientOption + +func WithAPIKey(apiKey string) Option { + if apiKey == "" { + return nil + } + return option.WithAPIKey(apiKey) +} + +func WithAudiences(audiences ...string) Option { + if len(audiences) == 0 { + return nil + } + + return option.WithAudiences(audiences...) +} + +func WithCredentialsFile(path string) Option { + if path == "" { + return nil + } + + return option.WithCredentialsFile(path) +} + +func WithEndpoint(endpoint string) Option { + if endpoint == "" { + return nil + } + + return option.WithEndpoint(endpoint) +} + +func WithQuotaProject(qp string) Option { + if qp == "" { + return nil + } + + return option.WithQuotaProject(qp) +} + +func WithRequestReason(rr string) Option { + if rr == "" { + return nil + } + + return option.WithRequestReason(rr) +} + +func WithScopes(scopes ...string) Option { + if len(scopes) == 0 { + return nil + } + + return option.WithScopes(scopes...) +} + +func WithUserAgent(ua string) Option { + if ua == "" { + return nil + } + + return option.WithUserAgent(ua) +} func WithCredentialsJSON(json string) Option { if json != "" {