Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] add a plan step to push perms #556

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions client/packages/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @ts-check

import version from "./src/version.js";
import { mkdir, writeFile, readFile, stat } from "fs/promises";
import { mkdir, writeFile, readFile } from "fs/promises";
import { join } from "path";
import { randomUUID } from "crypto";
import jsonDiff from "json-diff";
import dotenv from "dotenv";
import chalk from "chalk";
import { program, Option } from "commander";
Expand Down Expand Up @@ -1070,10 +1071,27 @@ async function pushPerms(appId) {
return;
}

const ok = await promptOk(
"Pushing permissions rules. This will immediately replace your production rules. OK to proceed?",
);
if (!ok) return;
console.log("Planning...");

const prodPerms = await fetchJson({
path: `/dash/apps/${appId}/perms/pull`,
debugName: "Perms pull",
errorMessage: "Failed to pull perms.",
});

if (!prodPerms.ok) return;

const diffedStr = jsonDiff.diffString(prodPerms.data.perms, perms)
if (!diffedStr.length) {
console.log("No perms changes detected. Exiting.");
return;
}

console.log("The following changes will be applied to your perms:");
console.log(diffedStr);

const okPush = await promptOk("OK to proceed?");
if (!okPush) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race condition in both push schema and perms, where if someone else pushed something in the meantime, we may potentially override it.

I think we can punt this race condition for now, but perhaps we can do in the future, is to pass in some version signifier, so in case it's not the same, we error out


const permsRes = await fetchJson({
method: "POST",
Expand Down
4 changes: 4 additions & 0 deletions client/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
"dotenv": "^16.3.1",
"env-paths": "^3.0.0",
"inquirer": "^10.1.6",
"json-diff": "^1.0.6",
"open": "^10.1.0",
"ora": "^8.1.1",
"pkg-dir": "^8.0.0",
"prettier": "^3.3.3",
"terminal-link": "^3.0.0",
"unconfig": "^0.5.5"
},
"devDependencies": {
"@types/json-diff": "^1.0.3"
}
}
46 changes: 46 additions & 0 deletions client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.