Skip to content

Commit

Permalink
add admin to unscoped db path (#279)
Browse files Browse the repository at this point in the history
* add admin to unscoped db path

* move to makeScopedEndpoint

* beta4

* fix tests
  • Loading branch information
fauna-chase authored Oct 9, 2023
1 parent 981cd93 commit ceb326c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fauna-shell",
"description": "faunadb shell",
"version": "1.2.0-beta3",
"version": "1.2.0-beta4",
"author": "Fauna",
"bin": {
"fauna": "./bin/run"
Expand Down
10 changes: 5 additions & 5 deletions src/commands/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class ShellCommand extends EvalCommand {
const { db_path } = this.args;

this.connection = db_path
? await this.ensureDbScopeClient({ scope: db_path, version: this.flags.version })
? await this.ensureDbScopeClient({
scope: db_path,
version: this.flags.version,
})
: await this.getClient({ version: this.flags.version });
this.startShell();
}
Expand Down Expand Up @@ -152,10 +155,7 @@ class ShellCommand extends EvalCommand {

ShellCommand.description = `Start an interactive shell.`;

ShellCommand.examples = [
"$ fauna shell",
"$ fauna shell my_db/nested_db"
];
ShellCommand.examples = ["$ fauna shell", "$ fauna shell my_db/nested_db"];

ShellCommand.flags = {
...FaunaCommand.flags,
Expand Down
10 changes: 8 additions & 2 deletions src/lib/config/root-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ export class Endpoint {
graphqlHost: string;
graphqlPort: number;
} {
const secret =
this.secret + (scope ? `:${scope}` : "") + (role ? `:${role}` : "");
let appendedRoleStr = "";
if (role) {
appendedRoleStr = `:${role}`;
} else if (scope) {
appendedRoleStr = ":admin";
}

const secret = this.secret + (scope ? `:${scope}` : "") + appendedRoleStr;

return {
secret,
Expand Down
14 changes: 7 additions & 7 deletions test/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe("local config", () => {
},
})
).to.deep.contain({
secret: "fn555:foo",
secret: "fn555:foo:admin",
url: "https://db.fauna.com",
});
});
Expand Down Expand Up @@ -185,7 +185,7 @@ describe("local config", () => {
},
})
).to.deep.contain({
secret: "fn555:my-db",
secret: "fn555:my-db:admin",
url: "https://db.fauna.com",
});
});
Expand Down Expand Up @@ -223,7 +223,7 @@ describe("local config with flags", () => {
},
})
).to.deep.contain({
secret: "fn888:foo",
secret: "fn888:foo:admin",
url: "http://localhost:10443",
});
});
Expand Down Expand Up @@ -263,7 +263,7 @@ describe("local config with flags", () => {
},
})
).to.deep.contain({
secret: "fn888:bar",
secret: "fn888:bar:admin",
url: "http://localhost:10443",
});
});
Expand Down Expand Up @@ -308,7 +308,7 @@ describe("local config with flags", () => {
},
})
).to.deep.contain({
secret: "fn999:my-db-3",
secret: "fn999:my-db-3:admin",
url: "http://somewhere-else:10443",
});
});
Expand All @@ -327,7 +327,7 @@ describe("local config with flags", () => {
scope: "my-scope",
})
).to.deep.contain({
secret: "fn1234:my-scope",
secret: "fn1234:my-scope:admin",
url: "http://localhost:8443",
});
});
Expand Down Expand Up @@ -355,7 +355,7 @@ describe("local config with flags", () => {
scope: "my-scope",
})
).to.deep.contain({
secret: "fn1234:my-db/my-scope",
secret: "fn1234:my-db/my-scope:admin",
url: "http://localhost:8443",
});
});
Expand Down

0 comments on commit ceb326c

Please sign in to comment.