@@ -65,12 +65,12 @@ function parseCoreCount(v: string): number | undefined {
6565 }
6666}
6767
68- function parseSecretPathOptional (
69- secretPath : string ,
70- ) : [ string , string ?, string ?] {
68+ function parseSecretPath ( secretPath : string ) : [ string , string ?, string ?] {
7169 // E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned
7270 // 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
7474 const lastEqualIndex = secretPath . lastIndexOf ( '=' ) ;
7575 const splitSecretPath =
7676 lastEqualIndex === - 1
@@ -89,25 +89,18 @@ function parseSecretPathOptional(
8989 return [ vaultName , directoryPath , value ] ;
9090}
9191
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-
10492function parseSecretPathValue ( secretPath : string ) : [ string , string , string ?] {
10593 const [ vaultName , directoryPath , value ] = parseSecretPath ( secretPath ) ;
10694 if ( value != null && ! secretPathValueRegex . test ( value ) ) {
10795 throw new commander . InvalidArgumentError (
10896 `${ value } is not a valid value name` ,
10997 ) ;
11098 }
99+ if ( directoryPath == null ) {
100+ throw new commander . InvalidArgumentError (
101+ `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
102+ ) ;
103+ }
111104 return [ vaultName , directoryPath , value ] ;
112105}
113106
@@ -118,6 +111,11 @@ function parseSecretPathEnv(secretPath: string): [string, string, string?] {
118111 `${ value } is not a valid environment variable name` ,
119112 ) ;
120113 }
114+ if ( directoryPath == null ) {
115+ throw new commander . InvalidArgumentError (
116+ `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
117+ ) ;
118+ }
121119 return [ vaultName , directoryPath , value ] ;
122120}
123121
@@ -221,7 +219,6 @@ export {
221219 validateParserToArgParser ,
222220 validateParserToArgListParser ,
223221 parseCoreCount ,
224- parseSecretPathOptional ,
225222 parseSecretPath ,
226223 parseSecretPathValue ,
227224 parseSecretPathEnv ,
0 commit comments