@leverege/build-tools 2.37.0 → 2.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server/refresh-npm-token.js +18 -23
- package/lib/web/refresh-npm-token.js +18 -23
- package/package.json +1 -1
- package/src/refresh-npm-token.mjs +29 -29
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
3
|
"use strict";
|
|
3
4
|
|
|
4
5
|
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
@@ -10,18 +11,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
10
11
|
// max age in seconds of the npmrc file before refresh
|
|
11
12
|
const refreshThreshold = 3600 * 24; // 1 day
|
|
12
13
|
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
13
15
|
const log = console.log;
|
|
14
|
-
const fetchToken =
|
|
15
|
-
const {
|
|
16
|
-
filename,
|
|
17
|
-
logMissing
|
|
18
|
-
} = opts;
|
|
16
|
+
const fetchToken = filename => {
|
|
19
17
|
const results = {
|
|
18
|
+
filename,
|
|
19
|
+
exists: false,
|
|
20
20
|
token: 'none',
|
|
21
21
|
lastUpdated: -1
|
|
22
22
|
};
|
|
23
23
|
try {
|
|
24
24
|
if (_nodeFs.default.existsSync(filename)) {
|
|
25
|
+
results.exists = true;
|
|
25
26
|
const stat = _nodeFs.default.statSync(filename);
|
|
26
27
|
results.lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
|
|
27
28
|
// grab the current token for logging a redacted version
|
|
@@ -32,27 +33,20 @@ const fetchToken = opts => {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
} catch (statErr) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, `<==fs.statSync failed on file ${filename}`);
|
|
39
|
-
}
|
|
36
|
+
log({
|
|
37
|
+
statErr
|
|
38
|
+
}, `<==fs.statSync failed on file ${filename}`);
|
|
40
39
|
}
|
|
41
40
|
return results;
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
// fetch the tokens - note the RO token is deprecated and may not exist
|
|
45
|
-
const npmrc = fetchToken({
|
|
46
|
-
|
|
47
|
-
logMissing: true
|
|
48
|
-
});
|
|
49
|
-
const npmrcRo = fetchToken({
|
|
50
|
-
filename: `${_nodeOs.default.homedir()}/.npmrc.ro`
|
|
51
|
-
});
|
|
44
|
+
const npmrc = fetchToken(`${_nodeOs.default.homedir()}/.npmrc`);
|
|
45
|
+
const npmrcRo = fetchToken(`${_nodeOs.default.homedir()}/.npmrc.ro`);
|
|
52
46
|
|
|
53
47
|
// log( { npmrc, npmrcRo }, '<==Your tokens be' )
|
|
54
48
|
|
|
55
|
-
if (npmrc.lastUpdated < refreshThreshold) {
|
|
49
|
+
if (npmrc.exists && npmrc.lastUpdated < refreshThreshold) {
|
|
56
50
|
process.exit(0);
|
|
57
51
|
}
|
|
58
52
|
|
|
@@ -75,7 +69,7 @@ try {
|
|
|
75
69
|
_nodeFs.default.copyFileSync(npmrc, `${npmrc}-BAK`); // make a backup for safety
|
|
76
70
|
}
|
|
77
71
|
|
|
78
|
-
_nodeFs.default.writeFileSync(
|
|
72
|
+
_nodeFs.default.writeFileSync(npmrc.filename, npmrcSecret);
|
|
79
73
|
} catch (fileErr) {
|
|
80
74
|
log(fileErr, 'fs failed');
|
|
81
75
|
process.exit(1);
|
|
@@ -83,7 +77,8 @@ try {
|
|
|
83
77
|
const now = new Date().toLocaleString();
|
|
84
78
|
const slackURL = 'https://hooks.slack.com/services/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';
|
|
85
79
|
const slackData = {
|
|
86
|
-
|
|
80
|
+
// eslint-disable-next-line max-len
|
|
81
|
+
text: `--- npmrc refreshed by \`${process.env.USER}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
|
|
87
82
|
channel: '#dev-ops-helm'
|
|
88
83
|
};
|
|
89
84
|
fetch(slackURL, {
|
|
@@ -92,8 +87,8 @@ fetch(slackURL, {
|
|
|
92
87
|
headers: {
|
|
93
88
|
'Content-Type': 'application/json'
|
|
94
89
|
}
|
|
95
|
-
}).catch(err =>
|
|
96
|
-
if (npmrcRo.
|
|
97
|
-
log(_chalk.default.red(
|
|
90
|
+
}).catch(err => log(err));
|
|
91
|
+
if (npmrcRo.exists) {
|
|
92
|
+
log(_chalk.default.red('\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove'));
|
|
98
93
|
process.exit(1);
|
|
99
94
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
3
|
"use strict";
|
|
3
4
|
|
|
4
5
|
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
@@ -10,18 +11,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
10
11
|
// max age in seconds of the npmrc file before refresh
|
|
11
12
|
const refreshThreshold = 3600 * 24; // 1 day
|
|
12
13
|
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
13
15
|
const log = console.log;
|
|
14
|
-
const fetchToken =
|
|
15
|
-
const {
|
|
16
|
-
filename,
|
|
17
|
-
logMissing
|
|
18
|
-
} = opts;
|
|
16
|
+
const fetchToken = filename => {
|
|
19
17
|
const results = {
|
|
18
|
+
filename,
|
|
19
|
+
exists: false,
|
|
20
20
|
token: 'none',
|
|
21
21
|
lastUpdated: -1
|
|
22
22
|
};
|
|
23
23
|
try {
|
|
24
24
|
if (_nodeFs.default.existsSync(filename)) {
|
|
25
|
+
results.exists = true;
|
|
25
26
|
const stat = _nodeFs.default.statSync(filename);
|
|
26
27
|
results.lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
|
|
27
28
|
// grab the current token for logging a redacted version
|
|
@@ -32,27 +33,20 @@ const fetchToken = opts => {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
} catch (statErr) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, `<==fs.statSync failed on file ${filename}`);
|
|
39
|
-
}
|
|
36
|
+
log({
|
|
37
|
+
statErr
|
|
38
|
+
}, `<==fs.statSync failed on file ${filename}`);
|
|
40
39
|
}
|
|
41
40
|
return results;
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
// fetch the tokens - note the RO token is deprecated and may not exist
|
|
45
|
-
const npmrc = fetchToken({
|
|
46
|
-
|
|
47
|
-
logMissing: true
|
|
48
|
-
});
|
|
49
|
-
const npmrcRo = fetchToken({
|
|
50
|
-
filename: `${_nodeOs.default.homedir()}/.npmrc.ro`
|
|
51
|
-
});
|
|
44
|
+
const npmrc = fetchToken(`${_nodeOs.default.homedir()}/.npmrc`);
|
|
45
|
+
const npmrcRo = fetchToken(`${_nodeOs.default.homedir()}/.npmrc.ro`);
|
|
52
46
|
|
|
53
47
|
// log( { npmrc, npmrcRo }, '<==Your tokens be' )
|
|
54
48
|
|
|
55
|
-
if (npmrc.lastUpdated < refreshThreshold) {
|
|
49
|
+
if (npmrc.exists && npmrc.lastUpdated < refreshThreshold) {
|
|
56
50
|
process.exit(0);
|
|
57
51
|
}
|
|
58
52
|
|
|
@@ -75,7 +69,7 @@ try {
|
|
|
75
69
|
_nodeFs.default.copyFileSync(npmrc, `${npmrc}-BAK`); // make a backup for safety
|
|
76
70
|
}
|
|
77
71
|
|
|
78
|
-
_nodeFs.default.writeFileSync(
|
|
72
|
+
_nodeFs.default.writeFileSync(npmrc.filename, npmrcSecret);
|
|
79
73
|
} catch (fileErr) {
|
|
80
74
|
log(fileErr, 'fs failed');
|
|
81
75
|
process.exit(1);
|
|
@@ -83,7 +77,8 @@ try {
|
|
|
83
77
|
const now = new Date().toLocaleString();
|
|
84
78
|
const slackURL = 'https://hooks.slack.com/services/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';
|
|
85
79
|
const slackData = {
|
|
86
|
-
|
|
80
|
+
// eslint-disable-next-line max-len
|
|
81
|
+
text: `--- npmrc refreshed by \`${process.env.USER}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
|
|
87
82
|
channel: '#dev-ops-helm'
|
|
88
83
|
};
|
|
89
84
|
fetch(slackURL, {
|
|
@@ -92,8 +87,8 @@ fetch(slackURL, {
|
|
|
92
87
|
headers: {
|
|
93
88
|
'Content-Type': 'application/json'
|
|
94
89
|
}
|
|
95
|
-
}).catch(err =>
|
|
96
|
-
if (npmrcRo.
|
|
97
|
-
log(_chalk.default.red(
|
|
90
|
+
}).catch(err => log(err));
|
|
91
|
+
if (npmrcRo.exists) {
|
|
92
|
+
log(_chalk.default.red('\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove'));
|
|
98
93
|
process.exit(1);
|
|
99
94
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
3
|
import fs from 'node:fs'
|
|
3
4
|
import os from 'node:os'
|
|
4
5
|
|
|
@@ -8,44 +9,43 @@ import execa from 'execa' // we can't use $ until we upgrade to ESM execa
|
|
|
8
9
|
// max age in seconds of the npmrc file before refresh
|
|
9
10
|
const refreshThreshold = 3600 * 24 // 1 day
|
|
10
11
|
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
11
13
|
const log = console.log
|
|
12
14
|
|
|
13
|
-
const fetchToken = (
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const fetchToken = ( filename ) => {
|
|
16
|
+
const results = {
|
|
17
|
+
filename,
|
|
18
|
+
exists : false,
|
|
19
|
+
token : 'none',
|
|
20
|
+
lastUpdated : -1
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
try {
|
|
18
24
|
if ( fs.existsSync( filename ) ) {
|
|
25
|
+
results.exists = true
|
|
19
26
|
const stat = fs.statSync( filename )
|
|
20
27
|
results.lastUpdated = Math.trunc( ( Date.now() - stat.mtimeMs ) / 1000 )
|
|
21
28
|
// grab the current token for logging a redacted version
|
|
22
29
|
const currentNpmrc = fs.readFileSync( filename, 'utf8' )
|
|
23
30
|
const found = currentNpmrc.match( /_authToken=(.*)\n/ )
|
|
24
|
-
if( found ) {
|
|
25
|
-
results.token = `${found[1].slice(0,8)}......${found[1].slice(-4)}`
|
|
31
|
+
if ( found ) {
|
|
32
|
+
results.token = `${found[1].slice( 0, 8 )}......${found[1].slice( -4 )}`
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
} catch ( statErr ) {
|
|
29
|
-
|
|
30
|
-
log( { statErr }, `<==fs.statSync failed on file ${filename}` )
|
|
31
|
-
}
|
|
36
|
+
log( { statErr }, `<==fs.statSync failed on file ${filename}` )
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
return results
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
// fetch the tokens - note the RO token is deprecated and may not exist
|
|
38
|
-
const npmrc = fetchToken( {
|
|
39
|
-
|
|
40
|
-
logMissing : true,
|
|
41
|
-
} )
|
|
42
|
-
const npmrcRo = fetchToken( {
|
|
43
|
-
filename : `${os.homedir()}/.npmrc.ro`,
|
|
44
|
-
} )
|
|
43
|
+
const npmrc = fetchToken( `${os.homedir()}/.npmrc` )
|
|
44
|
+
const npmrcRo = fetchToken( `${os.homedir()}/.npmrc.ro` )
|
|
45
45
|
|
|
46
46
|
// log( { npmrc, npmrcRo }, '<==Your tokens be' )
|
|
47
47
|
|
|
48
|
-
if ( npmrc.lastUpdated < refreshThreshold ) { process.exit( 0 ) }
|
|
48
|
+
if ( npmrc.exists && npmrc.lastUpdated < refreshThreshold ) { process.exit( 0 ) }
|
|
49
49
|
|
|
50
50
|
// fetch the contents of the npmrc secret stored on leverege-registry
|
|
51
51
|
let npmrcSecret
|
|
@@ -59,7 +59,7 @@ try {
|
|
|
59
59
|
'--project=leverege-registry',
|
|
60
60
|
] )
|
|
61
61
|
npmrcSecret = stdout
|
|
62
|
-
} catch( err ) {
|
|
62
|
+
} catch ( err ) {
|
|
63
63
|
log( chalk.yellow( `\nFailed Command => [${err.escapedCommand}]\n\n` ), chalk.red( err.stderr ) )
|
|
64
64
|
process.exit( 1 )
|
|
65
65
|
}
|
|
@@ -71,8 +71,8 @@ try {
|
|
|
71
71
|
if ( fs.existsSync( npmrc ) ) {
|
|
72
72
|
fs.copyFileSync( npmrc, `${npmrc}-BAK` ) // make a backup for safety
|
|
73
73
|
}
|
|
74
|
-
fs.writeFileSync(
|
|
75
|
-
} catch( fileErr ) {
|
|
74
|
+
fs.writeFileSync( npmrc.filename, npmrcSecret )
|
|
75
|
+
} catch ( fileErr ) {
|
|
76
76
|
log( fileErr, 'fs failed' )
|
|
77
77
|
process.exit( 1 )
|
|
78
78
|
}
|
|
@@ -80,21 +80,21 @@ try {
|
|
|
80
80
|
const now = ( new Date() ).toLocaleString()
|
|
81
81
|
const slackURL = 'https://hooks.slack.com/services/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'
|
|
82
82
|
const slackData = {
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
// eslint-disable-next-line max-len
|
|
84
|
+
text : `--- npmrc refreshed by \`${process.env.USER}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
|
|
85
|
+
channel : '#dev-ops-helm',
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
fetch( slackURL, {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
body: JSON.stringify( slackData ),
|
|
90
|
-
headers: {
|
|
91
|
-
'Content-Type': 'application/json',
|
|
89
|
+
method : 'POST',
|
|
90
|
+
body : JSON.stringify( slackData ),
|
|
91
|
+
headers : {
|
|
92
|
+
'Content-Type' : 'application/json',
|
|
92
93
|
},
|
|
93
94
|
} )
|
|
94
|
-
.catch( err =>
|
|
95
|
+
.catch( err => log( err ) )
|
|
95
96
|
|
|
96
|
-
if ( npmrcRo.
|
|
97
|
-
log( chalk.red(
|
|
97
|
+
if ( npmrcRo.exists ) {
|
|
98
|
+
log( chalk.red( '\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove' ) )
|
|
98
99
|
process.exit( 1 )
|
|
99
100
|
}
|
|
100
|
-
|