@leverege/build-tools 2.5.5 → 2.5.6

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.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const SimpleGit = require('simple-git');
5
+
6
+ const git = new SimpleGit();
7
+
8
+ const getCurrentBranchName = async () => {
9
+ const branchInfo = await git.branch();
10
+ return Object.entries(branchInfo.branches).find(([name, info]) => info.current)[0];
11
+ };
12
+
13
+ const isProtected = async () => {
14
+ const protectedBranches = ['master', 'development'];
15
+ const theBranch = await getCurrentBranchName();
16
+ return protectedBranches.includes(theBranch);
17
+ };
18
+
19
+ (async () => {
20
+ try {
21
+ const active = await isProtected();
22
+ process.exit(active ? 0 : 1);
23
+ } catch (err) {
24
+ console.error(err);
25
+ }
26
+ })();
Binary file
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const SimpleGit = require('simple-git');
5
+
6
+ const git = new SimpleGit();
7
+
8
+ const getCurrentBranchName = async () => {
9
+ const branchInfo = await git.branch();
10
+ return Object.entries(branchInfo.branches).find(([name, info]) => info.current)[0];
11
+ };
12
+
13
+ const isProtected = async () => {
14
+ const protectedBranches = ['master', 'development'];
15
+ const theBranch = await getCurrentBranchName();
16
+ return protectedBranches.includes(theBranch);
17
+ };
18
+
19
+ (async () => {
20
+ try {
21
+ const active = await isProtected();
22
+ process.exit(active ? 0 : 1);
23
+ } catch (err) {
24
+ console.error(err);
25
+ }
26
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -33,6 +33,7 @@
33
33
  "helminit-dp": "src/helminit-dp",
34
34
  "helminit-scaler": "src/helminit-scaler",
35
35
  "helmup": "src/helmup",
36
+ "husky-check": "src/husky-check.js",
36
37
  "k8scale": "src/k8scale",
37
38
  "k8x": "src/k8x",
38
39
  "npm-link": "src/npm-link",
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ const SimpleGit = require( 'simple-git' )
4
+ const git = new SimpleGit()
5
+
6
+ const getCurrentBranchName = async () => {
7
+ const branchInfo = await git.branch()
8
+ return Object
9
+ .entries( branchInfo.branches )
10
+ .find( ( [ name, info ] ) => ( info.current ) )[0]
11
+ }
12
+
13
+ const isProtected = async () => {
14
+ const protectedBranches = [ 'master', 'development' ]
15
+ const theBranch = await getCurrentBranchName()
16
+ return protectedBranches.includes( theBranch )
17
+ }
18
+
19
+ ( async () => {
20
+ try {
21
+ const active = await isProtected()
22
+ process.exit( active ? 0 : 1 )
23
+ } catch ( err ) {
24
+ console.error( err )
25
+ }
26
+ } )()
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ IMPERSONATE='gcloud config set auth/impersonate_service_account'
4
+ impersonate() {
5
+ sa=$1
6
+ echo "Impersonating $sa"
7
+ $IMPERSONATE $sa
8
+ }
9
+
10
+ case $1 in
11
+ gke)
12
+ impersonate k8s@project.iam.gserviceaccount.com
13
+ ;;
14
+ admin)
15
+ impersonate admin@other-project.iam.gserviceaccount.com
16
+ ;;
17
+ clear)
18
+ gcloud config unset auth/impersonate_service_account
19
+ ;;
20
+ *)
21
+ echo "Usage: Updates impersonated service account"
22
+ echo " imp-sa [gke|admin|clear]"
23
+ esac
@@ -0,0 +1,46 @@
1
+ #!/bin/bash
2
+
3
+ SVC_PROJ="leverege-dev-john"
4
+
5
+ SVC_NAME="terraformer"
6
+ SVC_ACCT="${SVC_NAME}@${SVC_PROJ}.iam.gserviceaccount.com"
7
+
8
+ function countdown() {
9
+ local SEC=${1}
10
+ shift
11
+ local MSG=${@}
12
+ while [ $SEC -ne 0 ];
13
+ do
14
+ printf "\r\033[KWaiting %.d seconds $MSG" $((SEC--))
15
+ sleep 1
16
+ done
17
+ }
18
+
19
+ gcloud iam service-accounts create ${SVC_NAME} \
20
+ --project=${SVC_PROJ} --quiet \
21
+ --description="the terraforming account" \
22
+ --display-name="terraformer" &> /dev/null
23
+
24
+ gcloud projects add-iam-policy-binding ${SVC_PROJ} \
25
+ --project=${SVC_PROJ} --quiet \
26
+ --member=serviceAccount:${SVC_ACCT} \
27
+ --role=roles/editor &> /dev/null
28
+
29
+ gcloud projects add-iam-policy-binding ${SVC_PROJ} \
30
+ --project=${SVC_PROJ} --quiet \
31
+ --member=serviceAccount:${SVC_ACCT} \
32
+ --role=roles/iam.securityAdmin &> /dev/null
33
+
34
+ countdown 30 "will delete ${SVC_NAME} service account"
35
+
36
+ gcloud projects remove-iam-policy-binding ${SVC_PROJ} \
37
+ --project=${SVC_PROJ} --quiet \
38
+ --member=serviceAccount:${SVC_ACCT} \
39
+ --role=roles/iam.securityAdmin &> /dev/null
40
+
41
+ gcloud projects remove-iam-policy-binding ${SVC_PROJ} \
42
+ --project=${SVC_PROJ} --quiet \
43
+ --member=serviceAccount:${SVC_ACCT} \
44
+ --role=roles/editor &> /dev/null
45
+
46
+ gcloud iam service-accounts delete ${SVC_ACCT} --quiet &> /dev/null