Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
8b23f0ba
Unverified
Commit
8b23f0ba
authored
2 years ago
by
Jamie Magee
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor: safely parse decrypted config (#20879)
parent
3390c34c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/config/decrypt.ts
+12
-2
12 additions, 2 deletions
lib/config/decrypt.ts
lib/config/schema.ts
+7
-0
7 additions, 0 deletions
lib/config/schema.ts
with
19 additions
and
2 deletions
lib/config/decrypt.ts
+
12
−
2
View file @
8b23f0ba
...
@@ -6,6 +6,7 @@ import { maskToken } from '../util/mask';
...
@@ -6,6 +6,7 @@ import { maskToken } from '../util/mask';
import
{
regEx
}
from
'
../util/regex
'
;
import
{
regEx
}
from
'
../util/regex
'
;
import
{
addSecretForSanitizing
}
from
'
../util/sanitize
'
;
import
{
addSecretForSanitizing
}
from
'
../util/sanitize
'
;
import
{
GlobalConfig
}
from
'
./global
'
;
import
{
GlobalConfig
}
from
'
./global
'
;
import
{
DecryptedObject
}
from
'
./schema
'
;
import
type
{
RenovateConfig
}
from
'
./types
'
;
import
type
{
RenovateConfig
}
from
'
./types
'
;
export
async
function
tryDecryptPgp
(
export
async
function
tryDecryptPgp
(
...
@@ -92,8 +93,17 @@ export async function tryDecrypt(
...
@@ -92,8 +93,17 @@ export async function tryDecrypt(
const
decryptedObjStr
=
await
tryDecryptPgp
(
privateKey
,
encryptedStr
);
const
decryptedObjStr
=
await
tryDecryptPgp
(
privateKey
,
encryptedStr
);
if
(
decryptedObjStr
)
{
if
(
decryptedObjStr
)
{
try
{
try
{
const
decryptedObj
=
JSON
.
parse
(
decryptedObjStr
);
const
decryptedObj
=
DecryptedObject
.
safeParse
(
const
{
o
:
org
,
r
:
repo
,
v
:
value
}
=
decryptedObj
;
JSON
.
parse
(
decryptedObjStr
)
);
// istanbul ignore if
if
(
!
decryptedObj
.
success
)
{
const
error
=
new
Error
(
'
config-validation
'
);
error
.
validationError
=
`Could not parse decrypted config.`
;
throw
error
;
}
const
{
o
:
org
,
r
:
repo
,
v
:
value
}
=
decryptedObj
.
data
;
if
(
is
.
nonEmptyString
(
value
))
{
if
(
is
.
nonEmptyString
(
value
))
{
if
(
is
.
nonEmptyString
(
org
))
{
if
(
is
.
nonEmptyString
(
org
))
{
const
orgName
=
org
.
replace
(
regEx
(
/
\/
$/
),
''
);
// Strip trailing slash
const
orgName
=
org
.
replace
(
regEx
(
/
\/
$/
),
''
);
// Strip trailing slash
...
...
This diff is collapsed.
Click to expand it.
lib/config/schema.ts
0 → 100644
+
7
−
0
View file @
8b23f0ba
import
{
z
}
from
'
zod
'
;
export
const
DecryptedObject
=
z
.
object
({
o
:
z
.
string
().
optional
(),
r
:
z
.
string
().
optional
(),
v
:
z
.
string
().
optional
(),
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment