@leverege/build-tools 2.36.1 → 2.37.0

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.
@@ -7,35 +7,52 @@ var _chalk = _interopRequireDefault(require("chalk"));
7
7
  var _execa = _interopRequireDefault(require("execa"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  // 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
10
  // max age in seconds of the npmrc file before refresh
14
11
  const refreshThreshold = 3600 * 24; // 1 day
15
12
 
16
13
  const log = console.log;
17
-
18
- // calculate number of seconds since last update and exit if the file
19
- // was recently updated
20
- let lastUpdated = refreshThreshold * 2; // forces refresh if npmrc file does not exist
21
- let oldToken;
22
- try {
23
- if (_nodeFs.default.existsSync(npmrc)) {
24
- const stat = _nodeFs.default.statSync(npmrc);
25
- lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
26
- // grab the old token for logging a redacted version
27
- const oldNpmrc = _nodeFs.default.readFileSync(npmrc, 'utf8');
28
- const found = oldNpmrc.match(/_authToken=(.*)\n/);
29
- if (found) {
30
- oldToken = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
14
+ const fetchToken = opts => {
15
+ const {
16
+ filename,
17
+ logMissing
18
+ } = opts;
19
+ const results = {
20
+ token: 'none',
21
+ lastUpdated: -1
22
+ };
23
+ try {
24
+ if (_nodeFs.default.existsSync(filename)) {
25
+ const stat = _nodeFs.default.statSync(filename);
26
+ results.lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
27
+ // grab the current token for logging a redacted version
28
+ const currentNpmrc = _nodeFs.default.readFileSync(filename, 'utf8');
29
+ const found = currentNpmrc.match(/_authToken=(.*)\n/);
30
+ if (found) {
31
+ results.token = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
32
+ }
33
+ }
34
+ } catch (statErr) {
35
+ if (logMissing) {
36
+ log({
37
+ statErr
38
+ }, `<==fs.statSync failed on file ${filename}`);
31
39
  }
32
40
  }
33
- } catch (statErr) {
34
- log({
35
- statErr
36
- }, `<==fs.statSync failed on file ${npmrc}`);
37
- }
38
- if (lastUpdated < refreshThreshold) {
41
+ return results;
42
+ };
43
+
44
+ // fetch the tokens - note the RO token is deprecated and may not exist
45
+ const npmrc = fetchToken({
46
+ filename: `${_nodeOs.default.homedir()}/.npmrc`,
47
+ logMissing: true
48
+ });
49
+ const npmrcRo = fetchToken({
50
+ filename: `${_nodeOs.default.homedir()}/.npmrc.ro`
51
+ });
52
+
53
+ // log( { npmrc, npmrcRo }, '<==Your tokens be' )
54
+
55
+ if (npmrc.lastUpdated < refreshThreshold) {
39
56
  process.exit(0);
40
57
  }
41
58
 
@@ -66,7 +83,7 @@ try {
66
83
  const now = new Date().toLocaleString();
67
84
  const slackURL = 'https://hooks.slack.com/services/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';
68
85
  const slackData = {
69
- text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n token [\`${oldToken}\`]`,
86
+ text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
70
87
  channel: '#dev-ops-helm'
71
88
  };
72
89
  fetch(slackURL, {
@@ -75,4 +92,8 @@ fetch(slackURL, {
75
92
  headers: {
76
93
  'Content-Type': 'application/json'
77
94
  }
78
- }).catch(err => console.log(err));
95
+ }).catch(err => console.log(err));
96
+ if (npmrcRo.token != 'none') {
97
+ log(_chalk.default.red(`\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove`));
98
+ process.exit(1);
99
+ }
@@ -7,35 +7,52 @@ var _chalk = _interopRequireDefault(require("chalk"));
7
7
  var _execa = _interopRequireDefault(require("execa"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  // 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
10
  // max age in seconds of the npmrc file before refresh
14
11
  const refreshThreshold = 3600 * 24; // 1 day
15
12
 
16
13
  const log = console.log;
17
-
18
- // calculate number of seconds since last update and exit if the file
19
- // was recently updated
20
- let lastUpdated = refreshThreshold * 2; // forces refresh if npmrc file does not exist
21
- let oldToken;
22
- try {
23
- if (_nodeFs.default.existsSync(npmrc)) {
24
- const stat = _nodeFs.default.statSync(npmrc);
25
- lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
26
- // grab the old token for logging a redacted version
27
- const oldNpmrc = _nodeFs.default.readFileSync(npmrc, 'utf8');
28
- const found = oldNpmrc.match(/_authToken=(.*)\n/);
29
- if (found) {
30
- oldToken = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
14
+ const fetchToken = opts => {
15
+ const {
16
+ filename,
17
+ logMissing
18
+ } = opts;
19
+ const results = {
20
+ token: 'none',
21
+ lastUpdated: -1
22
+ };
23
+ try {
24
+ if (_nodeFs.default.existsSync(filename)) {
25
+ const stat = _nodeFs.default.statSync(filename);
26
+ results.lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
27
+ // grab the current token for logging a redacted version
28
+ const currentNpmrc = _nodeFs.default.readFileSync(filename, 'utf8');
29
+ const found = currentNpmrc.match(/_authToken=(.*)\n/);
30
+ if (found) {
31
+ results.token = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
32
+ }
33
+ }
34
+ } catch (statErr) {
35
+ if (logMissing) {
36
+ log({
37
+ statErr
38
+ }, `<==fs.statSync failed on file ${filename}`);
31
39
  }
32
40
  }
33
- } catch (statErr) {
34
- log({
35
- statErr
36
- }, `<==fs.statSync failed on file ${npmrc}`);
37
- }
38
- if (lastUpdated < refreshThreshold) {
41
+ return results;
42
+ };
43
+
44
+ // fetch the tokens - note the RO token is deprecated and may not exist
45
+ const npmrc = fetchToken({
46
+ filename: `${_nodeOs.default.homedir()}/.npmrc`,
47
+ logMissing: true
48
+ });
49
+ const npmrcRo = fetchToken({
50
+ filename: `${_nodeOs.default.homedir()}/.npmrc.ro`
51
+ });
52
+
53
+ // log( { npmrc, npmrcRo }, '<==Your tokens be' )
54
+
55
+ if (npmrc.lastUpdated < refreshThreshold) {
39
56
  process.exit(0);
40
57
  }
41
58
 
@@ -66,7 +83,7 @@ try {
66
83
  const now = new Date().toLocaleString();
67
84
  const slackURL = 'https://hooks.slack.com/services/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';
68
85
  const slackData = {
69
- text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n token [\`${oldToken}\`]`,
86
+ text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
70
87
  channel: '#dev-ops-helm'
71
88
  };
72
89
  fetch(slackURL, {
@@ -75,4 +92,8 @@ fetch(slackURL, {
75
92
  headers: {
76
93
  'Content-Type': 'application/json'
77
94
  }
78
- }).catch(err => console.log(err));
95
+ }).catch(err => console.log(err));
96
+ if (npmrcRo.token != 'none') {
97
+ log(_chalk.default.red(`\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove`));
98
+ process.exit(1);
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.36.1",
3
+ "version": "2.37.0",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/helmdn CHANGED
@@ -92,6 +92,17 @@ function annihilateVelero() {
92
92
  }
93
93
 
94
94
  function helmDown() {
95
+ if [ -f "$1/.nohelmdn" ];
96
+ then
97
+ cat<<NOHELMDN
98
+ `color r "***ERROR: $1/.nohelmdn blocker detect - helmdn blocked"`
99
+
100
+ Somebody really doesn't want you to helmdn $1
101
+
102
+ NOHELMDN
103
+ exit 1
104
+ fi
105
+
95
106
  local namespace=${2:-default}
96
107
  local helmdn="helm uninstall $1 -n $namespace"
97
108
  eval $helmdn
@@ -5,33 +5,47 @@ import os from 'node:os'
5
5
  import chalk from 'chalk'
6
6
  import execa from 'execa' // we can't use $ until we upgrade to ESM execa
7
7
 
8
- // the standard user npmrc token is stored here
9
- const npmrc = `${os.homedir()}/.npmrc`
10
-
11
8
  // max age in seconds of the npmrc file before refresh
12
- const refreshThreshold = 3600 *24 // 1 day
9
+ const refreshThreshold = 3600 * 24 // 1 day
13
10
 
14
11
  const log = console.log
15
12
 
16
- // calculate number of seconds since last update and exit if the file
17
- // was recently updated
18
- let lastUpdated = refreshThreshold * 2 // forces refresh if npmrc file does not exist
19
- let oldToken
20
- try {
21
- if ( fs.existsSync( npmrc ) ) {
22
- const stat = fs.statSync( npmrc )
23
- lastUpdated = Math.trunc( ( Date.now() - stat.mtimeMs ) / 1000 )
24
- // grab the old token for logging a redacted version
25
- const oldNpmrc = fs.readFileSync( npmrc, 'utf8' )
26
- const found = oldNpmrc.match( /_authToken=(.*)\n/ )
27
- if( found ) {
28
- oldToken = `${found[1].slice(0,8)}......${found[1].slice(-4)}`
13
+ const fetchToken = ( opts ) => {
14
+ const { filename, logMissing } = opts
15
+ const results = { token : 'none', lastUpdated : -1 }
16
+
17
+ try {
18
+ if ( fs.existsSync( filename ) ) {
19
+ const stat = fs.statSync( filename )
20
+ results.lastUpdated = Math.trunc( ( Date.now() - stat.mtimeMs ) / 1000 )
21
+ // grab the current token for logging a redacted version
22
+ const currentNpmrc = fs.readFileSync( filename, 'utf8' )
23
+ const found = currentNpmrc.match( /_authToken=(.*)\n/ )
24
+ if( found ) {
25
+ results.token = `${found[1].slice(0,8)}......${found[1].slice(-4)}`
26
+ }
27
+ }
28
+ } catch ( statErr ) {
29
+ if ( logMissing ) {
30
+ log( { statErr }, `<==fs.statSync failed on file ${filename}` )
29
31
  }
30
32
  }
31
- } catch ( statErr ) {
32
- log( { statErr }, `<==fs.statSync failed on file ${npmrc}` )
33
+
34
+ return results
33
35
  }
34
- if ( lastUpdated < refreshThreshold ) { process.exit( 0 ) }
36
+
37
+ // fetch the tokens - note the RO token is deprecated and may not exist
38
+ const npmrc = fetchToken( {
39
+ filename : `${os.homedir()}/.npmrc`,
40
+ logMissing : true,
41
+ } )
42
+ const npmrcRo = fetchToken( {
43
+ filename : `${os.homedir()}/.npmrc.ro`,
44
+ } )
45
+
46
+ // log( { npmrc, npmrcRo }, '<==Your tokens be' )
47
+
48
+ if ( 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
@@ -66,7 +80,7 @@ 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
- text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n token [\`${oldToken}\`]`,
83
+ text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
70
84
  channel: '#dev-ops-helm',
71
85
  }
72
86
 
@@ -78,3 +92,9 @@ fetch( slackURL, {
78
92
  },
79
93
  } )
80
94
  .catch( err => console.log( err ) )
95
+
96
+ if ( npmrcRo.token != 'none' ) {
97
+ log( chalk.red( `\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove` ) )
98
+ process.exit( 1 )
99
+ }
100
+