-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const express = require('express'); | ||
const router = require('./routers'); | ||
const responses = require('../api/responses'); | ||
|
||
const app = express(); | ||
const port = 1234; | ||
|
||
app.use(responses); | ||
app.use('/', router); | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const express = require('express'); | ||
|
||
const apiRouter = express.Router(); | ||
const mainRouter = express.Router(); | ||
|
||
apiRouter.use(require('./service-credential-binding')); | ||
// apiRouter.use(require('./build-task')); | ||
// apiRouter.use(require('./build')); | ||
|
||
mainRouter.use('/v3', apiRouter); | ||
|
||
module.exports = mainRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const crypto = require('crypto'); | ||
const router = require('express').Router(); | ||
|
||
const { createCFAPIResource, createCFAPIResourceList } = require('../../test/api/support/factory/cf-api-response'); | ||
const { Site } = require('../../api/models'); | ||
|
||
// TODO: move this, don't use a global | ||
// on init, make a service credential binding for each site | ||
const serviceCredentialBindings = []; | ||
async function initServiceCredentialBindings() { | ||
const sites = await Site.findAll(); | ||
sites.forEach((site) => { | ||
const serviceCredentialBinding = { | ||
name: site.s3ServiceName, | ||
guid: crypto.randomUUID(), | ||
siteInfo: site, | ||
}; | ||
serviceCredentialBindings.push(serviceCredentialBinding); | ||
}); | ||
} | ||
initServiceCredentialBindings(); | ||
|
||
router.get('/service_credential_bindings', (req, res) => { | ||
const name = req.query.service_instance_names; | ||
const serviceCredentialBinding = serviceCredentialBindings.find(scb => scb.name === name); | ||
if (!serviceCredentialBinding) { | ||
return res.notFound(); | ||
} | ||
|
||
const { guid } = serviceCredentialBinding; | ||
const credentialsServiceInstance = createCFAPIResource({ name, guid }); | ||
const listCredentialServices = createCFAPIResourceList({ | ||
resources: [credentialsServiceInstance], | ||
}); | ||
return res.send(listCredentialServices); | ||
}); | ||
|
||
router.get('/service_credential_bindings/:guid/details', (req, res) => { | ||
const service = serviceCredentialBindings.find(scb => scb.guid === req.params.guid); | ||
const credentials = { | ||
accessKeyId: 'test', | ||
secretAccessKey: 'test', | ||
region: service.siteInfo.awsBucketRegion, | ||
bucket: service.siteInfo.awsBucketName, | ||
}; | ||
return res.send(credentials); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters