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

Commit 30ac915

Browse files
committed
fix(plugins/plugin-s3): null pointer exception in plugin-s3/ibm init
This would result in the ibm s3 provider not initializing itself. This PR also adds more debug to the ibm s3 provider.
1 parent 3cdd0d4 commit 30ac915

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class IBMCloudS3Provider implements S3Provider {
5151
// e.g. s3.ap.cloud-object-storage.appdomain.cloud -> s3.direct.ap.cloud-object-storage.appdomain.cloud
5252
this.directEndPoint = this.endPoint.replace(/^s3\./, 's3.direct.')
5353

54-
const defaultRegion = GeoDefaults[config['Default Region']] || config['Default Region']
54+
const defaultRegion = config ? GeoDefaults[config['Default Region']] || config['Default Region'] : undefined
5555
this.isDefault = config && geo === defaultRegion
5656

5757
// use the closest available endpoint for listBuckets, since it is geo-agnostic

plugins/plugin-s3/ibm/src/controller/local.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Debug from 'debug'
1718
import { REPL, encodeComponent } from '@kui-shell/core'
1819
import { FStat } from '@kui-shell/plugin-bash-like/fs'
1920

2021
import filepath from './filepath'
2122
import Config, { hasDefaultRegion, hasEndpoint, isGoodConfigIgnoringEndpoint } from '../model/Config'
2223

24+
const debug = Debug('plugin-s3/ibm/controller/local')
25+
2326
export function isGoodConfig(config: void | Record<string, any>): config is Config {
24-
return isGoodConfigIgnoringEndpoint(config) && hasEndpoint(config) && hasDefaultRegion(config)
27+
const checkA = isGoodConfigIgnoringEndpoint(config)
28+
const checkB = hasEndpoint(config)
29+
const checkC = hasDefaultRegion(config)
30+
debug('ibm s3 config check a', checkA)
31+
debug('ibm s3 config check b', checkB)
32+
debug('ibm s3 config check c', checkC)
33+
return checkA && checkB && checkC
2534
}
2635

2736
export default async function findLocal(repl: REPL): Promise<void | Config> {
@@ -32,5 +41,7 @@ export default async function findLocal(repl: REPL): Promise<void | Config> {
3241
if (isGoodConfig(config)) {
3342
return config
3443
}
35-
} catch (err) {}
44+
} catch (err) {
45+
debug('ibm s3 config error reading config', err)
46+
}
3647
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Debug from 'debug'
1718
import { addProviderInitializer } from '@kui-shell/plugin-s3'
1819

1920
export async function registerCapability() {
20-
const ibmcloud = await import('./s3provider').then(_ => _.default)
21-
addProviderInitializer(ibmcloud)
21+
const debug = Debug('plugin-s3/ibm/register')
22+
debug('registering ibm s3 provider 1')
23+
24+
try {
25+
const ibmcloud = await import('./s3provider').then(_ => _.default)
26+
debug('registering ibm s3 provider 2', ibmcloud)
27+
addProviderInitializer(ibmcloud)
28+
} catch (err) {
29+
debug('registering ibm s3 provider error', err)
30+
return []
31+
}
2232
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async function init(geo: string, mountName: string, repl: REPL, reinit: () => vo
5555
const config = await fetchConfig(repl)
5656
listeningAlready = false
5757
if (!isGoodConfig(config)) {
58+
debug('ibm s3 config is incomplete')
5859
return new IBMCloudS3Provider(
5960
geo,
6061
mountName,
@@ -64,7 +65,9 @@ async function init(geo: string, mountName: string, repl: REPL, reinit: () => vo
6465
} else {
6566
if (config && !config['Default Region']) {
6667
// TODO: isn't there a race here?
68+
debug('ibm s3 config inferring Default Region')
6769
config['Default Region'] = await repl.qexec('ibmcloud cos config region default')
70+
debug('ibm s3 config inferring Default Region: success', config['Default Region'])
6871
}
6972

7073
const provider = new IBMCloudS3Provider(geo, mountName, config)
@@ -73,14 +76,15 @@ async function init(geo: string, mountName: string, repl: REPL, reinit: () => vo
7376
if (provider.isDefault) {
7477
// e.g. add an /s3/ibm/default mount point
7578
provider.isDefault = false
76-
debug(`adding extra providers for default region in geo ${geo}`)
79+
debug(`ibm s3 config adding extra providers for default region in geo ${geo}`)
7780
return [...(await extraProvidersForDefaultRegion(geo, config)), provider]
7881
} else {
79-
debug(`adding extra providers for all regions in geo ${geo}`)
82+
debug(`ibm s3 config adding extra providers for all regions in geo ${geo}`)
8083
return [...(await extraProvidersForAllRegions(geo, config)), provider]
8184
}
8285
}
8386
} catch (err) {
87+
debug(`ibm s3 config fatal error`, err)
8488
return new IBMCloudS3Provider(geo, mountName, undefined, new UnsupportedS3ProviderError(err.message))
8589
}
8690
}

0 commit comments

Comments
 (0)