Skip to content

Commit

Permalink
Merge pull request #82 from cloud-annotations/niko-dev
Browse files Browse the repository at this point in the history
Niko dev
  • Loading branch information
bourdakos1 committed May 31, 2019
2 parents fbfda2b + 71b3274 commit 71ef608
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 16 deletions.
2 changes: 1 addition & 1 deletion __tests__/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const validPassword = 'password'
const validUrl = 'url'
const validAccessKeyId = 'access_key_id'
const validSecretAccessKey = 'secret_access_key'
const validRegion = 'us-geo'
const validRegion = 'us'
const validBucket = 'bucket'
const invalidBucket = 'out-of-region'
const randomError = 'random-error'
Expand Down
26 changes: 21 additions & 5 deletions __tests__/utils/cosEndpointBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,45 @@ describe('cosEndpointBuilder', () => {
it('us-geo local', () => {
const region = 'us-geo'
const endpoint = cosEndpointBuilder(region, true)
assert(endpoint === `https://s3-api.${region}.objectstorage.softlayer.net`)
assert(endpoint === `https://s3.us.cloud-object-storage.appdomain.cloud`)
})

it('us local', () => {
const region = 'us'
const endpoint = cosEndpointBuilder(region, true)
assert(endpoint === `https://s3.us.cloud-object-storage.appdomain.cloud`)
})

it('non us-geo local', () => {
const region = 'us-south'
const endpoint = cosEndpointBuilder(region, true)
assert(endpoint === `https://s3.${region}.objectstorage.softlayer.net`)
assert(
endpoint === `https://s3.us-south.cloud-object-storage.appdomain.cloud`
)
})

it('us-geo private', () => {
const region = 'us-geo'
const endpoint = cosEndpointBuilder(region, false)
assert(
endpoint ===
`https://s3-api.${region}.objectstorage.service.networklayer.com`
endpoint === `https://s3.private.us.cloud-object-storage.appdomain.cloud`
)
})

it('us private', () => {
const region = 'us'
const endpoint = cosEndpointBuilder(region, false)
assert(
endpoint === `https://s3.private.us.cloud-object-storage.appdomain.cloud`
)
})

it('non us-geo private', () => {
const region = 'us-south'
const endpoint = cosEndpointBuilder(region, false)
assert(
endpoint === `https://s3.${region}.objectstorage.service.networklayer.com`
endpoint ===
`https://s3.private.us-south.cloud-object-storage.appdomain.cloud`
)
})
})
59 changes: 50 additions & 9 deletions src/utils/cosEndpointBuilder.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
module.exports = (region, local) => {
let base
if (region.includes('us-geo')) {
base = 's3-api.'
} else {
base = 's3.'
let compatMap = {
us: 'us',
'us-geo': 'us',
'dal.us': 'dal.us',
'dal-us-geo': 'dal.us',
'wdc.us': 'wdc.us',
'wdc-us-geo': 'wdc.us',
'sjc.us': 'sjc.us',
'sjc-us-geo': 'sjc.us',
eu: 'eu',
'eu-geo': 'eu',
'ams.eu': 'ams.eu',
'ams-eu-geo': 'ams.eu',
'fra.eu': 'fra.eu',
'fra-eu-geo': 'fra.eu',
'mil.eu': 'mil.eu',
'mil-eu-geo': 'mil.eu',
ap: 'ap',
'ap-geo': 'ap',
'tok.ap': 'tok.ap',
'tok-ap-geo': 'tok.ap',
'seo.ap': 'seo.ap',
'seo-ap-geo': 'seo.ap',
'hkg.ap': 'hkg.ap',
'hkg-ap-geo': 'hkg.ap',
'us-south': 'us-south',
'us-east': 'us-east',
'eu-gb': 'eu-gb',
'eu-de': 'eu-de',
'jp-tok': 'jp-tok',
'au-syd': 'au-syd',
ams03: 'ams03',
che01: 'che01',
mel01: 'mel01',
osl01: 'osl01',
tor01: 'tor01',
sao01: 'sao01',
seo01: 'seo01',
mon01: 'mon01',
mex01: 'mex01',
sjc04: 'sjc04',
mil01: 'mil01',
hkg02: 'hkg02'
}

let end
const compatRegion = compatMap[region] || region

let private
if (local) {
end = '.objectstorage.softlayer.net'
private = ''
} else {
end = '.objectstorage.service.networklayer.com'
private = 'private.'
}
return `https://${base}${region}${end}`

return `https://s3.${private}${compatRegion}.cloud-object-storage.appdomain.cloud`
}
2 changes: 1 addition & 1 deletion src/utils/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MuteStream = require('mute-stream')
const { eraseLines, cursorHide, cursorShow } = require('ansi-escapes')

const renderItems = (items, delegate, index) => {
let pointer = (delegate.windowSize - 1) / 2
let pointer = Math.ceil((delegate.windowSize - 1) / 2)
if (index < pointer) {
for (let i = 0; i < delegate.windowSize; i++) {
process.stdout.write(delegate.renderItem(items[i], i === index))
Expand Down

0 comments on commit 71ef608

Please sign in to comment.