Skip to content

Commit

Permalink
improve stage list
Browse files Browse the repository at this point in the history
  • Loading branch information
u-minor committed Jun 19, 2016
1 parent 5038356 commit e92edc0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/bin/aglex.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ switch (argv._[0]) {
break
case 'stages':
console.log('Getting stage info for API ...')
aglex.getApiStages().then(data => {
_.forEach(data, (val, key) => {
console.log(`${key}: ${val}`)
})
aglex.getApiStages().then(stages => {
for (let stage of stages) {
console.log(`${stage.stageName}: ${stage.description} (${stage.invokeUrl})`)
}
console.log('Completed.')
}, err => {
debug(err)
Expand Down
7 changes: 0 additions & 7 deletions src/lib/aglex.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ class Aglex {
debug('getApiStages called')
const lib = aglexLib(this.config, this.logLevel)
return lib.getApiStages()
.then(stages => {
const data = {}
for (let stage of stages) {
data[stage.stageName] = stage.description
}
return data
})
}

updateApi () {
Expand Down
1 change: 1 addition & 0 deletions src/lib/aglexLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ class AglexLib {
logger.info((`cannot find api ${this.config.apiGateway.name}`).red)
throw new Error('Error')
}
logger.info(`found restApi ${api.name} ${api.id}`)
return api.stages()
}, err => {
logger.info((err.toString()).red)
Expand Down
3 changes: 2 additions & 1 deletion src/lib/apiGateway/restApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const debug = Debug('aglex.apiGateway.restApi')

import {resource} from './resource'
import {deployment} from './deployment'
import {Stage} from './stage'
import {stage} from './stage'

export const restApi = api => {
const Resource = resource(api)
const Deployment = deployment(api)
const Stage = stage(api)

class RestApi {
constructor (data) {
Expand Down
13 changes: 9 additions & 4 deletions src/lib/apiGateway/stage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import _ from 'lodash'

export class Stage {
constructor (restApi, data) {
this._restApi = restApi
_.merge(this, data)
export const stage = api => {
class Stage {
constructor (restApi, data) {
this._restApi = restApi
_.merge(this, data)
this.invokeUrl = `https://${restApi.id}.execute-api.${api.config.region}.amazonaws.com/${this.stageName}`
}
}

return Stage
}
10 changes: 5 additions & 5 deletions test/apiGateway/resource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ target.__Rewire__('method', () => stub.method)
describe('resource', () => {
const apiGateway = new AWS.APIGateway()
const RestApi = class {}
const api = new RestApi()
const restApi = new RestApi()
const Resource = lib.resource(apiGateway)
const res = new Resource(api, {
const res = new Resource(restApi, {
id: '12345abcde',
path: '/',
resourceMethods: {
Expand All @@ -39,7 +39,7 @@ describe('resource', () => {
describe('Resource.create', () => {
it('should return promise object', () => {
sb.stub(apiGateway, 'createResourceAsync').returns(new Promise(() => {}))
const ret = Resource.create(api, {path: '/'})
const ret = Resource.create(restApi, {path: '/'})

expect(ret).to.be.an.instanceof(Promise)
})
Expand All @@ -49,7 +49,7 @@ describe('resource', () => {
id: '12345abcde',
path: '/'
}))
const ret = Resource.create(api, {path: '/'})
const ret = Resource.create(restApi, {path: '/'})

ret.done((data) => check(done, () => {
expect(data).to.deep.equal({
Expand All @@ -63,7 +63,7 @@ describe('resource', () => {

describe('constructor', () => {
it('should generate a valid object', () => {
expect(res._restApi).to.equal(api)
expect(res._restApi).to.equal(restApi)
expect(res).to.have.property('id', '12345abcde')
expect(res).to.have.property('path', '/')
})
Expand Down
18 changes: 11 additions & 7 deletions test/apiGateway/stage.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { expect, sinon } from '../helper'
import {Stage} from '../../src/lib/apiGateway/stage'
import { AWS, expect, sinon } from '../helper'
import * as lib from '../../src/lib/apiGateway/stage'

describe('stage', () => {
const apiGateway = new AWS.APIGateway()
const RestApi = class {}
const restApi = new RestApi()
const stage = new Stage(restApi, {
stageName: 'foo',
deploymentId: '123abc',
createdDate: 'Fri, 01 Jan 2016 00:00:00 GMT'
})
const Stage = lib.stage(apiGateway)
const sb = sinon.sandbox.create()

before(() => {
Expand All @@ -21,7 +18,14 @@ describe('stage', () => {

describe('constructor', () => {
it('should generate a valid object', () => {
const stage = new Stage(restApi, {
stageName: 'foo',
deploymentId: '123abc',
createdDate: 'Fri, 01 Jan 2016 00:00:00 GMT'
})

expect(stage._restApi).to.equal(restApi)
expect(stage).to.have.property('invokeUrl', 'https://12345abcde.execute-api.us-east-1.amazonaws.com/foo')
expect(stage).to.have.property('stageName', 'foo')
expect(stage).to.have.property('deploymentId', '123abc')
expect(stage).to.have.property('createdDate', 'Fri, 01 Jan 2016 00:00:00 GMT')
Expand Down
5 changes: 5 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const AWS = {
},

APIGateway: class {
constructor () {
this.config = {
region: 'us-east-1'
}
}
createDeploymentAsync () {}
createResourceAsync () {}
createRestApiAsync () {}
Expand Down

0 comments on commit e92edc0

Please sign in to comment.