UNPKG

1.13 kBJavaScriptView Raw
1/* @flow */
2'use strict'
3
4/* ::
5import type {
6 API,
7 AWSAccount,
8 BlinkMRCServer
9} from '../types.js'
10*/
11
12const request = require('request')
13
14const scope = require('./scope.js')
15
16module.exports = async function getAWSAccount (
17 apiInstance /* : API */,
18 config /* : BlinkMRCServer */,
19 accessToken /* : string | void */
20) /* : Promise<AWSAccount> */ {
21 const serverCLIServiceConfig = scope.serverCLIServiceConfig(config)
22 return new Promise((resolve, reject) => {
23 if (!config.project) {
24 return reject(new Error('Please run the "scope" command to set the project scope.'))
25 }
26 request(
27 `${serverCLIServiceConfig.origin}/awsAccounts/${apiInstance.links.awsAccounts}`,
28 {
29 auth: {
30 bearer: accessToken
31 },
32 json: true
33 },
34 (err, response, body) => {
35 if (err) {
36 return reject(err)
37 }
38 if (response.statusCode !== 200) {
39 return reject(new Error(body && body.message ? body.message : 'Unknown error, please try again and contact support if the problem persists'))
40 }
41 return resolve(body)
42 })
43 })
44}