Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Ikke send telemetri i ekstern dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgfa committed Aug 7, 2023
1 parent b2e93f5 commit 6ef41cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 0 additions & 2 deletions nais/dev-gcp-ekstern.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ spec:
value: https://arbeidsgiver.ekstern.dev.nav.no/min-side-arbeidsgiver
- name: FOREBYGGE_FRAVAR_URL
value: https://arbeidsgiver.ekstern.dev.nav.no/forebygge-fravar
- name: GRAFANA_AGENT_COLLECTOR_URL
value: null
accessPolicy:
outbound:
external:
Expand Down
28 changes: 24 additions & 4 deletions server/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z, ZodEffects, ZodOptional, ZodString } from 'zod';
import { logger } from './backend-logger.js';

export const MILJØ = {
Expand All @@ -12,6 +12,7 @@ export type MILJØ = (typeof MILJØ)[keyof typeof MILJØ];
const isMiljø = (value: string): value is MILJØ => {
return (Object.values(MILJØ) as string[]).includes(value);
};

function getCurrentEnvironment() {
const { MILJO = 'local' } = process.env;
return MILJO;
Expand All @@ -20,15 +21,34 @@ function getCurrentEnvironment() {
function errorMap(issue: z.ZodIssueOptionalMessage, ctx: z.ErrorMapCtx): { message: string } {
return { message: `Kunne ikke parse miljøvariabler. [${ctx.defaultError}]` };
}

export function getFrontendEnvs() {
try {
return z
const miljø = z
.object({
MILJO: z.string().refine(isMiljø),
MIN_SIDE_ARBEIDSGIVER_URL: z.string().url(),
GRAFANA_AGENT_COLLECTOR_URL: z.string().url(),
})
.parse(process.env, { errorMap: errorMap });

let shape: {
GRAFANA_AGENT_COLLECTOR_URL: ZodString | ZodOptional<ZodString>;
MIN_SIDE_ARBEIDSGIVER_URL: ZodString;
MILJO: ZodEffects<ZodString>;
} = {
MILJO: z.string().refine(isMiljø),
MIN_SIDE_ARBEIDSGIVER_URL: z.string().url(),
GRAFANA_AGENT_COLLECTOR_URL: z.string().url(),
};

if (miljø.MILJO === MILJØ.DEV_EKSTERN) {
shape = {
MILJO: z.string().refine(isMiljø),
MIN_SIDE_ARBEIDSGIVER_URL: z.string().url(),
GRAFANA_AGENT_COLLECTOR_URL: z.string().url().optional(),
};
}

return z.object(shape).parse(process.env, { errorMap: errorMap });
} catch (err) {
if (process.env.NODE_ENV === 'development') {
return {
Expand Down

0 comments on commit 6ef41cb

Please sign in to comment.