Skip to content

Commit f219981

Browse files
authored
replace STACKIT logo on login page (#661)
* add new STACKIT logo * add logo as base64 to the login-successful.html
1 parent b3c931a commit f219981

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

internal/pkg/auth/templates/login-successful.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
<div class="logo m-5">
272272
<img
273273
alt="logo"
274-
src="https://cdn.apps.01.cf.eu01.stackit.cloud/assets/img/logo_inverted.svg"
274+
src="data:image/svg+xml;base64,{{.Logo}}"
275275
/>
276276
</div>
277277

Loading

internal/pkg/auth/user_login.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package auth
22

33
import (
4-
"embed"
4+
_ "embed"
55
"encoding/json"
66
"errors"
77
"fmt"
@@ -11,12 +11,12 @@ import (
1111
"net/http"
1212
"os"
1313
"os/exec"
14-
"path"
1514
"runtime"
1615
"strconv"
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"
@@ -26,22 +26,23 @@ const (
2626
defaultWellKnownConfig = "https://accounts.stackit.cloud/.well-known/openid-configuration"
2727
defaultCLIClientID = "stackit-cli-0000-0000-000000000001"
2828

29-
loginSuccessPath = "/login-successful"
30-
stackitLandingPage = "https://www.stackit.de"
31-
htmlTemplatesPath = "templates"
32-
loginSuccessfulHTMLFile = "login-successful.html"
29+
loginSuccessPath = "/login-successful"
3330

3431
// The IDP doesn't support wildcards for the port,
3532
// so we configure a range of ports from 8000 to 8020
3633
defaultPort = 8000
3734
configuredPortRange = 20
3835
)
3936

40-
//go:embed templates/*
41-
var htmlContent embed.FS
37+
//go:embed templates/login-successful.html
38+
var htmlTemplateContent string
4239

43-
type User struct {
40+
//go:embed templates/stackit_nav_logo_light.svg
41+
var logoSvgContent []byte
42+
43+
type InputValues struct {
4444
Email string
45+
Logo string
4546
}
4647

4748
type apiClient interface {
@@ -215,18 +216,19 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
215216
errServer = fmt.Errorf("read user email: %w", err)
216217
}
217218

218-
user := User{
219+
input := InputValues{
219220
Email: email,
221+
Logo: utils.Base64Encode(logoSvgContent),
220222
}
221223

222224
// ParseFS expects paths using forward slashes, even on Windows
223225
// See: https://github.com/golang/go/issues/44305#issuecomment-780111748
224-
htmlTemplate, err := template.ParseFS(htmlContent, path.Join(htmlTemplatesPath, loginSuccessfulHTMLFile))
226+
htmlTemplate, err := template.New("loginSuccess").Parse(htmlTemplateContent)
225227
if err != nil {
226228
errServer = fmt.Errorf("parse html file: %w", err)
227229
}
228230

229-
err = htmlTemplate.Execute(w, user)
231+
err = htmlTemplate.Execute(w, input)
230232
if err != nil {
231233
errServer = fmt.Errorf("render page: %w", err)
232234
}

internal/pkg/utils/utils.go

+8
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)