Skip to content

Commit 5d98897

Browse files
[GCP Bindings Bucket] Adds Component Metadata Schema (#2936)
Signed-off-by: Roberto J Rojas <[email protected]> Signed-off-by: Roberto Rojas <[email protected]> Co-authored-by: Alessandro (Ale) Segala <[email protected]>
1 parent 80fdafc commit 5d98897

File tree

4 files changed

+173
-61
lines changed

4 files changed

+173
-61
lines changed

.build-tools/builtin-authentication-profiles.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,72 @@ azuread:
103103
- AzurePublicCloud
104104
- AzureChinaCloud
105105
- AzureUSGovernmentCloud
106+
107+
gcp:
108+
- title: "GCP API Authentication with Service Account Key"
109+
description: |
110+
Authenticate authenticates API calls with the given service account or refresh token JSON credentials.
111+
metadata:
112+
- name: privateKeyID
113+
required: true
114+
sensitive: true
115+
description: |
116+
The GCP private key id. Replace with the value of "private_key_id" field of the Service Account Key file.
117+
example: '"privateKeyID"'
118+
- name: privateKey
119+
required: true
120+
sensitive: true
121+
description: |
122+
The GCP credentials private key. Replace with the value of "private_key" field of the Service Account Key file.
123+
example: '"-----BEGIN PRIVATE KEY-----\nMIIE...\\n-----END PRIVATE KEY-----\n"'
124+
- name: type
125+
type: string
126+
required: false
127+
description: |
128+
The GCP credentials type.
129+
example: '"service_account"'
130+
allowedValues:
131+
- service_account
132+
- name: projectID
133+
type: string
134+
required: true
135+
description: |
136+
GCP project id.
137+
example: '"projectID"'
138+
- name: clientEmail
139+
type: string
140+
required: true
141+
description: |
142+
GCP client email.
143+
example: '"[email protected]"'
144+
- name: clientID
145+
type: string
146+
required: true
147+
description: |
148+
The GCP client ID.
149+
example: '"0123456789-0123456789"'
150+
- name: authURI
151+
type: string
152+
required: false
153+
description: |
154+
The GCP account OAuth2 authorization server endpoint URI.
155+
example: '"https://accounts.google.com/o/oauth2/auth"'
156+
- name: tokenURI
157+
type: string
158+
required: false
159+
description: |
160+
The GCP account token server endpoint URI.
161+
example: '"https://oauth2.googleapis.com/token"'
162+
- name: authProviderX509CertURL
163+
type: string
164+
required: false
165+
description: |
166+
The GCP URL of the public x509 certificate, used to verify the signature
167+
on JWTs, such as ID tokens, signed by the authentication provider.
168+
example: '"https://www.googleapis.com/oauth2/v1/certs"'
169+
- name: clientX509CertURL
170+
type: string
171+
required: false
172+
description: |
173+
The GCP URL of the public x509 certificate, used to verify JWTs signed by the client.
174+
example: '"https://www.googleapis.com/robot/v1/metadata/x509/<PROJECT_NAME>.iam.gserviceaccount.com"'

bindings/gcp/bucket/bucket.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ type GCPStorage struct {
5454
}
5555

5656
type gcpMetadata struct {
57-
Bucket string `json:"bucket" mapstructure:"bucket"`
58-
Type string `json:"type" mapstructure:"type"`
59-
ProjectID string `json:"project_id" mapstructure:"project_id"`
60-
PrivateKeyID string `json:"private_key_id" mapstructure:"private_key_id"`
61-
PrivateKey string `json:"private_key" mapstructure:"private_key"`
62-
ClientEmail string `json:"client_email " mapstructure:"client_email"`
63-
ClientID string `json:"client_id" mapstructure:"client_id"`
64-
AuthURI string `json:"auth_uri" mapstructure:"auth_uri"`
65-
TokenURI string `json:"token_uri" mapstructure:"token_uri"`
66-
AuthProviderCertURL string `json:"auth_provider_x509_cert_url" mapstructure:"auth_provider_x509_cert_url"`
67-
ClientCertURL string `json:"client_x509_cert_url" mapstructure:"client_x509_cert_url"`
68-
DecodeBase64 bool `json:"decodeBase64,string" mapstructure:"decodeBase64"`
69-
EncodeBase64 bool `json:"encodeBase64,string" mapstructure:"encodeBase64"`
57+
// Ignored by metadata parser because included in built-in authentication profile
58+
Type string `json:"type" mapstructure:"type" mdignore:"true"`
59+
ProjectID string `json:"project_id" mapstructure:"projectID" mdignore:"true" mapstructurealiases:"project_id"`
60+
PrivateKeyID string `json:"private_key_id" mapstructure:"privateKeyID" mdignore:"true" mapstructurealiases:"private_key_id"`
61+
PrivateKey string `json:"private_key" mapstructure:"privateKey" mdignore:"true" mapstructurealiases:"private_key"`
62+
ClientEmail string `json:"client_email " mapstructure:"clientEmail" mdignore:"true" mapstructurealiases:"client_email"`
63+
ClientID string `json:"client_id" mapstructure:"clientID" mdignore:"true" mapstructurealiases:"client_id"`
64+
AuthURI string `json:"auth_uri" mapstructure:"authURI" mdignore:"true" mapstructurealiases:"auth_uri"`
65+
TokenURI string `json:"token_uri" mapstructure:"tokenURI" mdignore:"true" mapstructurealiases:"token_uri"`
66+
AuthProviderCertURL string `json:"auth_provider_x509_cert_url" mapstructure:"authProviderX509CertURL" mdignore:"true" mapstructurealiases:"auth_provider_x509_cert_url"`
67+
ClientCertURL string `json:"client_x509_cert_url" mapstructure:"clientX509CertURL" mdignore:"true" mapstructurealiases:"client_x509_cert_url"`
68+
69+
Bucket string `json:"bucket" mapstructure:"bucket"`
70+
DecodeBase64 bool `json:"decodeBase64,string" mapstructure:"decodeBase64"`
71+
EncodeBase64 bool `json:"encodeBase64,string" mapstructure:"encodeBase64"`
7072
}
7173

7274
type listPayload struct {

bindings/gcp/bucket/bucket_test.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ func TestParseMetadata(t *testing.T) {
2727
t.Run("Has correct metadata", func(t *testing.T) {
2828
m := bindings.Metadata{}
2929
m.Properties = map[string]string{
30-
"auth_provider_x509_cert_url": "my_auth_provider_x509",
31-
"auth_uri": "my_auth_uri",
32-
"Bucket": "my_bucket",
33-
"client_x509_cert_url": "my_client_x509",
34-
"client_email": "[email protected]",
35-
"client_id": "my_client_id",
36-
"private_key": "my_private_key",
37-
"private_key_id": "my_private_key_id",
38-
"project_id": "my_project_id",
39-
"token_uri": "my_token_uri",
40-
"type": "my_type",
30+
"authProviderX509CertURL": "my_auth_provider_x509",
31+
"authURI": "my_auth_uri",
32+
"Bucket": "my_bucket",
33+
"clientX509CertURL": "my_client_x509",
34+
"clientEmail": "[email protected]",
35+
"clientID": "my_client_id",
36+
"privateKey": "my_private_key",
37+
"privateKeyID": "my_private_key_id",
38+
"projectID": "my_project_id",
39+
"tokenURI": "my_token_uri",
40+
"type": "my_type",
4141
}
4242
gs := GCPStorage{logger: logger.NewLogger("test")}
4343
meta, err := gs.parseMetadata(m)
@@ -73,18 +73,18 @@ func TestMergeWithRequestMetadata(t *testing.T) {
7373
t.Run("Has merged metadata", func(t *testing.T) {
7474
m := bindings.Metadata{}
7575
m.Properties = map[string]string{
76-
"auth_provider_x509_cert_url": "my_auth_provider_x509",
77-
"auth_uri": "my_auth_uri",
78-
"Bucket": "my_bucket",
79-
"client_x509_cert_url": "my_client_x509",
80-
"client_email": "[email protected]",
81-
"client_id": "my_client_id",
82-
"private_key": "my_private_key",
83-
"private_key_id": "my_private_key_id",
84-
"project_id": "my_project_id",
85-
"token_uri": "my_token_uri",
86-
"type": "my_type",
87-
"decodeBase64": "false",
76+
"authProviderX509CertURL": "my_auth_provider_x509",
77+
"authURI": "my_auth_uri",
78+
"Bucket": "my_bucket",
79+
"clientX509CertURL": "my_client_x509",
80+
"clientEmail": "[email protected]",
81+
"clientID": "my_client_id",
82+
"privateKey": "my_private_key",
83+
"privateKeyID": "my_private_key_id",
84+
"projectID": "my_project_id",
85+
"tokenURI": "my_token_uri",
86+
"type": "my_type",
87+
"decodeBase64": "false",
8888
}
8989
gs := GCPStorage{logger: logger.NewLogger("test")}
9090
meta, err := gs.parseMetadata(m)
@@ -129,18 +129,18 @@ func TestMergeWithRequestMetadata(t *testing.T) {
129129
t.Run("Has invalid merged metadata decodeBase64", func(t *testing.T) {
130130
m := bindings.Metadata{}
131131
m.Properties = map[string]string{
132-
"auth_provider_x509_cert_url": "my_auth_provider_x509",
133-
"auth_uri": "my_auth_uri",
134-
"Bucket": "my_bucket",
135-
"client_x509_cert_url": "my_client_x509",
136-
"client_email": "[email protected]",
137-
"client_id": "my_client_id",
138-
"private_key": "my_private_key",
139-
"private_key_id": "my_private_key_id",
140-
"project_id": "my_project_id",
141-
"token_uri": "my_token_uri",
142-
"type": "my_type",
143-
"decodeBase64": "false",
132+
"authProviderX509CertURL": "my_auth_provider_x509",
133+
"authURI": "my_auth_uri",
134+
"Bucket": "my_bucket",
135+
"clientX509CertURL": "my_client_x509",
136+
"clientEmail": "[email protected]",
137+
"clientID": "my_client_id",
138+
"privateKey": "my_private_key",
139+
"privateKeyID": "my_private_key_id",
140+
"projectID": "my_project_id",
141+
"tokenURI": "my_token_uri",
142+
"type": "my_type",
143+
"decodeBase64": "false",
144144
}
145145
gs := GCPStorage{logger: logger.NewLogger("test")}
146146
meta, err := gs.parseMetadata(m)
@@ -173,19 +173,19 @@ func TestMergeWithRequestMetadata(t *testing.T) {
173173
t.Run("Has invalid merged metadata encodeBase64", func(t *testing.T) {
174174
m := bindings.Metadata{}
175175
m.Properties = map[string]string{
176-
"auth_provider_x509_cert_url": "my_auth_provider_x509",
177-
"auth_uri": "my_auth_uri",
178-
"Bucket": "my_bucket",
179-
"client_x509_cert_url": "my_client_x509",
180-
"client_email": "[email protected]",
181-
"client_id": "my_client_id",
182-
"private_key": "my_private_key",
183-
"private_key_id": "my_private_key_id",
184-
"project_id": "my_project_id",
185-
"token_uri": "my_token_uri",
186-
"type": "my_type",
187-
"decodeBase64": "false",
188-
"encodeBase64": "true",
176+
"authProviderX509CertURL": "my_auth_provider_x509",
177+
"authURI": "my_auth_uri",
178+
"Bucket": "my_bucket",
179+
"clientX509CertURL": "my_client_x509",
180+
"clientEmail": "[email protected]",
181+
"clientID": "my_client_id",
182+
"privateKey": "my_private_key",
183+
"privateKeyID": "my_private_key_id",
184+
"projectID": "my_project_id",
185+
"tokenURI": "my_token_uri",
186+
"type": "my_type",
187+
"decodeBase64": "false",
188+
"encodeBase64": "true",
189189
}
190190
gs := GCPStorage{logger: logger.NewLogger("test")}
191191
meta, err := gs.parseMetadata(m)

bindings/gcp/bucket/metadata.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# yaml-language-server: $schema=../../../component-metadata-schema.json
2+
schemaVersion: v1
3+
type: bindings
4+
name: gcp.bucket
5+
version: v1
6+
status: alpha
7+
title: "GCP Storage Bucket"
8+
urls:
9+
- title: Reference
10+
url: https://docs.dapr.io/reference/components-reference/supported-bindings/gcpbucket/
11+
binding:
12+
output: true
13+
operations:
14+
- name: create
15+
description: "Create an item."
16+
capabilities: []
17+
builtinAuthenticationProfiles:
18+
- name: "gcp"
19+
metadata:
20+
- name: bucket
21+
required: true
22+
description: |
23+
The bucket name.
24+
example: '"mybucket"'
25+
type: string
26+
- name: decodeBase64
27+
type: bool
28+
required: false
29+
default: 'false'
30+
description: |
31+
Configuration to decode base64 file content before saving to bucket storage.
32+
(In case of opening a file with binary content).
33+
example: '"true, false"'
34+
- name: encodeBase64
35+
type: bool
36+
required: false
37+
default: 'false'
38+
description: |
39+
Configuration to encode base64 file content before return the content.
40+
(In case of saving a file with binary content).
41+
example: '"true, false"'

0 commit comments

Comments
 (0)