@@ -67,32 +67,6 @@ function parseCoreCount(v: string): number | undefined {
6767 }
6868}
6969
70- function parseSecretPathOptional (
71- secretPath : string ,
72- ) : [ string , string ?, string ?] {
73- // E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned
74- // If 'vault1', ['vault1, undefined] is returned
75- // splits out everything after an `=` separator
76- const lastEqualIndex = secretPath . lastIndexOf ( '=' ) ;
77- const splitSecretPath =
78- lastEqualIndex === - 1
79- ? secretPath
80- : secretPath . substring ( 0 , lastEqualIndex ) ;
81- const value =
82- lastEqualIndex === - 1
83- ? undefined
84- : secretPath . substring ( lastEqualIndex + 1 ) ;
85- if ( ! vaultNameSecretPathRegex . test ( splitSecretPath ) ) {
86- throw new commander . InvalidArgumentError (
87- `${ secretPath } is not of the format <vaultName>[:<directoryPath>][=<value>]` ,
88- ) ;
89- }
90- const [ , vaultName , directoryPath ] = splitSecretPath . match (
91- vaultNameSecretPathRegex ,
92- ) ! ;
93- return [ vaultName , directoryPath , value ] ;
94- }
95-
9670function parseVaultName ( vaultName : string ) : string {
9771 if ( ! vaultNameRegex . test ( vaultName ) ) {
9872 throw new commander . InvalidArgumentError (
@@ -102,29 +76,12 @@ function parseVaultName(vaultName: string): string {
10276 return vaultName ;
10377}
10478
105- function parseSecretPath ( secretPath : string ) : [ string , string , string ?] {
106- // E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned
107- // If 'vault1', an error is thrown
108- const [ vaultName , secretName , value ] = parseSecretPathOptional ( secretPath ) ;
109- if ( secretName === undefined ) {
110- throw new commander . InvalidArgumentError (
111- `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
112- ) ;
113- }
114- return [ vaultName , secretName , value ] ;
115- }
116-
117- function parseSecretPathValue ( secretPath : string ) : [ string , string , string ?] {
118- const [ vaultName , directoryPath , value ] = parseSecretPath ( secretPath ) ;
119- if ( value != null && ! secretPathValueRegex . test ( value ) ) {
120- throw new commander . InvalidArgumentError (
121- `${ value } is not a valid value name` ,
122- ) ;
123- }
124- return [ vaultName , directoryPath , value ] ;
125- }
126-
127- function parseSecretPathEnv ( secretPath : string ) : [ string , string ?, string ?] {
79+ // E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned
80+ // If 'vault1', ['vault1, undefined] is returned
81+ // If 'vault1:', an error is thrown
82+ // If 'a/b/c', an error is thrown
83+ // Splits out everything after an `=` separator
84+ function parseSecretPath ( secretPath : string ) : [ string , string ?, string ?] {
12885 // The colon character `:` is prohibited in vaultName, so it's first occurence
12986 // means that this is the delimiter between vaultName and secretPath.
13087 const colonIndex = secretPath . indexOf ( ':' ) ;
@@ -141,20 +98,35 @@ function parseSecretPathEnv(secretPath: string): [string, string?, string?] {
14198 equalIndex === - 1
14299 ? secretPathPart
143100 : secretPathPart . substring ( 0 , equalIndex ) ;
144- const valueData =
101+ const value =
145102 equalIndex === - 1 ? undefined : secretPathPart . substring ( equalIndex + 1 ) ;
146103 if ( splitSecretPath != null && ! secretPathRegex . test ( splitSecretPath ) ) {
147104 throw new commander . InvalidArgumentError (
148105 `${ secretPath } is not of the format <vaultName>[:<secretPath>][=<value>]` ,
149106 ) ;
150107 }
151108 const parsedVaultName = parseVaultName ( vaultNamePart ) ;
152- const parsedSecretPath = splitSecretPath . match ( secretPathRegex ) ?. [ 0 ] ?? '/' ;
153- const [ vaultName , directoryPath , value ] = [
154- parsedVaultName ,
155- parsedSecretPath ,
156- valueData ,
157- ] ;
109+ const parsedSecretPath = splitSecretPath . match ( secretPathRegex ) ?. [ 0 ] ;
110+ return [ parsedVaultName , parsedSecretPath , value ] ;
111+ }
112+
113+ function parseSecretPathValue ( secretPath : string ) : [ string , string , string ?] {
114+ const [ vaultName , directoryPath , value ] = parseSecretPath ( secretPath ) ;
115+ if ( value != null && ! secretPathValueRegex . test ( value ) ) {
116+ throw new commander . InvalidArgumentError (
117+ `${ value } is not a valid value name` ,
118+ ) ;
119+ }
120+ if ( directoryPath == null ) {
121+ throw new commander . InvalidArgumentError (
122+ `${ secretPath } is not of the format <vaultName>:<directoryPath>[=<value>]` ,
123+ ) ;
124+ }
125+ return [ vaultName , directoryPath , value ] ;
126+ }
127+
128+ function parseSecretPathEnv ( secretPath : string ) : [ string , string ?, string ?] {
129+ const [ vaultName , directoryPath , value ] = parseSecretPath ( secretPath ) ;
158130 if ( value != null && ! environmentVariableRegex . test ( value ) ) {
159131 throw new commander . InvalidArgumentError (
160132 `${ value } is not a valid environment variable name` ,
@@ -263,7 +235,6 @@ export {
263235 validateParserToArgParser ,
264236 validateParserToArgListParser ,
265237 parseCoreCount ,
266- parseSecretPathOptional ,
267238 parseVaultName ,
268239 parseSecretPath ,
269240 parseSecretPathValue ,
0 commit comments