Skip to content

Commit

Permalink
Remove User From Org (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftp authored Jan 24, 2025
1 parent 203e638 commit 7ce3e96
Showing 2 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/dbos-cloud/cli.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import updateNotifier, { Package } from "update-notifier";
import { profile } from "./users/profile.js";
import { revokeRefreshToken } from "./users/authentication.js";
import { listAppVersions } from "./applications/list-app-versions.js";
import { orgInvite, orgListUsers, renameOrganization, joinOrganization } from "./organizations/organization.js";
import { orgInvite, orgListUsers, renameOrganization, joinOrganization, removeUserFromOrg } from "./organizations/organization.js";
import { ListWorkflowsInput, listWorkflows } from "./applications/manage-workflows.js";
import { importSecrets } from "./applications/secrets.js";

@@ -438,6 +438,15 @@ orgCommands
process.exit(exitCode);
});

orgCommands
.command("remove")
.description("Remove a user from an organization")
.argument("<username>", "User to remove")
.action(async (username: string) => {
const exitCode = await removeUserFromOrg(DBOSCloudHost, username);
process.exit(exitCode);
});

////////////////////////////
/* WORKFLOW COMMANDS */
////////////////////////////
30 changes: 30 additions & 0 deletions packages/dbos-cloud/organizations/organization.ts
Original file line number Diff line number Diff line change
@@ -142,3 +142,33 @@ export async function joinOrganization(host: string, orgname: string, secret: st
return 1;
}
}

export async function removeUserFromOrg(host: string, usernameToDelete: string) {
const logger = getLogger();
const userCredentials = await getCloudCredentials(host, logger);
const bearerToken = "Bearer " + userCredentials.token;

try {
await axios.delete(
`https://${host}/v1alpha1/${userCredentials.organization}/${usernameToDelete}`,
{
headers: {
"Content-Type": "application/json",
Authorization: bearerToken,
},
}
);

logger.info(`Successfully removed ${usernameToDelete} from organization ${userCredentials.organization}`);
return 0;
} catch (e) {
const errorLabel = `Failed to remove ${usernameToDelete} from organization ${userCredentials.organization}`;
const axiosError = e as AxiosError;
if (isCloudAPIErrorResponse(axiosError.response?.data)) {
handleAPIErrors(errorLabel, axiosError);
} else {
logger.error(`${errorLabel}: ${(e as Error).message}`);
}
return 1;
}
}

0 comments on commit 7ce3e96

Please sign in to comment.