15
15
16
16
// [START functions_billing_limit]
17
17
// [START functions_billing_stop]
18
- const { google } = require ( 'googleapis' ) ;
19
- const { auth } = require ( 'google-auth-library' ) ;
18
+ const { google} = require ( 'googleapis' ) ;
19
+ const { auth} = require ( 'google-auth-library' ) ;
20
20
21
21
const PROJECT_ID = process . env . GCP_PROJECT ;
22
22
const PROJECT_NAME = `projects/${ PROJECT_ID } ` ;
@@ -38,7 +38,7 @@ exports.notifySlack = async (data, context) => {
38
38
const res = await slack . chat . postMessage ( {
39
39
token : BOT_ACCESS_TOKEN ,
40
40
channel : CHANNEL ,
41
- text : budgetNotificationText
41
+ text : budgetNotificationText ,
42
42
} ) ;
43
43
console . log ( res ) ;
44
44
} ;
@@ -71,13 +71,13 @@ const _setAuthCredential = async () => {
71
71
if ( client . hasScopes && ! client . hasScopes ( ) ) {
72
72
client = client . createScoped ( [
73
73
'https://www.googleapis.com/auth/cloud-billing' ,
74
- 'https://www.googleapis.com/auth/cloud-platform'
74
+ 'https://www.googleapis.com/auth/cloud-platform' ,
75
75
] ) ;
76
76
}
77
77
78
78
// Set credential globally for all requests
79
79
google . options ( {
80
- auth : client
80
+ auth : client ,
81
81
} ) ;
82
82
} ;
83
83
@@ -86,8 +86,8 @@ const _setAuthCredential = async () => {
86
86
* @param {string } projectName Name of project to check if billing is enabled
87
87
* @return {bool } Whether project has billing enabled or not
88
88
*/
89
- const _isBillingEnabled = async ( projectName ) => {
90
- const res = await billing . getBillingInfo ( { name : projectName } ) ;
89
+ const _isBillingEnabled = async projectName => {
90
+ const res = await billing . getBillingInfo ( { name : projectName } ) ;
91
91
return res . data . billingEnabled ;
92
92
} ;
93
93
@@ -96,10 +96,10 @@ const _isBillingEnabled = async (projectName) => {
96
96
* @param {string } projectName Name of project disable billing on
97
97
* @return {string } Text containing response from disabling billing
98
98
*/
99
- const _disableBillingForProject = async ( projectName ) => {
99
+ const _disableBillingForProject = async projectName => {
100
100
const res = await billing . updateBillingInfo ( {
101
101
name : projectName ,
102
- resource : { ' billingAccountName' : '' } // Disable billing
102
+ resource : { billingAccountName : '' } , // Disable billing
103
103
} ) ;
104
104
return `Billing disabled: ${ JSON . stringify ( res . data ) } ` ;
105
105
} ;
@@ -126,7 +126,7 @@ exports.limitUse = async (data, context) => {
126
126
const _listRunningInstances = async ( projectId , zone ) => {
127
127
const res = await compute . instances . list ( {
128
128
project : projectId ,
129
- zone : zone
129
+ zone : zone ,
130
130
} ) ;
131
131
132
132
const instances = res . data . items || [ ] ;
@@ -142,15 +142,19 @@ const _stopInstances = async (projectId, zone, instanceNames) => {
142
142
if ( ! instanceNames . length ) {
143
143
return 'No running instances were found.' ;
144
144
}
145
- await Promise . all ( instanceNames . map ( instanceName => {
146
- return compute . instances . stop ( {
147
- project : projectId ,
148
- zone : zone ,
149
- instance : instanceName
150
- } ) . then ( ( res ) => {
151
- console . log ( 'Instance stopped successfully: ' + instanceName ) ;
152
- return res . data ;
153
- } ) ;
154
- } ) ) ;
145
+ await Promise . all (
146
+ instanceNames . map ( instanceName => {
147
+ return compute . instances
148
+ . stop ( {
149
+ project : projectId ,
150
+ zone : zone ,
151
+ instance : instanceName ,
152
+ } )
153
+ . then ( res => {
154
+ console . log ( 'Instance stopped successfully: ' + instanceName ) ;
155
+ return res . data ;
156
+ } ) ;
157
+ } )
158
+ ) ;
155
159
} ;
156
160
// [END functions_billing_limit]
0 commit comments