Skip to content

Commit 71e66bb

Browse files
feat(service-account): enable credentials to be saved as secret (#1575)
1 parent 4db0807 commit 71e66bb

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pkg/cmd/serviceaccount/svcaccountcmdutil/credentials/credentials.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package credentials
33
import (
44
"errors"
55
"fmt"
6-
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/color"
76
"io/ioutil"
87
"os"
98
"path/filepath"
109

10+
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/color"
11+
1112
"github.com/AlecAivazis/survey/v2"
1213
"github.com/MakeNowJust/heredoc"
1314
)
@@ -16,6 +17,7 @@ const (
1617
EnvFormat = "env"
1718
JSONFormat = "json"
1819
PropertiesFormat = "properties"
20+
SecretFormat = "secret"
1921
)
2022

2123
// Templates
@@ -40,6 +42,18 @@ var (
4042
"clientSecret":"%v",
4143
"oauthTokenUrl":"%v"
4244
}`)
45+
46+
templateSecret = heredoc.Doc(`
47+
apiVersion: v1
48+
kind: Secret
49+
metadata:
50+
name: service-account-credentials
51+
type: Opaque
52+
stringData:
53+
RHOAS_SERVICE_ACCOUNT_CLIENT_ID: %v
54+
RHOAS_SERVICE_ACCOUNT_CLIENT_SECRET: %v
55+
RHOAS_SERVICE_ACCOUNT_OAUTH_TOKEN_URL: %v
56+
`)
4357
)
4458

4559
// Credentials is a type which represents the credentials
@@ -59,6 +73,8 @@ func GetDefaultPath(outputFormat string) (filePath string) {
5973
filePath = "credentials.properties"
6074
case JSONFormat:
6175
filePath = "credentials.json"
76+
case SecretFormat:
77+
filePath = "credentials.yaml"
6278
}
6379

6480
pwd, err := os.Getwd()
@@ -94,6 +110,8 @@ func getFileFormat(output string) (format string) {
94110
format = templateProperties
95111
case JSONFormat:
96112
format = templateJSON
113+
case SecretFormat:
114+
format = templateSecret
97115
}
98116

99117
return format

pkg/cmd/serviceaccount/svcaccountcmdutil/svcaccount_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
var (
12-
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat}
12+
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat, credentials.SecretFormat}
1313
)
1414

1515
// Method fetches authentication details for providers

0 commit comments

Comments
 (0)