@rockset/cli
Version:
Official Rockset CLI
75 lines (74 loc) • 3.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const core_2 = require("@rockset/core");
const _ = require("lodash");
const cli_ux_1 = require("cli-ux");
const base_command_1 = require("../../base-command");
var KeyState;
(function (KeyState) {
KeyState["ACTIVE"] = "*";
KeyState["INACTIVE"] = "";
})(KeyState || (KeyState = {}));
const censorApiKey = (key) => {
return key === null || key === void 0 ? void 0 : key.replace(key === null || key === void 0 ? void 0 : key.substring(4, (key === null || key === void 0 ? void 0 : key.length) - 4), '*********');
};
let ListProfiles = /** @class */ (() => {
class ListProfiles extends base_command_1.RockCommand {
async run() {
var _a;
const { flags } = await this.parse(ListProfiles);
// First check if there is a profile active at all
const allAuth = await core_2.auth.listAuthProfiles();
const configList = _.map((_a = allAuth === null || allAuth === void 0 ? void 0 : allAuth.config) === null || _a === void 0 ? void 0 : _a.profiles, (v, name) => {
var _a;
return (Object.assign(Object.assign({}, v), { name, active: name === ((_a = allAuth.config) === null || _a === void 0 ? void 0 : _a.active_profile) && !allAuth.env.active
? KeyState.ACTIVE
: KeyState.INACTIVE }));
});
const envProfile = allAuth.env.active
? [
Object.assign(Object.assign({}, allAuth.env.profile), { name: 'ENV', active: KeyState.ACTIVE }),
]
: [];
const rows = envProfile.concat(configList);
if (allAuth.env.active) {
this.warn(`
The current authentication profile is configured from the environment.
If you would like to activate a different profile, please first clear the following environment variables.
ROCKSET_APIKEY
ROCKSET_APISERVER
`);
}
const censoredKeys = flags.showKeys
? rows
: rows.map((_a) => {
var { api_key } = _a, rest = tslib_1.__rest(_a, ["api_key"]);
return (Object.assign({ api_key: censorApiKey(api_key) }, rest));
});
if (rows.length > 0) {
cli_ux_1.cli.table(censoredKeys, {
active: {},
name: {},
api_server: {
header: 'API Server',
},
api_key: {
header: 'API Key',
},
});
}
else {
this.error('No profiles found! Please add a profile first using `rockset auth:add [profile] [apikey] [apiserver]`');
}
}
}
ListProfiles.flags = {
help: core_1.Flags.help({ char: 'h' }),
showKeys: core_1.Flags.boolean({ char: 's', description: 'uncensor all API Keys' }),
};
ListProfiles.description = `list all of the available profiles, and show the active profile`;
return ListProfiles;
})();
exports.default = ListProfiles;