@@ -65,12 +65,12 @@ function parseCoreCount(v: string): number | undefined {
65
65
}
66
66
}
67
67
68
- function parseSecretPathOptional (
69
- secretPath : string ,
70
- ) : [ string , string ?, string ?] {
68
+ function parseSecretPath ( secretPath : string ) : [ string , string ?, string ?] {
71
69
// E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned
72
70
// If 'vault1', ['vault1, undefined] is returned
73
- // splits out everything after an `=` separator
71
+ // If 'vault1:', an error is thrown
72
+ // If 'a/b/c', an error is thrown
73
+ // Splits out everything after an `=` separator
74
74
const lastEqualIndex = secretPath . lastIndexOf ( '=' ) ;
75
75
const splitSecretPath =
76
76
lastEqualIndex === - 1
@@ -89,25 +89,18 @@ function parseSecretPathOptional(
89
89
return [ vaultName , directoryPath , value ] ;
90
90
}
91
91
92
- function parseSecretPath ( secretPath : string ) : [ string , string , string ?] {
93
- // E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned
94
- // If 'vault1', an error is thrown
95
- const [ vaultName , secretName , value ] = parseSecretPathOptional ( secretPath ) ;
96
- if ( secretName === undefined ) {
97
- throw new commander . InvalidArgumentError (
98
- `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
99
- ) ;
100
- }
101
- return [ vaultName , secretName , value ] ;
102
- }
103
-
104
92
function parseSecretPathValue ( secretPath : string ) : [ string , string , string ?] {
105
93
const [ vaultName , directoryPath , value ] = parseSecretPath ( secretPath ) ;
106
94
if ( value != null && ! secretPathValueRegex . test ( value ) ) {
107
95
throw new commander . InvalidArgumentError (
108
96
`${ value } is not a valid value name` ,
109
97
) ;
110
98
}
99
+ if ( directoryPath == null ) {
100
+ throw new commander . InvalidArgumentError (
101
+ `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
102
+ ) ;
103
+ }
111
104
return [ vaultName , directoryPath , value ] ;
112
105
}
113
106
@@ -118,6 +111,11 @@ function parseSecretPathEnv(secretPath: string): [string, string, string?] {
118
111
`${ value } is not a valid environment variable name` ,
119
112
) ;
120
113
}
114
+ if ( directoryPath == null ) {
115
+ throw new commander . InvalidArgumentError (
116
+ `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
117
+ ) ;
118
+ }
121
119
return [ vaultName , directoryPath , value ] ;
122
120
}
123
121
@@ -221,7 +219,6 @@ export {
221
219
validateParserToArgParser ,
222
220
validateParserToArgListParser ,
223
221
parseCoreCount ,
224
- parseSecretPathOptional ,
225
222
parseSecretPath ,
226
223
parseSecretPathValue ,
227
224
parseSecretPathEnv ,
0 commit comments