Skip to content

Commit 4d4e320

Browse files
committed
Deprecate Service Account Mail option and remove tests for it
1 parent 6319ecc commit 4d4e320

File tree

4 files changed

+7
-101
lines changed

4 files changed

+7
-101
lines changed

core/auth/auth.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type credentialType string
1515

1616
type Credentials struct {
17-
STACKIT_SERVICE_ACCOUNT_EMAIL string
17+
STACKIT_SERVICE_ACCOUNT_EMAIL string // Deprecated: ServiceAccountEmail is not required anymore.
1818
STACKIT_SERVICE_ACCOUNT_TOKEN string
1919
STACKIT_SERVICE_ACCOUNT_KEY_PATH string
2020
STACKIT_PRIVATE_KEY_PATH string
@@ -32,8 +32,6 @@ const (
3232
func SetupAuth(cfg *config.Configuration) (rt http.RoundTripper, err error) {
3333
if cfg == nil {
3434
cfg = &config.Configuration{}
35-
email := getServiceAccountEmail(cfg)
36-
cfg.ServiceAccountEmail = email
3735
}
3836

3937
if cfg.CustomAuth != nil {
@@ -244,25 +242,6 @@ func readCredential(cred credentialType, credentials *Credentials) (string, erro
244242
return credentialValue, nil
245243
}
246244

247-
// getServiceAccountEmail searches for an email in the following order: client configuration, environment variable, credentials file.
248-
// is not required for authentication, so it can be empty.
249-
func getServiceAccountEmail(cfg *config.Configuration) string {
250-
if cfg.ServiceAccountEmail != "" {
251-
return cfg.ServiceAccountEmail
252-
}
253-
254-
email, emailSet := os.LookupEnv("STACKIT_SERVICE_ACCOUNT_EMAIL")
255-
if !emailSet || email == "" {
256-
credentials, err := readCredentialsFile(cfg.CredentialsFilePath)
257-
if err != nil {
258-
// email is not required for authentication, so it shouldnt block it
259-
return ""
260-
}
261-
return credentials.STACKIT_SERVICE_ACCOUNT_EMAIL
262-
}
263-
return email
264-
}
265-
266245
// getKey searches for a key in the following order: client configuration, environment variable, credentials file.
267246
func getKey(cfgKey, cfgKeyPath *string, envVar, credType credentialType, cfgCredFilePath string) error {
268247
if *cfgKey != "" {

core/auth/auth_test.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ func TestSetupAuth(t *testing.T) {
170170
t.Setenv("STACKIT_CREDENTIALS_PATH", "")
171171
}
172172

173-
t.Setenv("STACKIT_SERVICE_ACCOUNT_EMAIL", "test-email")
174-
175173
authRoundTripper, err := SetupAuth(test.config)
176174

177175
if err != nil && test.isValid {
@@ -570,78 +568,6 @@ func TestNoAuth(t *testing.T) {
570568
}
571569
}
572570

573-
func TestGetServiceAccountEmail(t *testing.T) {
574-
for _, test := range []struct {
575-
description string
576-
cfg *config.Configuration
577-
envEmailSet bool
578-
path string
579-
expectedEmail string
580-
isValid bool
581-
}{
582-
{
583-
description: "custom_config",
584-
cfg: &config.Configuration{
585-
ServiceAccountEmail: "test_email",
586-
},
587-
path: "",
588-
expectedEmail: "test_email",
589-
isValid: true,
590-
},
591-
{
592-
description: "config_over_env_var",
593-
cfg: &config.Configuration{},
594-
envEmailSet: true,
595-
path: "",
596-
expectedEmail: "env_email",
597-
isValid: true,
598-
},
599-
{
600-
description: "env_variable",
601-
cfg: &config.Configuration{
602-
ServiceAccountEmail: "test_email",
603-
},
604-
envEmailSet: true,
605-
path: "",
606-
expectedEmail: "test_email",
607-
isValid: true,
608-
},
609-
{
610-
description: "path",
611-
cfg: &config.Configuration{},
612-
envEmailSet: false,
613-
path: "test_resources/test_credentials_bar.json",
614-
expectedEmail: "bar_email",
615-
isValid: true,
616-
},
617-
{
618-
description: "invalid_structure",
619-
cfg: &config.Configuration{},
620-
envEmailSet: false,
621-
path: "test_resources/test_invalid_structure.json",
622-
expectedEmail: "",
623-
isValid: false,
624-
},
625-
} {
626-
t.Run(test.description, func(t *testing.T) {
627-
if test.envEmailSet {
628-
t.Setenv("STACKIT_SERVICE_ACCOUNT_EMAIL", "env_email")
629-
} else {
630-
t.Setenv("STACKIT_SERVICE_ACCOUNT_EMAIL", "")
631-
}
632-
t.Setenv("STACKIT_CREDENTIALS_PATH", test.path)
633-
got := getServiceAccountEmail(test.cfg)
634-
if (got != "") && !test.isValid {
635-
t.Errorf("getServiceAccountEmail() did not return empty value for invalid test case")
636-
return
637-
}
638-
if got != test.expectedEmail {
639-
t.Errorf("getServiceAccountEmail() = %v, want %v", got, test.expectedEmail)
640-
}
641-
})
642-
}
643-
}
644-
645571
func generatePrivateKey() (string, error) {
646572
// Generate a new RSA key pair with a size of 2048 bits
647573
privKey, err := rsa.GenerateKey(rand.Reader, 2048)

core/clients/token_flow.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type TokenFlow struct {
1919

2020
// TokenFlowConfig is the flow config
2121
type TokenFlowConfig struct {
22+
// Deprecated: ServiceAccountEmail is not required anymore.
2223
ServiceAccountEmail string
2324
ServiceAccountToken string
2425
// Deprecated: retry options were removed to reduce complexity of the client. If this functionality is needed, you can provide your own custom HTTP client.

core/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type Configuration struct {
8181
UserAgent string `json:"userAgent,omitempty"`
8282
Debug bool `json:"debug,omitempty"`
8383
NoAuth bool `json:"noAuth,omitempty"`
84-
ServiceAccountEmail string `json:"serviceAccountEmail,omitempty"`
84+
ServiceAccountEmail string `json:"serviceAccountEmail,omitempty"` // Deprecated: ServiceAccountEmail is not required anymore.
8585
Token string `json:"token,omitempty"`
8686
ServiceAccountKey string `json:"serviceAccountKey,omitempty"`
8787
PrivateKey string `json:"privateKey,omitempty"`
@@ -176,9 +176,10 @@ func WithTokenEndpoint(url string) ConfigurationOption {
176176
}
177177

178178
// WithServiceAccountEmail returns a ConfigurationOption that sets the service account email
179-
func WithServiceAccountEmail(serviceAccountEmail string) ConfigurationOption {
180-
return func(config *Configuration) error {
181-
config.ServiceAccountEmail = serviceAccountEmail
179+
//
180+
// Deprecated: WithServiceAccountEmail is not required anymore.
181+
func WithServiceAccountEmail(_ string) ConfigurationOption {
182+
return func(_ *Configuration) error {
182183
return nil
183184
}
184185
}
@@ -319,7 +320,6 @@ func WithCustomConfiguration(cfg *Configuration) ConfigurationOption {
319320
config.NoAuth = cfg.NoAuth
320321
config.Token = cfg.Token
321322
config.ServiceAccountKey = cfg.ServiceAccountKey
322-
config.ServiceAccountEmail = cfg.ServiceAccountEmail
323323
config.ServiceAccountKeyPath = cfg.ServiceAccountKeyPath
324324
config.PrivateKey = cfg.PrivateKey
325325
config.PrivateKeyPath = cfg.PrivateKeyPath

0 commit comments

Comments
 (0)