-
Notifications
You must be signed in to change notification settings - Fork 97
feat: extend paymaster follow-up #5032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+284
−34
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0fb9f4
chore: fix comments
natanasow 097b3af
chore: resolve comments
natanasow 7d46b0e
chore: fix typo
natanasow 45d775e
chore: resolve comments
natanasow 55be1d3
chore: add paymaster account startup validation
natanasow 6979068
chore: fix key validation
natanasow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,59 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { ConfigKey, GlobalConfig } from './globalConfig'; | ||
| import { ConfigKey } from './globalConfig'; | ||
|
|
||
| export class LoggerService { | ||
| public static readonly SENSITIVE_FIELDS: ConfigKey[] = ['OPERATOR_KEY_MAIN', 'GITHUB_TOKEN', 'GH_ACCESS_TOKEN']; | ||
| /** | ||
| * Unified map of sensitive fields. | ||
| * | ||
| * Key: configuration field name. | ||
| * Value: | ||
| * - `true` - entire value is sensitive | ||
| * - `number[]` - positions of sensitive fields in array values | ||
| */ | ||
| public static readonly SENSITIVE_FIELDS_MAP: Map<ConfigKey, number[] | true> = new Map([ | ||
| // Fields where the whole value is sensitive | ||
| ['OPERATOR_KEY_MAIN', true], | ||
| ['GITHUB_TOKEN', true], | ||
| ['GH_ACCESS_TOKEN', true], | ||
|
|
||
| // Fields where only certain positions in arrays are sensitive | ||
| ['PAYMASTER_ACCOUNTS', [2]], | ||
| ] as [ConfigKey, true | number[]][]); | ||
|
|
||
| /** | ||
| * RegExp to detect GitHub-style secrets in string values. | ||
| */ | ||
| public static readonly GITHUB_SECRET_PATTERN: RegExp = | ||
| /^(gh[pousr]_[a-zA-Z0-9]{36,251}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$/; | ||
|
|
||
| /** | ||
| * Hide sensitive information | ||
| * Hide sensitive configuration values. | ||
| * | ||
| * @param envName | ||
| * @param envValue | ||
| * @param envName - the configuration key | ||
| * @param envValue - the value, either string or array of arrays of strings | ||
| * @returns masked string representation of the environment variable | ||
| */ | ||
| static maskUpEnv(envName: string, envValue: string | undefined): string { | ||
| const isSensitiveField: boolean = (this.SENSITIVE_FIELDS as string[]).indexOf(envName) > -1; | ||
| const isKnownSecret: boolean = | ||
| GlobalConfig.ENTRIES[envName].type === 'string' && !!this.GITHUB_SECRET_PATTERN.exec(envValue ?? ''); | ||
| static maskUpEnv(envName: string, envValue: string | undefined | string[][]): string { | ||
| // explicitly listed as sensitive | ||
| const sensitiveInfo = this.SENSITIVE_FIELDS_MAP.get(envName as ConfigKey); | ||
| if (sensitiveInfo === true) { | ||
| return `${envName} = **********`; | ||
| } | ||
|
|
||
| // certain positions are sensitive in array values | ||
| if (Array.isArray(sensitiveInfo) && sensitiveInfo.length) { | ||
| return `${envName} = ${(envValue as string[][]).map( | ||
| (a) => `[${a.map((v, k) => (sensitiveInfo.includes(k) ? `**********` : v))}]`, | ||
| )}`; | ||
| } | ||
|
|
||
| if (isSensitiveField || isKnownSecret) { | ||
| // handle GitHub tokens | ||
| if (typeof envValue === 'string' && !!this.GITHUB_SECRET_PATTERN.exec(envValue ?? '')) { | ||
| return `${envName} = **********`; | ||
| } | ||
|
|
||
natanasow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Not sensitive | ||
| return `${envName} = ${envValue}`; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.