Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROD][KAIZEN-0] migrate to Google Artifact Registry #385

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ concurrency:
cancel-in-progress: true

env:
IMAGE: ghcr.io/${{ github.repository }}/internarbeidsflatedecorator:${{ github.sha }}
CI: true
TZ: Europe/Oslo

Expand Down Expand Up @@ -35,47 +34,56 @@ jobs:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
id-token: write
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
steps:
- uses: actions/checkout@v3
- name: Publish Docker image
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker build --tag ${IMAGE} .
docker login ghcr.io -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN}
docker push ${IMAGE}
uses: nais/docker-build-push@v0
id: docker-build-push
with:
team: personoversikt
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}

deploy-qa:
name: Deploy to preprod
needs: build-and-push
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
strategy:
matrix:
q_env: [q0, q1]
steps:
- uses: actions/checkout@v3
- uses: nais/deploy/actions/deploy@v1
- uses: nais/deploy/actions/deploy@v2
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
PRINT_PAYLOAD: true
CLUSTER: dev-fss
RESOURCE: .nais/qa-template.yaml
VAR: q_env=${{matrix.q_env}}
VAR: q_env=${{matrix.q_env}},image=${{ needs.build-and-push.outputs.image }}

deploy-prod:
name: Deploy to prod
needs: build-and-push
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: nais/deploy/actions/deploy@v1
- uses: nais/deploy/actions/deploy@v2
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
PRINT_PAYLOAD: true
CLUSTER: prod-fss
RESOURCE: .nais/prod.yaml
VAR: image=${{ needs.build-and-push.outputs.image }}

deploy-gh-pages:
name: Deploy til gh-pages
Expand Down
5 changes: 1 addition & 4 deletions src/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useOnMount } from './hooks/use-on-mount';
import { useOnChanged } from './hooks/use-on-changed';
import { getContextvalueValue, isContextvalueControlled, RESET_VALUE } from './redux/utils';
import { DecoratorHotkeysProvider } from './components/hurtigtaster/hurtigtaster';
import FeatureToggleProvider from './featureToggle/FeatureToggleProvider';

function Application(props: ApplicationProps) {
const dispatch = useDispatch<Dispatch<SagaActions>>();
Expand Down Expand Up @@ -81,9 +80,7 @@ class ErrorHandler extends React.Component<ApplicationProps> {
render() {
return (
<Provider store={store}>
<FeatureToggleProvider key={this.props.accessToken}>
<Application {...this.props} />
</FeatureToggleProvider>
<Application {...this.props} />
</Provider>
);
}
Expand Down
35 changes: 10 additions & 25 deletions src/components/lenker.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, {useEffect} from 'react';
import React, { useEffect } from 'react';
import {
finnMiljoStreng,
finnNaisInternNavMiljoStreng,
finnNaisMiljoStreng,
hentMiljoFraUrl
} from '../utils/url-utils';
import {WrappedState} from "../hooks/use-wrapped-state";
import {useInitializedState} from "../hooks/use-initialized-state";
import {useEnhetContextvalueState, useFnrContextvalueState} from "../hooks/use-contextvalue-state";
import {Hotkey, ProxyConfig} from "../domain";
import {lagModiacontextholderUrl} from "../redux/api";
import {useDecoratorHotkeys} from "./hurtigtaster/hurtigtaster";
import { WrappedState } from "../hooks/use-wrapped-state";
import { useInitializedState } from "../hooks/use-initialized-state";
import { useEnhetContextvalueState, useFnrContextvalueState } from "../hooks/use-contextvalue-state";
import { Hotkey, ProxyConfig } from "../domain";
import { lagModiacontextholderUrl } from "../redux/api";
import { useDecoratorHotkeys } from "./hurtigtaster/hurtigtaster";
import './lenker.css';
import { FeatureToggles } from '../featureToggle/FeatureToggles';
import { useFeatureToggle } from '../featureToggle/FeatureToggleProvider';

function Lenke(props: { href: string; children: string; target?: string; }) {
/* eslint-disable jsx-a11y/anchor-has-content */
Expand Down Expand Up @@ -57,10 +55,7 @@ const pesysUrl = (fnr: string, path: string) => (fnr ? pesysDomain(path) : pesys
export const gosysUrl = (fnr: string, path: string) => fnr ? gosysDomain(path) : gosysDomain('/gosys/');
const fpsakUrl = `https://fpsak${finnNaisInternNavMiljoStreng()}`
const foreldrePengerUrl = (aktoerId: string) => aktoerId ? `${fpsakUrl}/aktoer/${aktoerId}` : `${fpsakUrl}/`;
function arbeidssokerregistreringURL(fnr: string, enhet: string) {
const queryParams = `?${fnr ? `fnr=${fnr}` : ''}${fnr && enhet ? '&' : ''}${enhet ? `enhetId=${enhet}` : ''}`;
return `https://arbeidssokerregistrering${finnNaisInternNavMiljoStreng()}${queryParams}`;
}

const inst2 = () => `https://inst2-web${finnNaisMiljoStreng(true)}/`;
function k9Url(aktorId: string): string {
const miljo = hentMiljoFraUrl();
Expand Down Expand Up @@ -106,28 +101,18 @@ interface Props {
proxyConfig: ProxyConfig;
}

const useArbeidssokerRegistreringUrl = (fnr: string, enhet: string) => {
const isOn = useFeatureToggle(FeatureToggles.NY_ARBEIDSSOKER_REGISTRERING_URL)
if (isOn) {
return `https://arbeidssokerregistrering-for-veileder${finnNaisInternNavMiljoStreng()}/`
}
return arbeidssokerregistreringURL(fnr, enhet)
}

function Lenker(props: Props) {
const fnr = useFnrContextvalueState().withDefault('');
const enhet = useEnhetContextvalueState().withDefault('');
const aktorId: string = useInitializedState((state) => state.data.aktorId)
.map((resp) => resp.aktorId)
.withDefault('');

const {register} = useDecoratorHotkeys();
const { register } = useDecoratorHotkeys();
useEffect(() => {
lagHotkeys(fnr, aktorId).forEach(register);
}, [register, fnr, aktorId])

const arbeidssokerregistreringURL = useArbeidssokerRegistreringUrl(fnr, enhet)

if (!props.apen.value) {
return null;
}
Expand Down Expand Up @@ -178,7 +163,7 @@ function Lenker(props: Props) {
<Lenke href={`https://veilarbpersonflate${finnNaisInternNavMiljoStreng()}/${fnr ? fnr : ''}?enhet=${enhet}`}>
Aktivitetsplan
</Lenke>
<Lenke href={arbeidssokerregistreringURL}>
<Lenke href={`https://arbeidssokerregistrering-for-veileder${finnNaisInternNavMiljoStreng()}/`}>
Registrer person
</Lenke>
<Lenke href={`https://tiltaksgjennomforing${finnNaisInternNavMiljoStreng()}/tiltaksgjennomforing`}>
Expand Down
39 changes: 39 additions & 0 deletions src/featureToggle/FeatureToggleManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { FeatureTogglesResponse, hentFeatureToggles } from '../redux/api';
import { FeatureToggles } from './FeatureToggles';


const TEN_SECONDS = 10000

class FeatureToggleManager {
private lastFetch?: number
private toggles: FeatureTogglesResponse

constructor() {
this.toggles = this.defaultToggles()
}

private defaultToggles = (): FeatureTogglesResponse => {
return {
'modiacontextholder.ikke-fnr-i-path': false
};
};

private getToggles = async () => {
const res = await hentFeatureToggles()
if (res.data) {
this.toggles = res.data
this.lastFetch = Date.now()
}
}

private shouldFetchToggles = (): boolean => !this.lastFetch || this.lastFetch < Date.now() - TEN_SECONDS

getToggle = async (toggleId: FeatureToggles): Promise<boolean> => {
if (this.shouldFetchToggles()) {
await this.getToggles()
}
return !!this.toggles[toggleId]
}
}

export default new FeatureToggleManager()
41 changes: 0 additions & 41 deletions src/featureToggle/FeatureToggleProvider.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/featureToggle/FeatureToggles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum FeatureToggles {
NY_ARBEIDSSOKER_REGISTRERING_URL = 'modiacontextholder.ny-arbeidssoker-registrering-url'
IKKE_FNR_I_PATH = 'modiacontextholder.ikke-fnr-i-path'
}
2 changes: 1 addition & 1 deletion src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mock.get('/modiacontextholder/api/decorator/aktor/:fnr', (req, res, ctx) => {

mock.get('/modiacontextholder/api/featuretoggle', (req, res, ctx) => {
const response: FeatureTogglesResponse = {
'modiacontextholder.ny-arbeidssoker-registrering-url': true
'modiacontextholder.ikke-fnr-i-path': false
};
return res(ctx.status(200), ctx.statusText('Ok'), ctx.json(response));
});
Expand Down
27 changes: 22 additions & 5 deletions src/redux/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AktivBruker, AktivEnhet, AktorIdResponse, Saksbehandler } from '../inte
import failureConfig from './../mock/mock-error-config';
import { ProxyConfig } from '../domain';
import { FeatureToggles } from '../featureToggle/FeatureToggles';
import FeatureToggleManager from '../featureToggle/FeatureToggleManager';

export enum ContextApiType {
NY_AKTIV_ENHET = 'NY_AKTIV_ENHET',
Expand Down Expand Up @@ -52,15 +53,18 @@ export function lagModiacontextholderUrl(proxyConfig: ProxyConfig = false): stri
}
function lagUrls(proxyConfig: ProxyConfig) {
const modiacontextholderUrl = lagModiacontextholderUrl(proxyConfig);
return {
const config = {
aktivEnhetUrl: `${modiacontextholderUrl}/api/context/aktivenhet`,
aktivBrukerUrl: `${modiacontextholderUrl}/api/context/aktivbruker`,
contextUrl: `${modiacontextholderUrl}/api/context`,
saksbehandlerUrl: `${modiacontextholderUrl}/api/decorator`,
featureTogglesUrl: `${modiacontextholderUrl}/api/featuretoggle`,
aktorIdUrl: (fnr: string) => `${modiacontextholderUrl}/api/decorator/aktor/${fnr}`
aktorIdUrl: (fnr: string) => `${modiacontextholderUrl}/api/decorator/aktor/${fnr}`,
modiacontextholderUrl
};
return config;
}

export let urls = lagUrls(false);

export type ResponseError = { data: undefined; error: string };
Expand Down Expand Up @@ -103,7 +107,11 @@ export async function getJson<T>(info: RequestInfo, init?: RequestInit): Promise
}
}

async function postJson<T>(url: string, body: T, options?: RequestInit): Promise<FetchResponse<T>> {
async function postJson<RESPONSE, REQUEST = any>(
url: string,
body: REQUEST,
options?: RequestInit
): Promise<FetchResponse<RESPONSE>> {
try {
const response: Response = await doFetch(url, {
...(options || {}),
Expand All @@ -115,7 +123,7 @@ async function postJson<T>(url: string, body: T, options?: RequestInit): Promise
const content = await response.text();
return { data: undefined, error: content };
}
return { data: body, error: undefined };
return { data: (await response.json()) as RESPONSE, error: undefined };
} catch (error) {
return { data: undefined, error };
}
Expand All @@ -137,13 +145,22 @@ async function deleteJson(url: string, options?: RequestInit): Promise<FetchResp
}
}

export function hentAktorId(fnr: string): Promise<FetchResponse<AktorIdResponse>> {
export async function hentAktorId(fnr: string): Promise<FetchResponse<AktorIdResponse>> {
const feilmelding = lagFnrFeilmelding(fnr);

if (feilmelding.isJust()) {
return Promise.reject('Ugyldig fødselsnummer, kan ikke hente aktørId');
}

const isOn = await FeatureToggleManager.getToggle(FeatureToggles.IKKE_FNR_I_PATH);

if (isOn) {
return postJson<AktorIdResponse, String>(
`${urls.modiacontextholderUrl}/api/v2/decorator/aktor/hent-fnr`,
fnr
);
}

return getJson<AktorIdResponse>(urls.aktorIdUrl(fnr));
}

Expand Down