Skip to content

Commit

Permalink
bruk tokenx på kall til arbeidsplassen
Browse files Browse the repository at this point in the history
  • Loading branch information
kenglxn committed Aug 30, 2023
1 parent e9ffa95 commit c3defa8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
3 changes: 3 additions & 0 deletions nais/dev-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ spec:
- host: arbeidsgiver.intern.dev.nav.no
- host: tiltak-proxy.dev-fss-pub.nais.io
- host: aareg-innsyn-arbeidsgiver-api.dev-fss-pub.nais.io
- host: arbeidsplassen.intern.dev.nav.no
rules:
- application: min-side-arbeidsgiver-api
- application: notifikasjon-bruker-api
Expand All @@ -62,3 +63,5 @@ spec:
cluster: dev-fss
- application: presenterte-kandidater-api
namespace: toi
- application: pam-stillingsregistrering-api
namespace: teampam
3 changes: 3 additions & 0 deletions nais/prod-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ spec:
- host: arbeidsgiver.nav.no
- host: tiltak-proxy.prod-fss-pub.nais.io
- host: aareg-innsyn-arbeidsgiver-api.prod-fss-pub.nais.io
- host: arbeidsplassen.nav.no
rules:
- application: min-side-arbeidsgiver-api
- application: notifikasjon-bruker-api
Expand All @@ -61,3 +62,5 @@ spec:
cluster: prod-fss
- application: presenterte-kandidater-api
namespace: toi
- application: pam-stillingsregistrering-api
namespace: teampam
12 changes: 6 additions & 6 deletions server/mock/pamMock.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export const mock = (app) => {
app.use(
'/min-side-arbeidsgiver/mock/arbeidsplassen.nav.no/stillingsregistrering-api/api/arbeidsgiver/:id',
(req, res) => res.sendStatus(200)
app.use('/min-side-arbeidsgiver/stillingsregistrering-api/api/arbeidsgiver/:id', (req, res) =>
res.sendStatus(200)
);
app.use(
'/min-side-arbeidsgiver/mock/arbeidsplassen.nav.no/stillingsregistrering-api/api/stillinger/numberByStatus',
'/min-side-arbeidsgiver/stillingsregistrering-api/api/stillinger/numberByStatus',
(req, res) => {
res.send({
TIL_GODKJENNING: 17,
Expand All @@ -15,5 +14,6 @@ export const mock = (app) => {
AVVIST: 0,
PUBLISERT: 5,
});
});
}
}
);
};
22 changes: 22 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ const main = async () => {
})
);

app.use(
'/min-side-arbeidsgiver/stillingsregistrering-api',
tokenXMiddleware({
log: log,
audience: {
dev: 'dev-gcp:teampam:pam-stillingsregistrering-api',
prod: 'prod-gcp:teampam:pam-stillingsregistrering-api',
}[MILJO],
}),
createProxyMiddleware({
...proxyOptions,
pathRewrite: {
'^/min-side-arbeidsgiver/stillingsregistrering-api':
'/stillingsregistrering-api',
},
target: {
dev: 'https://arbeidsplassen.intern.dev.nav.no',
prod: 'https://arbeidsplassen.nav.no',
}[MILJO],
})
);

app.use(
'/min-side-arbeidsgiver/api',
tokenXMiddleware({
Expand Down
33 changes: 8 additions & 25 deletions src/api/pamApi.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import {gittMiljo} from "../utils/environment";


const pamSettBedriftURL = gittMiljo({
prod: (orgnr: string) =>
`https://arbeidsplassen.nav.no/stillingsregistrering-api/api/arbeidsgiver/${orgnr}`,
dev: (orgnr: string) =>
`https://arbeidsplassen.intern.dev.nav.no/stillingsregistrering-api/api/arbeidsgiver/${orgnr}`,
other: (orgnr: string) =>
`/min-side-arbeidsgiver/mock/arbeidsplassen.nav.no/stillingsregistrering-api/api/arbeidsgiver/${orgnr}`,
});
export const settBedriftIPam = (orgnr: string): Promise<unknown> =>
fetch(pamSettBedriftURL(orgnr), {
method: 'GET',
credentials: 'include',
fetch(`/min-side-arbeidsgiver/stillingsregistrering-api/api/arbeidsgiver/${orgnr}`, {
method: 'POST',
});


interface PamStatusAnnonser {
TIL_GODKJENNING: number;
GODKJENT: number;
Expand All @@ -26,20 +13,16 @@ interface PamStatusAnnonser {
PUBLISERT: number;
}

const pamHentStillingsannonserURL = gittMiljo({
prod: 'https://arbeidsplassen.nav.no/stillingsregistrering-api/api/stillinger/numberByStatus',
dev: 'https://arbeidsplassen.intern.dev.nav.no/stillingsregistrering-api/api/stillinger/numberByStatus',
other: '/min-side-arbeidsgiver/mock/arbeidsplassen.nav.no/stillingsregistrering-api/api/stillinger/numberByStatus',
});
export const hentAntallannonser = async (): Promise<number> => {
const respons = await fetch(pamHentStillingsannonserURL, {
method: 'GET',
credentials: 'include',
});
const respons = await fetch(
'/min-side-arbeidsgiver/stillingsregistrering-api/api/stillinger/numberByStatus',
{
method: 'GET',
}
);
if (respons.ok) {
const responsBody: PamStatusAnnonser = await respons.json();
return responsBody.PUBLISERT;
}
return 0;
};

0 comments on commit c3defa8

Please sign in to comment.