@@ -67,32 +67,6 @@ function parseCoreCount(v: string): number | undefined {
67
67
}
68
68
}
69
69
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
-
96
70
function parseVaultName ( vaultName : string ) : string {
97
71
if ( ! vaultNameRegex . test ( vaultName ) ) {
98
72
throw new commander . InvalidArgumentError (
@@ -102,29 +76,12 @@ function parseVaultName(vaultName: string): string {
102
76
return vaultName ;
103
77
}
104
78
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 ?] {
128
85
// The colon character `:` is prohibited in vaultName, so it's first occurence
129
86
// means that this is the delimiter between vaultName and secretPath.
130
87
const colonIndex = secretPath . indexOf ( ':' ) ;
@@ -141,20 +98,35 @@ function parseSecretPathEnv(secretPath: string): [string, string?, string?] {
141
98
equalIndex === - 1
142
99
? secretPathPart
143
100
: secretPathPart . substring ( 0 , equalIndex ) ;
144
- const valueData =
101
+ const value =
145
102
equalIndex === - 1 ? undefined : secretPathPart . substring ( equalIndex + 1 ) ;
146
103
if ( splitSecretPath != null && ! secretPathRegex . test ( splitSecretPath ) ) {
147
104
throw new commander . InvalidArgumentError (
148
105
`${ secretPath } is not of the format <vaultName>[:<secretPath>][=<value>]` ,
149
106
) ;
150
107
}
151
108
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 ) ;
158
130
if ( value != null && ! environmentVariableRegex . test ( value ) ) {
159
131
throw new commander . InvalidArgumentError (
160
132
`${ value } is not a valid environment variable name` ,
@@ -263,7 +235,6 @@ export {
263
235
validateParserToArgParser ,
264
236
validateParserToArgListParser ,
265
237
parseCoreCount ,
266
- parseSecretPathOptional ,
267
238
parseVaultName ,
268
239
parseSecretPath ,
269
240
parseSecretPathValue ,
0 commit comments