77 "os"
88 "path/filepath"
99
10+ "github.com/stackitcloud/stackit-cli/internal/pkg/config"
11+
1012 "github.com/zalando/go-keyring"
1113)
1214
@@ -69,6 +71,15 @@ func SetAuthField(key authFieldKey, value string) error {
6971}
7072
7173func setAuthFieldInKeyring (key authFieldKey , value string ) error {
74+ activeProfile , err := config .GetProfile ()
75+ if err != nil {
76+ return fmt .Errorf ("get profile: %w" , err )
77+ }
78+
79+ if activeProfile != "" {
80+ activeProfileKeyring := filepath .Join (keyringService , activeProfile )
81+ return keyring .Set (activeProfileKeyring , string (key ), value )
82+ }
7283 return keyring .Set (keyringService , string (key ), value )
7384}
7485
@@ -82,7 +93,18 @@ func setAuthFieldInEncodedTextFile(key authFieldKey, value string) error {
8293 if err != nil {
8394 return fmt .Errorf ("get config dir: %w" , err )
8495 }
85- textFileDir := filepath .Join (configDir , textFileFolderName )
96+
97+ activeProfile , err := config .GetProfile ()
98+ if err != nil {
99+ return fmt .Errorf ("get profile: %w" , err )
100+ }
101+
102+ profileTextFileFolderName := textFileFolderName
103+ if activeProfile != "" {
104+ profileTextFileFolderName = filepath .Join (activeProfile , textFileFolderName )
105+ }
106+
107+ textFileDir := filepath .Join (configDir , profileTextFileFolderName )
86108 textFilePath := filepath .Join (textFileDir , textFileName )
87109
88110 contentEncoded , err := os .ReadFile (textFilePath )
@@ -143,6 +165,15 @@ func GetAuthField(key authFieldKey) (string, error) {
143165}
144166
145167func getAuthFieldFromKeyring (key authFieldKey ) (string , error ) {
168+ activeProfile , err := config .GetProfile ()
169+ if err != nil {
170+ return "" , fmt .Errorf ("get profile: %w" , err )
171+ }
172+
173+ if activeProfile != "" {
174+ activeProfileKeyring := filepath .Join (keyringService , activeProfile )
175+ return keyring .Get (activeProfileKeyring , string (key ))
176+ }
146177 return keyring .Get (keyringService , string (key ))
147178}
148179
@@ -156,7 +187,18 @@ func getAuthFieldFromEncodedTextFile(key authFieldKey) (string, error) {
156187 if err != nil {
157188 return "" , fmt .Errorf ("get config dir: %w" , err )
158189 }
159- textFileDir := filepath .Join (configDir , textFileFolderName )
190+
191+ activeProfile , err := config .GetProfile ()
192+ if err != nil {
193+ return "" , fmt .Errorf ("get profile: %w" , err )
194+ }
195+
196+ profileTextFileFolderName := textFileFolderName
197+ if activeProfile != "" {
198+ profileTextFileFolderName = filepath .Join (activeProfile , textFileFolderName )
199+ }
200+
201+ textFileDir := filepath .Join (configDir , profileTextFileFolderName )
160202 textFilePath := filepath .Join (textFileDir , textFileName )
161203
162204 contentEncoded , err := os .ReadFile (textFilePath )
@@ -187,7 +229,18 @@ func createEncodedTextFile() error {
187229 if err != nil {
188230 return fmt .Errorf ("get config dir: %w" , err )
189231 }
190- textFileDir := filepath .Join (configDir , textFileFolderName )
232+
233+ activeProfile , err := config .GetProfile ()
234+ if err != nil {
235+ return fmt .Errorf ("get profile: %w" , err )
236+ }
237+
238+ profileTextFileFolderName := textFileFolderName
239+ if activeProfile != "" {
240+ profileTextFileFolderName = filepath .Join (activeProfile , textFileFolderName )
241+ }
242+
243+ textFileDir := filepath .Join (configDir , profileTextFileFolderName )
191244 textFilePath := filepath .Join (textFileDir , textFileName )
192245
193246 err = os .MkdirAll (textFileDir , os .ModePerm )
0 commit comments