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