Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devops: start uploading build logs to bots (#1870)
Logs will be saved next to the build archive, with the same name and double extension `.log.zip`.
- Loading branch information
1 parent
ef7815e
commit ea95a91
Showing
3 changed files
with
148 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const readline = require('readline'); | ||
|
||
// These env variable values should be removed from logs no matter what. | ||
const BLOCKLIST_ENV_KEYS = new Set([ | ||
'AZ_ACCOUNT_NAME', | ||
'AZ_ACCOUNT_KEY', | ||
'TELEGRAM_BOT_KEY', | ||
]); | ||
|
||
// These env variable values can stay in logs - they are harmless. | ||
const ALLOWLIST_ENV_KEYS = new Set([ | ||
'SHELL', | ||
'TERM', | ||
'USER', | ||
'PWD', | ||
'EDITOR', | ||
'LANG', | ||
'HOME', | ||
'LOGNAME', | ||
'COLORTERM', | ||
'TMPDIR', | ||
]); | ||
|
||
const sanitizeEnv = Object.entries(process.env).filter(([key, value]) => { | ||
if (BLOCKLIST_ENV_KEYS.has(key)) | ||
return true; | ||
if (ALLOWLIST_ENV_KEYS.has(key)) | ||
return false; | ||
// Sanitize all env variables that have `KEY` or `ACCOUNT` as a name. | ||
if (key.toUpperCase().includes('KEY') || key.toUpperCase().includes('ACCOUNT')) | ||
return true; | ||
// We shouldn't try sanitizing env values that are too short. | ||
if (value.trim().length < 7) | ||
return false; | ||
return true; | ||
}); | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
crlfDelay: Infinity, | ||
}); | ||
|
||
rl.on('line', line => { | ||
for (const [key, value] of sanitizeEnv) | ||
line = line.split(value).join(`<${key}>`); | ||
console.log(line); | ||
}); | ||
|
This file contains 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