From 05674f7a74dc3d128f05e909b86c1bff0e79aa79 Mon Sep 17 00:00:00 2001 From: Sven Urbanski Date: Thu, 15 Aug 2024 18:39:03 +0200 Subject: [PATCH 1/9] feat(db): handle group locks (#1880) Group locks do not really need to be handled in the manifest-export, because a group lock is just a list of locks for multiple envs, meaning the cd-service creates separate events for each one. Ref: SRX-KNBOC7 --- .../pkg/cmd/server.go | 6 ++ .../pkg/repository/transformer.go | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/services/manifest-repo-export-service/pkg/cmd/server.go b/services/manifest-repo-export-service/pkg/cmd/server.go index 0aa61283c..1755b6ab0 100755 --- a/services/manifest-repo-export-service/pkg/cmd/server.go +++ b/services/manifest-repo-export-service/pkg/cmd/server.go @@ -505,6 +505,12 @@ func getTransformer(ctx context.Context, eslEventType db.EventType) (repository. case db.EvtCreateUndeployApplicationVersion: //exhaustruct:ignore return &repository.CreateUndeployApplicationVersion{}, nil + case db.EvtCreateEnvironmentGroupLock: + //exhaustruct:ignore + return &repository.CreateEnvironmentGroupLock{}, nil + case db.EvtDeleteEnvironmentGroupLock: + //exhaustruct:ignore + return &repository.DeleteEnvironmentGroupLock{}, nil case db.EvtUndeployApplication: //exhaustruct:ignore return &repository.UndeployApplication{}, nil diff --git a/services/manifest-repo-export-service/pkg/repository/transformer.go b/services/manifest-repo-export-service/pkg/repository/transformer.go index 0e84cdbd9..4d6cb2e86 100644 --- a/services/manifest-repo-export-service/pkg/repository/transformer.go +++ b/services/manifest-repo-export-service/pkg/repository/transformer.go @@ -1837,3 +1837,59 @@ func (u *UndeployApplication) Transform( } return fmt.Sprintf("application '%v' was deleted successfully", u.Application), nil } + +type CreateEnvironmentGroupLock struct { + Authentication `json:"-"` + TransformerMetadata `json:"metadata"` + TransformerEslVersion db.TransformerID `json:"-"` // Tags the transformer with EventSourcingLight eslVersion +} + +func (c *CreateEnvironmentGroupLock) GetEslVersion() db.TransformerID { + return c.TransformerEslVersion +} + +func (c *CreateEnvironmentGroupLock) SetEslVersion(eslVersion db.TransformerID) { + c.TransformerEslVersion = eslVersion +} + +func (c *CreateEnvironmentGroupLock) GetDBEventType() db.EventType { + return db.EvtCreateEnvironmentGroupLock +} + +func (c *CreateEnvironmentGroupLock) Transform( + _ context.Context, + _ *State, + _ TransformerContext, + _ *sql.Tx, +) (string, error) { + // group locks are handled on the cd-service, and split into environment locks + return "empty commit for group lock creation", nil +} + +type DeleteEnvironmentGroupLock struct { + Authentication `json:"-"` + TransformerMetadata `json:"metadata"` + TransformerEslVersion db.TransformerID `json:"-"` // Tags the transformer with EventSourcingLight eslVersion +} + +func (c *DeleteEnvironmentGroupLock) GetEslVersion() db.TransformerID { + return c.TransformerEslVersion +} + +func (c *DeleteEnvironmentGroupLock) SetEslVersion(eslVersion db.TransformerID) { + c.TransformerEslVersion = eslVersion +} + +func (c *DeleteEnvironmentGroupLock) GetDBEventType() db.EventType { + return db.EvtDeleteEnvironmentGroupLock +} + +func (c *DeleteEnvironmentGroupLock) Transform( + _ context.Context, + _ *State, + _ TransformerContext, + _ *sql.Tx, +) (string, error) { + // group locks are handled on the cd-service, and split into environment locks + return "empty commit for group lock deletion", nil +} From dd680edab3a61117b922b3390c86c3d5290ddf42 Mon Sep 17 00:00:00 2001 From: Miguel Crespo <162333021+miguel-crespo-fdc@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:55:44 +0100 Subject: [PATCH 2/9] fix: team locks overview (#1876) Upon overview recalculation, the team locks were being added to the app locks. We fix this. Ref: SRX-QMIIYB --- pkg/db/overview.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/db/overview.go b/pkg/db/overview.go index ecb289b97..3749eadb2 100644 --- a/pkg/db/overview.go +++ b/pkg/db/overview.go @@ -44,7 +44,7 @@ func (h *DBHandler) UpdateOverviewTeamLock(ctx context.Context, transaction *sql if app.Locks == nil { app.Locks = map[string]*api.Lock{} } - app.Locks[teamLock.LockID] = &api.Lock{ + app.TeamLocks[teamLock.LockID] = &api.Lock{ Message: teamLock.Metadata.Message, LockId: teamLock.LockID, CreatedAt: timestamppb.New(teamLock.Created), @@ -54,7 +54,7 @@ func (h *DBHandler) UpdateOverviewTeamLock(ctx context.Context, transaction *sql }, } if teamLock.Deleted { - delete(app.Locks, teamLock.LockID) + delete(app.TeamLocks, teamLock.LockID) } } err = h.WriteOverviewCache(ctx, transaction, latestOverview) From 23ef039a69b51330e9a4f1a7c73ddf80fd976956 Mon Sep 17 00:00:00 2001 From: Sven Urbanski Date: Fri, 16 Aug 2024 09:56:42 +0200 Subject: [PATCH 3/9] chore: renaming pnpm scripts to be consistent (#1878) now we have eslint-check/eslint-fix and scss-check/scss-lintlint Ref: SRX-KNBOC7 --- services/frontend-service/Earthfile | 4 ++-- services/frontend-service/Makefile | 6 +++--- services/frontend-service/package.json | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/frontend-service/Earthfile b/services/frontend-service/Earthfile index ae76f3d43..32aa57833 100644 --- a/services/frontend-service/Earthfile +++ b/services/frontend-service/Earthfile @@ -67,8 +67,8 @@ node-modules: lint-ui: FROM +deps-ui - RUN pnpm eslint - RUN pnpm lint-scss + RUN pnpm eslint-check + RUN pnpm scss-check unit-test-ui: FROM +deps-ui diff --git a/services/frontend-service/Makefile b/services/frontend-service/Makefile index ec5488d11..bcd73aeef 100644 --- a/services/frontend-service/Makefile +++ b/services/frontend-service/Makefile @@ -95,12 +95,12 @@ test-go: $(ALL_GO_FILES) | proto $(GO) test $(GO_TEST_ARGS) ./... test-ts: src/api/api.ts - pnpm eslint + pnpm eslint-check # The extra '--' was added because of pnpm, Usage: pnpm test [-- ...] pnpm test -- --watchAll=false -lint-scss: deps - pnpm lint-scss +scss-check: deps + pnpm scss-check docker: $(EARTHLY) +docker --registry=$(IMAGE_REGISTRY) --tag=$(VERSION) diff --git a/services/frontend-service/package.json b/services/frontend-service/package.json index ea592a0df..225856dfb 100644 --- a/services/frontend-service/package.json +++ b/services/frontend-service/package.json @@ -37,11 +37,11 @@ "build": "GENERATE_SOURCEMAP=false react-scripts build", "test": "TC=Europe/Berlin react-scripts test --color", "start": "WATCHPACK_POLLING=true CHOKIDAR_USEPOLLING=true react-scripts start", - "eslint": "eslint --cache --cache-location 'misc/.eslintcache' --ext .ts,.tsx src/", + "eslint-check": "eslint --cache --cache-location 'misc/.eslintcache' --ext .ts,.tsx src/", "eslint-fix": "eslint --fix --cache --cache-location 'misc/.eslintcache' --ext .ts,.tsx src/", "circular-check": "madge -c --extensions ts,tsx --ts-config tsconfig.json --no-spinner src/", - "lint-scss": "prettier -c --parser scss 'src/**/*.scss'", - "format-scss": "prettier --write --parser scss 'src/**/*.scss'" + "scss-check": "prettier -c --parser scss 'src/**/*.scss'", + "scss-fix": "prettier --write --parser scss 'src/**/*.scss'" }, "devDependencies": { "@babel/core": "7.25.2", From 194ab67bb464fa431da766276ad9e3324ddc44b9 Mon Sep 17 00:00:00 2001 From: Ahmed Nour <125875466+ahmed-nour-fdc@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:23:04 +0200 Subject: [PATCH 4/9] feat: Display logged-in user (#1879) * Display a welcome message for the logged-in user. * If the cookie `kuberpult.oauth` is not set, nothing is displayed. Ref: SRX-Y5QM5R --- .../components/TopAppBar/TopAppBar.test.tsx | 59 +++++++++++++++++++ .../src/ui/components/TopAppBar/TopAppBar.tsx | 18 +++++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 services/frontend-service/src/ui/components/TopAppBar/TopAppBar.test.tsx diff --git a/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.test.tsx b/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.test.tsx new file mode 100644 index 000000000..84554e98e --- /dev/null +++ b/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.test.tsx @@ -0,0 +1,59 @@ +/*This file is part of kuberpult. + +Kuberpult is free software: you can redistribute it and/or modify +it under the terms of the Expat(MIT) License as published by +the Free Software Foundation. + +Kuberpult is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +MIT License for more details. + +You should have received a copy of the MIT License +along with kuberpult. If not, see . + +Copyright freiheit.com*/ +import React from 'react'; +import { render } from '@testing-library/react'; +import { TopAppBar } from './TopAppBar'; +import { MemoryRouter } from 'react-router-dom'; + +describe('TopAppBar', () => { + beforeEach(() => { + document.cookie = ''; + }); + interface dataEnvT { + name: string; + cookie: string; + welcomeMessage: string; + } + const sampleEnvData: dataEnvT[] = [ + { + name: 'no cookie', + cookie: '', + welcomeMessage: '', + }, + { + name: 'cookie defined with no user email', + cookie: 'kuberpult.oauth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MjA2MjE5OTc3Nzd9.p3ApN5elnhhRhrh7DCOF-9suPIXYC36Nycf0nHfxuf8', + welcomeMessage: 'Welcome, Guest!', + }, + { + name: 'cookie defined with a user email', + cookie: 'kuberpult.oauth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJlbWFpbCI6InRlc3QudGVzdEB0ZXN0LmNvbSJ9.wgoizCsQb6AuFsbINF5OHfmfipdj5MuEUwJjZaqsBOg', + welcomeMessage: 'Welcome, test.test@test.com!', + }, + ]; + describe.each(sampleEnvData)(`welcomeMessage`, (tc) => { + it(tc.name, () => { + document.cookie = tc.cookie; + const { container } = render( + + + + ); + const message = container.getElementsByClassName('welcome-message'); + tc.cookie === '' ? expect(message).toHaveLength(0) : expect(message[0].textContent).toBe(tc.welcomeMessage); + }); + }); +}); diff --git a/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.tsx b/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.tsx index 9a6ac41ad..8889e5573 100644 --- a/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.tsx +++ b/services/frontend-service/src/ui/components/TopAppBar/TopAppBar.tsx @@ -13,6 +13,7 @@ You should have received a copy of the MIT License along with kuberpult. If not, see . Copyright freiheit.com*/ +import { jwtDecode } from 'jwt-decode'; import { Textfield } from '../textfield'; import React, { useCallback } from 'react'; import { SideBar } from '../SideBar/SideBar'; @@ -47,6 +48,12 @@ export const TopAppBar: React.FC = (props) => { const teamsParam = (params.get('teams') || '').split(',').filter((val) => val !== ''); const version = useKuberpultVersion() || '2.6.0'; + const cookieValue = document.cookie + .split('; ') + .find((row) => row.startsWith('kuberpult.oauth=')) + ?.split('=')[1]; + const decodedToken: any = cookieValue ? jwtDecode(cookieValue) : undefined; + const loggedInUser = decodedToken?.email || 'Guest'; const hideWithoutWarningsValue = hideWithoutWarnings(params); const allWarnings: Warning[] = useAllWarnings(); @@ -114,7 +121,15 @@ export const TopAppBar: React.FC = (props) => { ) : (
); - + const renderedUser = cookieValue ? ( +
+ + Welcome, {loggedInUser}! + +
+ ) : ( +
+ ); return (
@@ -127,6 +142,7 @@ export const TopAppBar: React.FC = (props) => { {renderedTeamsFilter} {renderedWarningsFilter} {renderedWarnings} + {renderedUser}
Planned Actions