Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async validateToken(token) {
try {
const api = new DigitalOcean(token);
const {
body: {account}
} = await api.account();
if (account.status === 'active') {
return true;
}
return false;
} catch (error) {
console.error(error.message);
process.exit(1);
}
}
const verifyAccount = async accesstoken => {
try {
const DoAPI = new DigitalOcean(accesstoken, 5);
spinner.start('Verifying your account...');
const {
body: { account }
} = await DoAPI.account();
if (account) {
spinner.succeed('Account verified!');
config.set('do_api_access_token', accesstoken);
console.log(`
${chalk.green('Hi! Your access token is valid.')}
Email: ${account.email}
Droplet Limit: ${account.droplet_limit}
Floating IP Limit: ${account.floating_ip_limit}
`);
}
} catch (error) {
async init() {
let API_TOKEN = '';
if (config.has('do_access_token')) {
API_TOKEN = config.get('do_access_token');
} else {
const {askToken} = require('../prompts');
const {token} = await askToken();
await this.validateToken(token);
this.setToken('do_access_token', token);
API_TOKEN = token;
}
this.api = new DigitalOcean(API_TOKEN);
this.spinner = new Ora();
}
'use strict';
const DigitalOcean = require('do-wrapper').default;
const chalk = require('chalk');
const CacheConf = require('cache-conf');
const Ora = require('ora');
const config = new CacheConf();
const spinner = new Ora();
const ACCESS_TOKEN = config.get('do_api_access_token');
const DoAPI = new DigitalOcean(ACCESS_TOKEN, 50);
module.exports.config = config;
module.exports.spinner = spinner;
module.exports.DoAPI = DoAPI;
module.exports.initAccount = async () => {
const verifyAccount = async accesstoken => {
try {
const DoAPI = new DigitalOcean(accesstoken, 5);
spinner.start('Verifying your account...');
const {
body: { account }
} = await DoAPI.account();
constructor(public events: Events, public logs: LoggerService, public config: ConfigService) {
let key = this.config.get(ConfigKeys.apiKey);
this.api = new DigitalOcean(key);
}
updateApiKey(key: string): Promise {
let apiToCheck = new DigitalOcean(key);
return apiToCheck.account().then((resp) => {
if (resp.body.account.droplet_limit === 0) {
throw new Error(errors.DROPLET_LIMIT);
}
this.api = apiToCheck;
});
}