Skip to content

Commit

Permalink
feat: api authentication (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Aug 10, 2023
1 parent 7430bd8 commit 1fc97f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ DISABLE_TELEMETRY=false
INSTALL_METHOD=helm
IS_CLUSTER_ZERO=true
KUBEFIRST_VERSION=1.10.7
POSTHOG_KEY=phc_1i5RDnv8Byf9w05fV8l02GSltpDwF9iyf0ry0U0Fw4r
POSTHOG_KEY=phc_1i5RDnv8Byf9w05fV8l02GSltpDwF9iyf0ry0U0Fw4r
# Make sure the K1_ACCESS_TOKEN value matches the env var in the api
K1_ACCESS_TOKEN=feedkray
5 changes: 5 additions & 0 deletions charts/console/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
value: {{ .Values.isClusterZero | default "true" | quote }}
- name: INSTALL_METHOD
value: {{ .Values.installMethod | default "helm" }}
- name: K1_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.existingSecret | default "kubefirst-initial-secrets" }}
key: K1_ACCESS_TOKEN
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down
12 changes: 10 additions & 2 deletions pages/api/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { API_URL = '' } = process.env;
const { API_URL = '', K1_ACCESS_TOKEN = '' } = process.env;
const { body, url } = req.body;
const { url: queryUrl } = req.query;

Expand All @@ -15,7 +15,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// eslint-disable-next-line no-console
console.log(`METHOD: ${req.method} URL: ${kubefirstEndpointUrl}`);
try {
const response = await axios({ url: kubefirstEndpointUrl, data: body, method: req.method });
const response = await axios({
url: kubefirstEndpointUrl,
data: body,
method: req.method,
headers: {
...req.headers,
Authorization: `Bearer ${K1_ACCESS_TOKEN}`,
},
});
res.status(200).json(response.data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
Expand Down

0 comments on commit 1fc97f8

Please sign in to comment.