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

Commit 967dd1f

Browse files
starpitk8s-ci-robot
authored andcommitted
fix(plugins/plugin-s3): up command does not respect --cos-instance choice for ibm cloud
part of #7677
1 parent c44eee1 commit 967dd1f

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

plugins/plugin-core-support/up/src/ibm/cos/creds.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ import { Arguments, encodeComponent } from '@kui-shell/core'
1919

2020
import Options from '../options'
2121

22-
async function check({ REPL }: Pick<Arguments, 'REPL'>) {
22+
/** @return a --cos-instance command line option, if specified */
23+
function cosinstance(parsedOptions: Arguments<Options>['parsedOptions']) {
24+
const cosinstance = parsedOptions['cos-instance']
25+
? `--cos-instance ${encodeComponent(parsedOptions['cos-instance'])}`
26+
: ''
27+
return cosinstance
28+
}
29+
30+
async function check({ REPL, parsedOptions }: Pick<Arguments<Options>, 'REPL' | 'parsedOptions'>) {
2331
try {
24-
return await REPL.qexec<string>('ibmcloud cos validate --output name')
32+
return await REPL.qexec<string>(`ibmcloud cos validate --output name ${cosinstance(parsedOptions)}`)
2533
} catch (err) {
2634
return false
2735
}
@@ -33,10 +41,7 @@ export default {
3341
(!checkResult ? colors.red('not configured') : colors.gray('service-instance=') + colors.yellow(checkResult)),
3442
needsCloudLogin: true,
3543
fix: async (args: Arguments<Options>) => {
36-
const cosinstance = args.parsedOptions['cos-instance']
37-
? `--cos-instance ${encodeComponent(args.parsedOptions['cos-instance'])}`
38-
: ''
39-
await args.REPL.qexec(`ibmcloud cos bind ${cosinstance}`)
44+
await args.REPL.qexec(`ibmcloud cos bind ${cosinstance(args.parsedOptions)}`)
4045
return check(args)
4146
},
4247
onFail: 'ibmcloud cos bind',

plugins/plugin-s3/i18n/ibm_en_US.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"validCreds": "Your connection to IBM Cloud Object Storage looks good",
3+
"noCreds": "An HMAC key is needed. Please try [ibmcloud cos bind](#kuiexec?command=ibmcloud%20cos%20bind).",
4+
"invalidConfiguration": "Invalid IBM Cloud Object Storage configuration detected.",
5+
"noServiceInstanceNameError": "Cannot find the Cloud Object Storage service instance for your credentials",
6+
"nonMatchingServiceNameError": "Desired Cloud Object Storage service instance not selected: {0} != {1}",
7+
"noEndpoint": "Please set your IBM Cloud Object Storage endpoint via [ibmcloud cos endpoint](#kuiexec?command=ibmcloud%20cos%20endpoint)."
8+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,17 @@ async function findCredentials(
128128
): Promise<void | Config> {
129129
const local = await findLocal(args.REPL)
130130

131-
if (local) {
131+
const instanceName = args.parsedOptions['cos-instance']
132+
const matchingNames = local && (!instanceName || local.serviceInstanceName === instanceName)
133+
134+
if (local && matchingNames) {
132135
debug('already have valid local config')
133136
return local
134137
} else {
135138
const instances = await (instancesP || findInstances(args))
136139
debug('instances', instances)
137140

138141
if (instances.length > 0) {
139-
const instanceName = args.parsedOptions['cos-instance']
140142
const instance = instanceName ? instances.find(_ => _.name === instanceName) : instances[0]
141143
if (!instance) {
142144
throw new Error(`Cannot find specified instance ${instanceName}`)

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@ import { setServiceInstanceName } from './bind'
2222
import { setEndpointIfPossible } from './endpoint'
2323
import Config, { hasEndpoint, hasServiceInstanceName } from '../model/Config'
2424

25-
const strings = i18n('plugin-ibmcloud', 'cos')
25+
const strings = i18n('plugin-s3', 'ibm')
2626

2727
interface Options extends ParsedOptions {
2828
output: 'name'
29+
'cos-instance': string
2930
}
3031

3132
/** Avoid redundant lookups for one-and-done headless mode */
3233
const headlessTasks: Record<string, Promise<string | Config>> = {}
34+
function invalidate({ command }: Pick<Arguments, 'command'>) {
35+
return (headlessTasks[command] = undefined)
36+
}
3337

3438
async function innerValidate(args: Arguments<Options>): Promise<string | Config> {
3539
const config = await readConfig(args)
3640

37-
if (isGoodConfig(config)) {
41+
const instanceName = args.parsedOptions['cos-instance']
42+
const matchingNames = !instanceName || config.serviceInstanceName === instanceName
43+
44+
if (isGoodConfig(config) && matchingNames) {
3845
if (args.execOptions.type !== ExecType.Nested) {
3946
return strings('validCreds')
4047
} else if (args.parsedOptions.output === 'name') {
@@ -53,16 +60,24 @@ async function innerValidate(args: Arguments<Options>): Promise<string | Config>
5360
const noCredsMessage = strings('noCreds')
5461
const noEndpointMessage = strings('noEndpoint')
5562
const noServiceInstanceNameError = strings('noServiceInstanceName')
63+
const nonMatchingServiceNameError = strings('nonMatchingServiceNameError', instanceName, config.serviceInstanceName)
5664

5765
if (noEndpoint && noCreds) {
66+
invalidate(args)
5867
throw new Error(`${noCredsMessage} ${noEndpointMessage}`)
5968
} else if (noEndpoint) {
69+
invalidate(args)
6070
throw new Error(noEndpointMessage)
6171
} else if (noCreds) {
72+
invalidate(args)
6273
throw new Error(noCredsMessage)
6374
} else {
6475
if (!hasServiceInstanceName(config) && !(await setServiceInstanceName(args, config))) {
76+
invalidate(args)
6577
throw new Error(noServiceInstanceNameError)
78+
} else if (!matchingNames) {
79+
invalidate(args)
80+
throw new Error(nonMatchingServiceNameError)
6681
}
6782

6883
if (args.parsedOptions.output === 'name') {

0 commit comments

Comments
 (0)