stsbroker
Version:
CLI to configure and interact with your own AWS STS Broker.
51 lines (50 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const cli_ux_1 = require("cli-ux");
const chalk = require('chalk');
const storage = require("node-persist");
const cognito_1 = require("../cognito");
var tmp = require('tmp');
const fs = require("fs");
const axios = require('axios');
class Policies extends command_1.Command {
async run() {
const { flags } = this.parse(Policies);
await storage.init({ dir: this.config.configDir });
const config = await storage.getItem('config');
var tmpobj = tmp.fileSync();
fs.writeFileSync(tmpobj.name, JSON.stringify(config));
try {
const cognitoToken = await cognito_1.getToken({
hostedUI: tmpobj.name,
reset: flags.reset
});
cli_ux_1.default.action.start(chalk.blue("Let's check what policies are available for you"));
axios.defaults.headers.common['Authorization'] = cognitoToken;
axios.defaults.headers.post['Content-Type'] = 'application/json';
const response = await axios.get(config.endpoint + '/policies');
cli_ux_1.default.action.stop(chalk.blue("Done!"));
cli_ux_1.default.table(response.data, {
policy_id: {
header: 'Policy ID',
minWidth: 20,
},
description: {
get: (row) => row.description,
},
account: {
header: 'AWS Account'
}
}, Object.assign({ printLine: this.log }, flags));
process.exit();
}
catch (error) {
this.error(chalk.red("Sorry... It seems like something went wrong while retrieving your policy list"));
process.exit();
}
}
}
exports.default = Policies;
Policies.description = 'Get STS Broker policies available';
Policies.flags = Object.assign(Object.assign({}, cli_ux_1.default.table.flags()), { reset: command_1.flags.boolean({ description: "Reset Cognito credentials" }) });