Skip to content

Commit

Permalink
Merge branch 'main' into soknader-fra-innsending
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbjoern committed Jan 26, 2024
2 parents 65aaeef + 874c83d commit f0618a7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .nais/dev-gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SOKNAD_API_AUDIENCE="dev-gcp:aap:soknad-api"
INNSENDING_URL="http://innsending"
INNSENDING_AUDIENCE="dev-gcp:aap:innsending"

OPPSLAG_URL="http://oppslag"
OPPSLAG_AUDIENCE="dev-gcp:aap:oppslag"

NEXT_PUBLIC_NY_INNSENDING="enabled"

DOKUMENTER_URL="http://dokumenter"
Expand All @@ -18,4 +21,4 @@ OPPSLAG_AUDIENCE="dev-gcp:aap:oppslag"
ASSET_PREFIX="https://cdn.nav.no/aap/aap-innsyn"
WONDERWALL_REDIRECT_DESTINATION="/oauth2/login?redirect=/aap/mine-aap"

NEXT_PUBLIC_FARO_URL="https://telemetry.ekstern.dev.nav.no/collect"
NEXT_PUBLIC_FARO_URL="https://telemetry.ekstern.dev.nav.no/collect"
5 changes: 4 additions & 1 deletion .nais/prod-gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ NEXT_PUBLIC_ENVIRONMENT="prod"
SOKNAD_API_URL="http://soknad-api"
SOKNAD_API_AUDIENCE="prod-gcp:aap:soknad-api"

OPPSLAG_URL="http://oppslag"
OPPSLAG_AUDIENCE="prod-gcp:aap:oppslag"

DOKUMENTER_URL="http://dokumenter"
DOKUMENTER_AUDIENCE="prod-gcp:aap:dokumenter"

ASSET_PREFIX="https://cdn.nav.no/aap/aap-innsyn"
WONDERWALL_REDIRECT_DESTINATION="/oauth2/login?redirect=/aap/mine-aap"

NEXT_PUBLIC_FARO_URL="https://telemetry.nav.no/collect"
NEXT_PUBLIC_FARO_URL="https://telemetry.nav.no/collect"
10 changes: 6 additions & 4 deletions lib/api/tokenXProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ export const tokenXProxy = async (
req: NextApiRequest,
res: NextApiResponse,
path: string,
prometheusPath: string
prometheusPath: string,
hostname: 'oppslag' | 'soknad-api',
audience: string
) => {
const accessToken = getAccessTokenFromRequest(req)?.substring('Bearer '.length)!;
let tokenxToken;
try {
tokenxToken = await getTokenX(accessToken, process.env.SOKNAD_API_AUDIENCE!);
tokenxToken = await getTokenX(accessToken, audience);
} catch (err: any) {
logger.error({ msg: 'getTokenXError', error: err });
}
const stopTimer = metrics.backendApiDurationHistogram.startTimer({ path: prometheusPath });
const result = await proxyApiRouteRequest({
req,
res,
hostname: 'soknad-api',
path: path,
hostname,
path,
bearerToken: tokenxToken,
https: false,
});
Expand Down
4 changes: 3 additions & 1 deletion pages/api/dokument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const handler = beskyttetApi(async (req, res) => {
/* @ts-ignore: TODO: Følge opp med tokenXproxy repo for å fikse type */
res,
`/oppslag/dokument/${journalpostId}/${dokumentId}`,
'/oppslag/dokument'
'/oppslag/dokument',
'soknad-api',
process.env.SOKNAD_API_AUDIENCE
);
});

Expand Down
34 changes: 34 additions & 0 deletions pages/api/nyeapi/dokument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getStringFromPossiblyArrayQuery } from '@navikt/aap-felles-utils-client';
import { beskyttetApi } from '@navikt/aap-felles-utils';
import { tokenXProxy } from 'lib/api/tokenXProxy';
import { randomUUID } from 'crypto';

const handler = beskyttetApi(async (req, res) => {
const journalpostId = getStringFromPossiblyArrayQuery(req.query.journalpostId);
const dokumentId = getStringFromPossiblyArrayQuery(req.query.dokumentId);
if (!journalpostId || !dokumentId) {
res.status(400).json({ error: 'journalpostId og dokumentId må være satt' });
}

const callid = randomUUID();
req.headers['Nav-CallId'] = callid;

return await tokenXProxy(
req,
/* @ts-ignore: TODO: Følge opp med tokenXproxy repo for å fikse type */
res,
`/oppslag/dokument/${journalpostId}/${dokumentId}`,
'/oppslag/dokument',
'oppslag',
process.env.OPPSLAG_AUDIENCE
);
});

export const config = {
api: {
responseLimit: '50mb',
bodyParser: false,
},
};

export default handler;
24 changes: 24 additions & 0 deletions pages/api/nyeapi/dokumenter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mockDokumenter } from 'lib/mock/mockDokumenter';
import { logger, isMock, tokenXApiProxy, beskyttetApi, getAccessTokenFromRequest } from '@navikt/aap-felles-utils';
import metrics from 'lib/metrics';

const handler = beskyttetApi(async (req, res) => {
const accessToken = getAccessTokenFromRequest(req);
const dokumenter = await getDocuments(accessToken);
res.status(200).json(dokumenter);
});

export const getDocuments = async (accessToken?: string) => {
if (isMock()) return mockDokumenter;
return await tokenXApiProxy({
url: `${process.env.OPPSLAG_URL}/dokumenter`,
prometheusPath: '/oppslag/dokumenter',
method: 'GET',
audience: process.env.OPPSLAG_AUDIENCE!,
bearerToken: accessToken,
logger: logger,
metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter,
metricsTimer: metrics.backendApiDurationHistogram,
});
};
export default handler;

0 comments on commit f0618a7

Please sign in to comment.