Skip to content

Commit de33ef8

Browse files
committed
move base64Encode function to utils
1 parent 05e7593 commit de33ef8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

internal/pkg/auth/user_login.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package auth
22

33
import (
44
_ "embed"
5-
"encoding/base64"
65
"encoding/json"
76
"errors"
87
"fmt"
@@ -17,6 +16,7 @@ import (
1716
"strings"
1817
"time"
1918

19+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2020
"golang.org/x/oauth2"
2121

2222
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
@@ -218,7 +218,7 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
218218

219219
input := InputValues{
220220
Email: email,
221-
Logo: base64Encode(logoSvgContent),
221+
Logo: utils.Base64Encode(logoSvgContent),
222222
}
223223

224224
// ParseFS expects paths using forward slashes, even on Windows
@@ -260,13 +260,6 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
260260
return nil
261261
}
262262

263-
// base64Encode encodes a []byte to a base64 representation as string
264-
func base64Encode(message []byte) string {
265-
b := make([]byte, base64.StdEncoding.EncodedLen(len(message)))
266-
base64.StdEncoding.Encode(b, message)
267-
return string(b)
268-
}
269-
270263
// getUserAccessAndRefreshTokens trades the authorization code retrieved from the first OAuth2 leg for an access token and a refresh token
271264
func getUserAccessAndRefreshTokens(idpWellKnownConfig *wellKnownConfig, clientID, codeVerifier, authorizationCode, callbackURL string) (accessToken, refreshToken string, err error) {
272265
// Set form-encoded data for the POST to the access token endpoint

internal/pkg/utils/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"encoding/base64"
45
"fmt"
56
"net/url"
67
"strings"
@@ -116,3 +117,10 @@ func PtrByteSizeDefault(size *int64, defaultValue string) string {
116117
}
117118
return bytesize.New(float64(*size)).String()
118119
}
120+
121+
// Base64Encode encodes a []byte to a base64 representation as string
122+
func Base64Encode(message []byte) string {
123+
b := make([]byte, base64.StdEncoding.EncodedLen(len(message)))
124+
base64.StdEncoding.Encode(b, message)
125+
return string(b)
126+
}

0 commit comments

Comments
 (0)