UNPKG

960 BJavaScriptView Raw
1/* @flow */
2'use strict'
3
4/* ::
5import type BlinkMobileIdentity, {
6 AWSCredentials
7} from '@blinkmobile/bm-identity'
8
9import type {
10 BlinkMRCServer
11} from '../types.js'
12*/
13
14const logSymbols = require('log-symbols')
15
16const logUpdates = require('./utils/log-updates.js')
17
18function authenticate (
19 config /* : BlinkMRCServer */,
20 blinkMobileIdentity /* : BlinkMobileIdentity */,
21 env /* : string */
22) /* : Promise<AWSCredentials> */ {
23 const stopUpdates = logUpdates(() => 'Authenticating...')
24 return blinkMobileIdentity.assumeAWSRole({
25 bmProject: config.project,
26 command: 'logs',
27 environment: env
28 })
29 .then((results) => {
30 stopUpdates((logUpdater) => logUpdater(logSymbols.success, 'Authentication complete!'))
31 return results
32 })
33 .catch((err) => {
34 stopUpdates((logUpdater) => logUpdater(logSymbols.error, 'Authentication failed...'))
35 return Promise.reject(err)
36 })
37}
38
39module.exports = {
40 authenticate
41}