Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions backend/logic/deploy/bucket/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const { isConfigured } = require('@origin/dshop-validation/matrix')
const { guessContentType, walkDir } = require('../../../utils/filesystem')
const { assert } = require('../../../utils/validators')
const { BucketExistence } = require('../../../utils/enums')
const { NETWORK_ID_TO_NAME, BUCKET_PREFIX } = require('../../../utils/const')
const {
NETWORK_ID_TO_NAME,
AWS_MARKETPLACE_DEPLOYMENT,
BUCKET_PREFIX
} = require('../../../utils/const')
const { getLogger } = require('../../../utils/logger')

const log = getLogger('logic.deploy.bucket.aws')
Expand All @@ -24,7 +28,7 @@ let cachedClient = null
function isAvailable({ networkConfig, resourceSelection }) {
return (
resourceSelection.includes('aws-files') &&
isConfigured(networkConfig, 'aws-files')
(AWS_MARKETPLACE_DEPLOYMENT || isConfigured(networkConfig, 'aws-files'))
)
}

Expand All @@ -34,13 +38,23 @@ function isAvailable({ networkConfig, resourceSelection }) {
* @param args {Object}
* @param args.networkConfig {Object} - Decrypted networkConfig object
*/

function configure({ networkConfig }) {
cachedClient = new S3({
apiVersion: '2006-03-01',
accessKeyId: networkConfig.awsAccessKeyId,
secretAccessKey: networkConfig.awsSecretAccessKey,
region: networkConfig.awsRegion // Optional
})
if (AWS_MARKETPLACE_DEPLOYMENT) {
//Use the credentials from the EC2 Instance metadata
cachedClient = new S3({
apiVersion: '2006-03-01',
region: networkConfig.awsRegion // Optional
})
} else {
//Look up the shop admin's AWS credentials from the network config
cachedClient = new S3({
apiVersion: '2006-03-01',
accessKeyId: networkConfig.awsAccessKeyId,
secretAccessKey: networkConfig.awsSecretAccessKey,
region: networkConfig.awsRegion // Optional
})
}
}

/**
Expand Down Expand Up @@ -81,7 +95,11 @@ async function deploy({ shop, networkConfig, OutputDir }) {
}
}

await cachedClient.createBucket(params).promise()
await cachedClient
.createBucket(params, (err) => {
console.error(`Cannot create S3 Bucket:\n`, err)
})
.promise()

log.debug('Waiting for bucket to exist...')

Expand Down
8 changes: 7 additions & 1 deletion backend/logic/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const { getLogger } = require('../../utils/logger')
const { getMyIP } = require('../../utils/ip')
const { assert } = require('../../utils/validators')
const { hasCNAMEOrA } = require('../../utils/dns')
const { DSHOP_CACHE, DEFAULT_INFRA_RESOURCES } = require('../../utils/const')
const {
AWS_MARKETPLACE_DEPLOYMENT,
DSHOP_CACHE,
DEFAULT_INFRA_RESOURCES
} = require('../../utils/const')

const {
deploymentLock,
Expand Down Expand Up @@ -309,6 +313,7 @@ async function deploy({
selection: resourceSelection,
id: 'gcp-files'
}) ||
AWS_MARKETPLACE_DEPLOYMENT ||
canUseResource({
networkConfig,
selection: resourceSelection,
Expand All @@ -323,6 +328,7 @@ async function deploy({
dataDir,
resourceSelection
})
log.debug(`Result of bucket deployment: #${responses}`)
if (responses.length > 0) {
bucketUrls = responses.map((r) => r.url)
bucketHttpUrls = responses.map((r) => r.httpUrl)
Expand Down
Loading