From 908896ea1637715fdb96336a986c9dcaf0d5ac2a Mon Sep 17 00:00:00 2001 From: greg pereira Date: Sun, 24 Nov 2024 12:53:51 -0800 Subject: [PATCH] linting Signed-off-by: greg pereira --- deploy/k8s/base/keycloak/README.md | 21 ++++++++++-- .../resources/instructlab-ui-client.yaml | 1 + .../k8s/base/keycloak/resources/keycloak.yaml | 1 + .../keycloak/resources/kustomization.yaml | 3 -- deploy/k8s/base/keycloak/resources/realm.yaml | 1 + deploy/k8s/base/keycloak/resources/user.yaml | 1 + src/app/api/auth/[...nextauth]/route.ts | 14 ++++---- src/app/login/keycloakicon.tsx | 33 +++++++++---------- src/components/Dashboard/index.tsx | 2 +- 9 files changed, 46 insertions(+), 31 deletions(-) diff --git a/deploy/k8s/base/keycloak/README.md b/deploy/k8s/base/keycloak/README.md index 35efa759..0c04dd12 100644 --- a/deploy/k8s/base/keycloak/README.md +++ b/deploy/k8s/base/keycloak/README.md @@ -18,8 +18,19 @@ oc get pods -n keycloak-system # keycloak-postgresql-5965b4dd55-22hsc 1/1 Running 0 11d # rhsso-operator-758844f657-s97k9 1/1 Running 0 32h -oc --kustomize apply resources/ -# This will create the Keycloak instance, KeycloakClient, KeycloakRealm, and a dummy user +cd resources/ + +oc create -f keycloak.yaml +# wait for keycloak instance to be initialized and in the `reconciling` stage with status `ready`, +# this may take up to a few minutes + +oc create -f realm.yaml +# wait for the keycloakRealm to be `reconciling` + +oc create -f instructlab-ui-client.yaml && oc create -f user.yaml +# These two are very fast, wait for them to also be in the `reconciling` stage + +# In total, this will create the Keycloak instance, KeycloakClient, KeycloakRealm, and a dummy user ``` ## Application setup @@ -32,6 +43,12 @@ To get these values you can do the following (this assumes no modification to th export KEYCLOAK_CLIENT_ID=$(kubectl get secret keycloak-client-secret-instructlab-ui -n keycloak-system -o yaml | yq .data.CLIENT_ID | base64 -d) export KEYCLOAK_CLIENT_SECRET=$(kubectl get secret keycloak-client-secret-instructlab-ui -n keycloak-system -o yaml | yq .data.CLIENT_SECRET | base64 -d) export KEYCLOAK_ISSUER=$(kubectl get keycloak keycloak -n keycloak-system -o jsonpath='{.status.externalURL}')/auth/realms/instructlab-ui + +echo "KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID}" >> .env +echo "KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET}" >> .env +echo "KEYCLOAK_ISSUER=${KEYCLOAK_ISSUER}" >> .env + +cat .env | tail -n 3 ``` Additionally, make sure the `IL_UI_DEPLOYMENT=dev` value is set in the `.env` file, because keycloak auth is not currently available diff --git a/deploy/k8s/base/keycloak/resources/instructlab-ui-client.yaml b/deploy/k8s/base/keycloak/resources/instructlab-ui-client.yaml index ba62014d..7407dea3 100644 --- a/deploy/k8s/base/keycloak/resources/instructlab-ui-client.yaml +++ b/deploy/k8s/base/keycloak/resources/instructlab-ui-client.yaml @@ -4,6 +4,7 @@ metadata: labels: app: sso name: instructlab-ui + namespace: keycloak-system spec: client: clientAuthenticatorType: client-secret diff --git a/deploy/k8s/base/keycloak/resources/keycloak.yaml b/deploy/k8s/base/keycloak/resources/keycloak.yaml index 95473012..88d8172e 100644 --- a/deploy/k8s/base/keycloak/resources/keycloak.yaml +++ b/deploy/k8s/base/keycloak/resources/keycloak.yaml @@ -4,6 +4,7 @@ metadata: labels: app: sso name: keycloak + namespace: keycloak-system spec: externalAccess: enabled: true diff --git a/deploy/k8s/base/keycloak/resources/kustomization.yaml b/deploy/k8s/base/keycloak/resources/kustomization.yaml index 71245269..64d83e4b 100644 --- a/deploy/k8s/base/keycloak/resources/kustomization.yaml +++ b/deploy/k8s/base/keycloak/resources/kustomization.yaml @@ -1,8 +1,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization - -namespace: keycloak-system - resources: - keycloak.yaml - realm.yaml diff --git a/deploy/k8s/base/keycloak/resources/realm.yaml b/deploy/k8s/base/keycloak/resources/realm.yaml index 9a40a209..20151881 100644 --- a/deploy/k8s/base/keycloak/resources/realm.yaml +++ b/deploy/k8s/base/keycloak/resources/realm.yaml @@ -4,6 +4,7 @@ metadata: labels: app: sso name: instructlab-ui + namespace: keycloak-system spec: instanceSelector: matchLabels: diff --git a/deploy/k8s/base/keycloak/resources/user.yaml b/deploy/k8s/base/keycloak/resources/user.yaml index 138f460f..3bbbeeba 100644 --- a/deploy/k8s/base/keycloak/resources/user.yaml +++ b/deploy/k8s/base/keycloak/resources/user.yaml @@ -5,6 +5,7 @@ metadata: labels: app: sso name: dummy + namespace: keycloak-system spec: realmSelector: matchLabels: diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 45009cf6..52f254f1 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -2,7 +2,7 @@ import NextAuth, { NextAuthOptions } from 'next-auth'; import GitHubProvider from 'next-auth/providers/github'; import CredentialsProvider from 'next-auth/providers/credentials'; -import KeycloakProvider from "next-auth/providers/keycloak"; +import KeycloakProvider from 'next-auth/providers/keycloak'; import axios from 'axios'; import winston from 'winston'; import path from 'path'; @@ -10,7 +10,7 @@ import path from 'path'; // Extend the Session and JWT types declare module 'next-auth' { interface Session { - provider?: string + provider?: string; accessToken?: string; id?: string; } @@ -45,16 +45,16 @@ const ORG = process.env.NEXT_PUBLIC_AUTHENTICATION_ORG!; const authOptions: NextAuthOptions = { providers: [ GitHubProvider({ - name: "Github", + name: 'Github', clientId: process.env.OAUTH_GITHUB_ID!, clientSecret: process.env.OAUTH_GITHUB_SECRET!, authorization: { params: { scope: 'public_repo' } } }), KeycloakProvider({ - name: "Keycloak", + name: 'Keycloak', clientId: process.env.KEYCLOAK_CLIENT_ID!, clientSecret: process.env.KEYCLOAK_CLIENT_SECRET!, - issuer: process.env.KEYCLOAK_ISSUER, + issuer: process.env.KEYCLOAK_ISSUER }), CredentialsProvider({ name: 'Credentials', @@ -83,7 +83,7 @@ const authOptions: NextAuthOptions = { async jwt({ token, user, account }) { if (account) { token.accessToken = account.access_token!; - token.provider = account.provider + token.provider = account.provider!; } if (user) { token.id = user.id; @@ -96,7 +96,7 @@ const authOptions: NextAuthOptions = { if (token) { session.accessToken = token.accessToken; session.id = token.id; - session.provider = token.provider + session.provider = token.provider; } // // Uncomment for session callback debugging // console.log('Session Callback:', session); diff --git a/src/app/login/keycloakicon.tsx b/src/app/login/keycloakicon.tsx index c89d2c5f..6ab44e9c 100644 --- a/src/app/login/keycloakicon.tsx +++ b/src/app/login/keycloakicon.tsx @@ -1,20 +1,17 @@ // Pulled from: https://github.com/keycloak/keycloak-misc/blob/main/logo/icon-white.svg const KeycloakIcon = () => ( - - - - ); - - export default KeycloakIcon; + + + +); + +export default KeycloakIcon; diff --git a/src/components/Dashboard/index.tsx b/src/components/Dashboard/index.tsx index 534f9f1e..566ac047 100644 --- a/src/components/Dashboard/index.tsx +++ b/src/components/Dashboard/index.tsx @@ -41,7 +41,7 @@ const Index: React.FunctionComponent = () => { const router = useRouter(); const fetchAndSetPullRequests = React.useCallback(async () => { - if (session?.accessToken && session?.provider == "Github") { + if (session?.accessToken && session?.provider == 'Github') { try { const header = { Authorization: `Bearer ${session.accessToken}`,