Skip to content

Commit

Permalink
feature: use backend url from env as host for installing agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Oct 19, 2023
1 parent 5d5eb2f commit a0160ae
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*/
const config = {
productionBrowserSourceMaps: true,
env: {
// make the backend URL available to the frontend
NEXT_PUBLIC_BACKEND_URL: process.env.BACKEND_URL
},
async rewrites() {
// if clerk is enabled, we will use next API routes to proxy requests to
// the backend
Expand Down
6 changes: 5 additions & 1 deletion src/components/Agents/InstallAgentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useContext } from "react";
import { GeneratedAgent } from "../../api/services/agents";
import { Button } from "../Button";
import CodeBlock from "../CodeBlock/CodeBlock";
import { Modal } from "../Modal";
import { AuthContext } from "../../context";

type Props = {
isOpen: boolean;
Expand All @@ -14,6 +16,8 @@ export default function InstallAgentModal({
onClose,
generatedAgent
}: Props) {
const { backendUrl } = useContext(AuthContext);

return (
<Modal
title={"Installation Instructions"}
Expand All @@ -26,7 +30,7 @@ export default function InstallAgentModal({
<CodeBlock
code={`helm repo add flanksource https://flanksource.github.io/charts
helm repo update
helm install mc-agent flanksource/mission-control-agent -n "mission-control-agent" --create-namespace --set upstream.createSecret=true --set upstream.host=$host --set upstream.username=${generatedAgent.username} --set upstream.password=${generatedAgent.access_token}`}
helm install mc-agent flanksource/mission-control-agent -n "mission-control-agent" --create-namespace --set upstream.createSecret=true --set upstream.host=${backendUrl} --set upstream.username=${generatedAgent.username} --set upstream.password=${generatedAgent.access_token}`}
/>
</div>
<div className="flex flex-row justify-end gap-4 p-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export default function ClerkAuthContextProvider({
return (
// remove the ?? (payload as any) when the API is updated to return the user
// inside payload instead of the payload itself
<AuthContext.Provider value={{ user: payload.user ?? (payload as any) }}>
<AuthContext.Provider
value={{
user: payload.user ?? (payload as any),
backendUrl: backendURL as string
}}
>
{children}
</AuthContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AuthContext } from "../../../context";
import ErrorPage from "../../Errors/ErrorPage";
import FullPageSkeletonLoader from "../../SkeletonLoader/FullPageSkeletonLoader";

const backendURL = process.env.NEXT_PUBLIC_BACKEND_URL;

type Props = {
children: React.ReactNode;
};
Expand Down Expand Up @@ -33,7 +35,9 @@ export default function KratosAuthContextProvider({ children }: Props) {
}

return (
<AuthContext.Provider value={{ user: payload.user }}>
<AuthContext.Provider
value={{ user: payload.user, backendUrl: backendURL }}
>
{children}
</AuthContext.Provider>
);
Expand Down
2 changes: 2 additions & 0 deletions src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { User } from "../api/services/users";

interface IAuthContext {
user: User;
backendUrl?: string;
}

interface IInitialAuthContext {
user: null;
backendUrl?: string;
}

export const AuthContext = createContext<IAuthContext | IInitialAuthContext>({
Expand Down

0 comments on commit a0160ae

Please sign in to comment.