@flowcore/cli-plugin-config
Version:
Flowcore CLI configuration plugin
43 lines (42 loc) • 1.83 kB
JavaScript
import { BaseCommand, LOGIN_CODES, ValidateLogin, } from "@flowcore/cli-plugin-config";
import { ClientFactory } from "../utils/graphql.util.js";
import { WHOAMI_GQL_QUERY, } from "../utils/queries/me.gql.js";
export default class Whoami extends BaseCommand {
static description = "Check what user you are logged in as";
async run() {
const config = this.cliConfiguration.getConfig();
const { auth, login } = config;
if (!login.url) {
this.logger.error("No login url configured");
}
if (!auth) {
this.logger.error("Not logged in");
}
const validator = new ValidateLogin(login.url);
const result = await validator.validate(config, this.cliConfiguration);
if (result.status === LOGIN_CODES.LOGIN_SUCCESS) {
const userInfo = result;
this.logger.info(`Logged in as ${userInfo.name || userInfo.preferred_username} (${userInfo.flowcore_user_id})`);
this.logger.info("");
this.logger.info("Associated tenants:");
const client = await ClientFactory.create(this.cliConfiguration, this.logger);
const response = await client.request(WHOAMI_GQL_QUERY);
const table = this.ui
.table()
.head(["Tenant", "Display Name", "Link Type"]);
for (const org of response.me.organizations) {
table.row([
org.organization.org,
org.organization.displayName,
org.linkType,
]);
}
table.render();
return;
}
if (result.status === LOGIN_CODES.LOGIN_EXPIRED) {
this.logger.error("Login expired, please login again");
}
this.logger.error("Not logged in");
}
}