Skip to content

Commit

Permalink
Support migrated ssh integration (#70)
Browse files Browse the repository at this point in the history
Addresses: ENG-1766

updates ssh installation to check for new installation document
structure
  • Loading branch information
varunalla authored Apr 10, 2024
1 parent a34baab commit 92b1080
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@p0security/cli",
"version": "0.5.1",
"version": "0.5.2",
"description": "Execute infra CLI commands with P0 grants",
"main": "index.ts",
"repository": {
Expand Down
12 changes: 4 additions & 8 deletions src/commands/__tests__/ssh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ const mockPrint1 = print1 as jest.Mock;
const mockPrint2 = print2 as jest.Mock;

mockGetDoc({
workflows: {
items: [
{
state: "installed",
type: "aws",
identifier: "test-account",
},
],
"iam-write": {
["aws:test-account"]: {
state: "installed",
},
},
});

Expand Down
12 changes: 6 additions & 6 deletions src/commands/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ const validateSshInstall = async (authn: Authn) => {
const configDoc = await getDoc<SshConfig, object>(
doc(`o/${authn.identity.org.tenantId}/integrations/ssh`)
);
const items = configDoc
.data()
?.workflows?.items.filter(
(i) => i.state === "installed" && i.type === "aws"
);
if (!items?.length) {
const configItems = configDoc.data()?.["iam-write"];

const items = Object.entries(configItems ?? {}).filter(
([key, value]) => value.state == "installed" && key.startsWith("aws")
);
if (items.length === 0) {
throw "This organization is not configured for SSH access via the P0 CLI";
}
};
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/ssh/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ This file is part of @p0security/cli
You should have received a copy of the GNU General Public License along with @p0security/cli. If not, see <https://www.gnu.org/licenses/>.
**/
type SshItemConfig = {
alias?: string;
identifier: string;
label?: string;
state: string;
type: "aws" | "gcloud";
};

export type SshConfig = {
workflows?: {
items: SshItemConfig[];
};
"iam-write": Record<string, SshItemConfig>;
};

0 comments on commit 92b1080

Please sign in to comment.