-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-1488: Added unleash api token file (#996)
- Loading branch information
1 parent
a43940e
commit 019e628
Showing
23 changed files
with
214 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Deploy unleash api-tokens | ||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- '.github/workflows/unleash-apitokens.yaml' | ||
- '.nais/unleash/unleash-apitoken-dev.yaml' | ||
- '.nais/unleash/unleash-apitoken-prod.yaml' | ||
jobs: | ||
apply-apitoken-unleash: | ||
name: Apply ApiToken for Unleash to cluster | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Deploy to dev | ||
uses: nais/deploy/actions/deploy@v1 | ||
env: | ||
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | ||
CLUSTER: dev-gcp | ||
RESOURCE: .nais/unleash/unleash-apitoken-dev.yaml | ||
- name: Deploy to prod | ||
uses: nais/deploy/actions/deploy@v1 | ||
env: | ||
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | ||
CLUSTER: prod-gcp | ||
RESOURCE: .nais/unleash/unleash-apitoken-prod.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: unleash.nais.io/v1 | ||
kind: ApiToken | ||
metadata: | ||
name: syfomodiaperson | ||
namespace: teamsykefravr | ||
labels: | ||
team: teamsykefravr | ||
spec: | ||
unleashInstance: | ||
apiVersion: unleash.nais.io/v1 | ||
kind: RemoteUnleash | ||
name: teamsykefravr | ||
secretName: syfomodiaperson-unleash-api-token | ||
environment: development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: unleash.nais.io/v1 | ||
kind: ApiToken | ||
metadata: | ||
name: syfomodiaperson | ||
namespace: teamsykefravr | ||
labels: | ||
team: teamsykefravr | ||
spec: | ||
unleashInstance: | ||
apiVersion: unleash.nais.io/v1 | ||
kind: RemoteUnleash | ||
name: teamsykefravr | ||
secretName: syfomodiaperson-unleash-api-token | ||
environment: production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { UNLEASH_ROOT } from "@/apiConstants"; | ||
import { ToggleNames } from "@/data/unleash/unleash_types"; | ||
import express from "express"; | ||
|
||
export const mockUnleashEndpoint = (server: any) => { | ||
server.get( | ||
`${UNLEASH_ROOT}/toggles`, | ||
(req: express.Request, res: express.Response) => { | ||
res.setHeader("Content-Type", "application/json"); | ||
res.send(JSON.stringify(mockUnleashResponse)); | ||
} | ||
); | ||
}; | ||
|
||
export const mockUnleashResponse = Object.values(ToggleNames).reduce( | ||
(accumulator, toggleName) => { | ||
return { ...accumulator, [toggleName]: true }; | ||
}, | ||
{} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +0,0 @@ | ||
import unleashClient = require("unleash-client"); | ||
|
||
const { initialize, Strategy } = unleashClient; | ||
|
||
class ByDevEnhet extends Strategy { | ||
constructor() { | ||
super("byDevEnhet"); | ||
} | ||
|
||
isEnabled(parameters: any, context: any) { | ||
if (!context.valgtEnhet) { | ||
return false; | ||
} | ||
|
||
const valgtEnhetMatches = | ||
parameters.enheter.indexOf(context.valgtEnhet) !== -1; | ||
|
||
return valgtEnhetMatches && process.env.NAIS_CONTEXT === "dev"; | ||
} | ||
} | ||
|
||
class ByProdEnhet extends Strategy { | ||
constructor() { | ||
super("byProdEnhet"); | ||
} | ||
|
||
isEnabled(parameters: any, context: any) { | ||
if (!context.valgtEnhet) { | ||
return false; | ||
} | ||
|
||
const valgtEnhetMatches = | ||
parameters.enheter.indexOf(context.valgtEnhet) !== -1; | ||
|
||
return valgtEnhetMatches && process.env.NAIS_CONTEXT === "prod"; | ||
} | ||
} | ||
|
||
class ByUserId extends Strategy { | ||
constructor() { | ||
super("byUserId"); | ||
} | ||
|
||
isEnabled(parameters: any, context: any) { | ||
if (!context.user) { | ||
return false; | ||
} | ||
|
||
return parameters.user.indexOf(context.user) !== -1; | ||
} | ||
} | ||
|
||
class ByEnvironmentToggle extends Strategy { | ||
constructor() { | ||
super("byEnvironmentToggle"); | ||
} | ||
|
||
isEnabled(parameters: any) { | ||
return ( | ||
(parameters.dev === "true" && process.env.NAIS_CONTEXT === "dev") || | ||
(parameters.prod === "true" && process.env.NAIS_CONTEXT === "prod") | ||
); | ||
} | ||
} | ||
|
||
const unleash = initialize({ | ||
url: "https://unleash.nais.io/api/", | ||
appName: "syfomodiaperson", | ||
environment: process.env.NAIS_CONTEXT, | ||
strategies: [ | ||
new ByDevEnhet(), | ||
new ByUserId(), | ||
new ByProdEnhet(), | ||
new ByEnvironmentToggle(), | ||
], | ||
}); | ||
|
||
export const unleashToggles = (toggles: any, valgtEnhet: any, userId: any) => { | ||
return { | ||
"syfo.dialogmote.virksomhetinput": unleash.isEnabled( | ||
"syfo.dialogmote.virksomhetinput", | ||
{ | ||
valgtEnhet: valgtEnhet, | ||
user: userId, | ||
} | ||
), | ||
"syfo.motebehov.tilbakemelding": unleash.isEnabled( | ||
"syfo.motebehov.tilbakemelding", | ||
{ | ||
valgtEnhet: valgtEnhet, | ||
user: userId, | ||
} | ||
), | ||
"syfo.behandlerdialog.meldingfranav": unleash.isEnabled( | ||
"syfo.behandlerdialog.meldingfranav", | ||
{ | ||
valgtEnhet: valgtEnhet, | ||
user: userId, | ||
} | ||
), | ||
}; | ||
}; | ||
Oops, something went wrong.