Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
fix(plugins/environments): overwrite remote environment variables wit…
Browse files Browse the repository at this point in the history
…h local ones
  • Loading branch information
miguelrk committed May 21, 2024
1 parent 1b9b1e6 commit b2a0183
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/auth/routes/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const config: RouteConfig = {

export default (config: AuthConfig) => {
return defineRoute((req, ctx) => {
const authFormWrapper = "grid gap-6 w-full xs:w-[350px] max-w-[350px] pb-16";
const authFormWrapper =
"grid gap-6 w-full xs:w-[350px] max-w-[350px] pb-16";
if (config.image) {
return (
<div className="w-full h-full lg:grid lg:min-h-[600px] lg:grid-cols-2 xl:min-h-[800px]">
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/auth/routes/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ export const getRoutesByProvider = (
const routes: PluginRoute[] = [
{
path: `/auth/${provider}/signin`,
handler: async (req, _ctx) => {
const authConfig = getAuthConfig(provider, providerOptions);
handler: async (req, ctx) => {
const authConfig = getAuthConfig(provider, providerOptions, ctx);
const response = await signIn(req, authConfig);
return response;
},
},
{
path: `/auth/${provider}/callback`,
handler: async (req, ctx) => {
const authConfig = getAuthConfig(provider, providerOptions);
const authConfig = getAuthConfig(provider, providerOptions, ctx);
const {
response,
tokens,
Expand Down
1 change: 0 additions & 1 deletion lib/plugins/auth/utils/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export async function getUserGithub(
throw new Error(`${response.status}: ${message}`);
}
const userGithub: UserGithub = await response.json();
console.log(userGithub)
return {
provider: "github",
authId: userGithub.login,
Expand Down
16 changes: 12 additions & 4 deletions lib/plugins/environments/mod.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// deno-lint-ignore-file no-explicit-any
import { load } from "jsr:@std/dotenv";
import { netzo } from "../../apis/netzo.ts";
import type { Project } from "../types.ts";
import { logInfo, LOGS } from "../utils.ts";

const envVarsLocal = await load({ export: true });

export async function setEnvVarsIfRemoteProject() {
const {
NETZO_PROJECT_ID,
NETZO_API_KEY,
NETZO_API_URL = "https://api.netzo.io",
NETZO_APP_URL = "https://app.netzo.io",
// NETZO_APP_URL = "https://app.netzo.io",
} = Deno.env.toObject();

if (NETZO_PROJECT_ID && NETZO_API_KEY) {
Expand All @@ -21,10 +24,15 @@ export async function setEnvVarsIfRemoteProject() {

if (!project) throw new Error(LOGS.notFoundProject());

const envVars = project.envVars?.development ?? {};
const envVarsRemote = project.envVars?.development ?? {};
const envVars = { ...envVarsRemote, ...envVarsLocal };
setEnvVars(envVars);
logInfo(LOGS.envNoticeProduction(Object.keys(envVars).length));
logInfo(LOGS.openInNetzo(NETZO_APP_URL, project));
logInfo(LOGS.loadedEnvsNotice(
Object.keys(envVarsLocal).length,
Object.keys(envVarsRemote).length,
Object.keys(envVars).length,
));
// logInfo(LOGS.openInNetzo(NETZO_APP_URL, project));

return;
} else {
Expand Down
11 changes: 9 additions & 2 deletions lib/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ export const LOGS = {
envNoticeDevelopment: () => {
return "Running locally... Set NETZO_PROJECT_ID and NETZO_API_KEY to connect to remote project.";
},
envNoticeProduction: (count: number) => {
return `Connected to remote Netzo project. Loaded ${count} environment variables.`;
loadedEnvsNotice: (
countLocal: number,
countRemote: number,
countTotal: number,
) => {
return `Loaded ${countTotal} environment variables from ${countLocal} local and ${countTotal - countLocal} remote (overwrote ${countTotal - countRemote}).`;
},
notFoundProject: () => {
return "Project not found. Check the project ID and API key.";
Expand All @@ -78,6 +82,9 @@ export const LOGS = {
const url = `${appUrl}/workspaces/${workspaceId}/projects/${_id}`;
return `Open at ${url}`;
},
localEnvVarSet: (key: string) => {
return `Overwrote remote environment variable "${key}" with local.`;
},
} as const;

export const RESPONSES = {
Expand Down

0 comments on commit b2a0183

Please sign in to comment.