Skip to content

Commit

Permalink
multiple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Feb 27, 2024
1 parent d5e1f87 commit 54a741f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 2 additions & 0 deletions modules/web/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.17.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions modules/web/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -122,6 +124,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -163,6 +167,7 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
3 changes: 1 addition & 2 deletions modules/web/pkg/settings/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ func handleGetSettingsGlobalCanI(c *gin.Context) {
}

func handleGetSettingGlobal(c *gin.Context) {
k8sClient := client.InClusterClient()
c.JSON(http.StatusOK, manager.GetGlobalSettings(k8sClient))
c.JSON(http.StatusOK, manager.GetGlobalSettings(client.InClusterClient()))
}

func handleSettingsGlobalSave(c *gin.Context) {
Expand Down
6 changes: 3 additions & 3 deletions modules/web/pkg/settings/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewSettingsManager() SettingsManagerI {
// load config map data into settings manager and return true if new settings are different.
func (sm *SettingsManager) load(client kubernetes.Interface) (changed bool) {
configMap, err := client.CoreV1().ConfigMaps(args.Namespace()).
Get(context.TODO(), args.SettingsConfigMapName(), metav1.GetOptions{})
Get(context.Background(), args.SettingsConfigMapName(), metav1.GetOptions{})
if err != nil {
log.Printf("Cannot find settings config map: %s", err.Error())
err = sm.restoreConfigMap(client)
Expand Down Expand Up @@ -130,7 +130,7 @@ func (sm *SettingsManager) restoreConfigMap(client kubernetes.Interface) error {
}

restoredConfigMap, err := client.CoreV1().ConfigMaps(args.Namespace()).
Create(context.TODO(), configMap, metav1.CreateOptions{})
Create(context.Background(), configMap, metav1.CreateOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (sm *SettingsManager) saveSettings(client kubernetes.Interface) error {
}

_, err = client.CoreV1().ConfigMaps(args.Namespace()).
Patch(context.TODO(), args.SettingsConfigMapName(), types.MergePatchType, marshal, metav1.PatchOptions{})
Patch(context.Background(), args.SettingsConfigMapName(), types.MergePatchType, marshal, metav1.PatchOptions{})
return err
}

Expand Down
33 changes: 17 additions & 16 deletions modules/web/pkg/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,37 @@ import (
"encoding/json"

"dario.cat/mergo"
"github.com/samber/lo"
)

var defaultSettings = Settings{
ClusterName: "",
ItemsPerPage: 10,
LabelsLimit: 3,
LogsAutoRefreshTimeInterval: 5,
ResourceAutoRefreshTimeInterval: 5,
DisableAccessDeniedNotifications: false,
DefaultNamespace: "default",
ClusterName: lo.ToPtr(""),
ItemsPerPage: lo.ToPtr(10),
LabelsLimit: lo.ToPtr(3),
LogsAutoRefreshTimeInterval: lo.ToPtr(5),
ResourceAutoRefreshTimeInterval: lo.ToPtr(5),
DisableAccessDeniedNotifications: lo.ToPtr(false),
DefaultNamespace: lo.ToPtr("default"),
NamespaceFallbackList: []string{"default"},
}

type Settings struct {
ClusterName string `json:"clusterName"`
ItemsPerPage int `json:"itemsPerPage"`
LabelsLimit int `json:"labelsLimit"`
LogsAutoRefreshTimeInterval int `json:"logsAutoRefreshTimeInterval"`
ResourceAutoRefreshTimeInterval int `json:"resourceAutoRefreshTimeInterval"`
DisableAccessDeniedNotifications bool `json:"disableAccessDeniedNotifications"`
DefaultNamespace string `json:"defaultNamespace"`
NamespaceFallbackList []string `json:"namespaceFallbackList"`
ClusterName *string `json:"clusterName,omitempty"`
ItemsPerPage *int `json:"itemsPerPage,omitempty"`
LabelsLimit *int `json:"labelsLimit,omitempty"`
LogsAutoRefreshTimeInterval *int `json:"logsAutoRefreshTimeInterval,omitempty"`
ResourceAutoRefreshTimeInterval *int `json:"resourceAutoRefreshTimeInterval,omitempty"`
DisableAccessDeniedNotifications *bool `json:"disableAccessDeniedNotifications,omitempty"`
DefaultNamespace *string `json:"defaultNamespace,omitempty"`
NamespaceFallbackList []string `json:"namespaceFallbackList,omitempty"`
}

func (s *Settings) Default() *Settings {
if s == nil {
return &defaultSettings
}

_ = mergo.Merge(&s, defaultSettings)
_ = mergo.Merge(s, defaultSettings)

return s
}
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/common/services/global/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AuthInterceptor implements HttpInterceptor {
const token = this.cookies_.get(this.appConfig_.authTokenCookieName);
// Filter requests made to our backend starting with 'api/v1' and append request header
// with token stored in a cookie.
if (req.url.startsWith('api/v1') && !!token) {
if ((req.url.startsWith('api/v1') || req.url.startsWith('settings')) && !!token) {
const authReq = req.clone({
headers: req.headers.set(this.appConfig_.authTokenHeaderName, `Bearer ${token}`),
});
Expand Down

0 comments on commit 54a741f

Please sign in to comment.