Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 755f5c4

Browse files
committed
feat(plugins/plugin-s3): add support for public ibmcloud s3 (COS) buckets
part of #7896
1 parent 3503e63 commit 755f5c4

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

plugins/plugin-s3/ibm/src/IBMCloudS3Provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class IBMCloudS3Provider implements S3Provider {
3636
public constructor(
3737
private readonly geo: string,
3838
public readonly mountName: string,
39-
config?: Config,
39+
config?: Pick<Config, 'AccessKeyID' | 'SecretAccessKey' | 'endpointForKui'>,
4040
public readonly error?: Error
4141
) {
4242
const accessKey = config ? config.AccessKeyID : undefined

plugins/plugin-s3/ibm/src/s3provider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { isGoodConfig } from './controller/local'
2424

2525
import baseMountName from './baseMountName'
2626
import IBMCloudS3Provider from './IBMCloudS3Provider'
27-
import extraProvidersForDefaultRegion from './specialMounts'
27+
import { extraProvidersForDefaultRegion, extraProvidersForAllRegions } from './specialMounts'
2828

2929
/** Listening for reconfigs? */
3030
let listeningAlready = false
@@ -72,22 +72,26 @@ async function init(geo: string, mountName: string, repl: REPL, reinit: () => vo
7272
provider.isDefault = false
7373
return [...(await extraProvidersForDefaultRegion(geo, config)), provider]
7474
} else {
75-
return provider
75+
return [...(await extraProvidersForAllRegions(geo, config)), provider]
7676
}
7777
}
7878
} catch (err) {
7979
return new IBMCloudS3Provider(geo, mountName, undefined, new UnsupportedS3ProviderError(err.message))
8080
}
8181
}
8282

83+
export function mountNameForGeo(geo: string, ...extra: string[]) {
84+
return [baseMountName, geo.replace(/-/g, '/'), ...extra].join('/')
85+
}
86+
8387
/**
8488
* We want one ProviderInitializer per geo
8589
*
8690
*/
8791
const initializer: ProviderInitializer[] = Object.keys(Geos)
8892
// .filter(_ => !/-geo$/.test(_)) // don't manifest geo endpoints in the VFS
8993
.map(geo => {
90-
const mountName = `${baseMountName}/${geo.replace(/-/g, '/')}`
94+
const mountName = mountNameForGeo(geo)
9195
return {
9296
mountName,
9397
init: init.bind(undefined, geo, mountName)

plugins/plugin-s3/ibm/src/specialMounts.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { getOrSetPreference } from '@kui-shell/core'
1919

2020
import Config from './model/Config'
2121
import baseMountName from './baseMountName'
22+
import { mountNameForGeo } from './s3provider'
2223
import IBMCloudS3Provider from './IBMCloudS3Provider'
2324

2425
/** The /s3/ibm/default mount point */
@@ -28,6 +29,15 @@ function defaultProvider(geo: string, config: Config) {
2829
return provider
2930
}
3031

32+
/** The /s3/ibm/public mount point */
33+
function publicProvider(geo: string, { endpointForKui }: Pick<Config, 'endpointForKui'>) {
34+
return new IBMCloudS3Provider(geo, mountNameForGeo(geo, 'public'), {
35+
AccessKeyID: '',
36+
SecretAccessKey: '',
37+
endpointForKui
38+
})
39+
}
40+
3141
/** A "bind" mount that points to a subdirectory of a given mount */
3242
class BindMount extends IBMCloudS3Provider {
3343
public constructor(geo: string, mountName: string, config: Config, public readonly subdir: string) {
@@ -45,6 +55,17 @@ async function bindProvider(geo: string, config: Config, pseudo: string) {
4555
return provider
4656
}
4757

48-
export default function extraProvidersForDefaultRegion(geo: string, config: Config) {
49-
return Promise.all([defaultProvider(geo, config), bindProvider(geo, config, 'bin'), bindProvider(geo, config, 'tmp')])
58+
export function extraProvidersForDefaultRegion(geo: string, config: Config) {
59+
return Promise.all([
60+
defaultProvider(geo, config), // /s3/ibm/default
61+
publicProvider(geo, config), // /s3/ibm/public (i.e. access to public buckets without credentials)
62+
bindProvider(geo, config, 'bin'), // s3/ibm/bin
63+
bindProvider(geo, config, 'tmp') // s3/ibm/tmp
64+
])
65+
}
66+
67+
export function extraProvidersForAllRegions(geo: string, config: Config) {
68+
return [
69+
publicProvider(geo, config) // /s3/ibm/public (i.e. access to public buckets without credentials)
70+
]
5071
}

0 commit comments

Comments
 (0)