* Modifies the priority of a given firewall rule. * * @param {string} projectId - project ID or project number of the Cloud project you want to use. * @param {string} firewallRuleName - name of the rule you want to modify. * @param {number} priority - the new priority to be set for the rule.
(projectId, firewallRuleName, priority = 10)
| 20 | * @param {number} priority - the new priority to be set for the rule. |
| 21 | */ |
| 22 | function main(projectId, firewallRuleName, priority = 10) { |
| 23 | // [START compute_firewall_patch] |
| 24 | /** |
| 25 | * TODO(developer): Uncomment and replace these variables before running the sample. |
| 26 | */ |
| 27 | // const projectId = 'YOUR_PROJECT_ID'; |
| 28 | // const firewallRuleName = 'FIREWALL_RULE_NAME'; |
| 29 | // const priority = 10; |
| 30 | |
| 31 | const compute = require('@google-cloud/compute'); |
| 32 | const computeProtos = compute.protos.google.cloud.compute.v1; |
| 33 | |
| 34 | async function patchFirewallPriority() { |
| 35 | const firewallsClient = new compute.FirewallsClient(); |
| 36 | const operationsClient = new compute.GlobalOperationsClient(); |
| 37 | |
| 38 | const firewallRule = new computeProtos.Firewall(); |
| 39 | firewallRule.priority = priority; |
| 40 | |
| 41 | // The patch operation doesn't require the full definition of a Firewall object. It will only update |
| 42 | // the values that were set in it, in this case it will only change the priority. |
| 43 | const [response] = await firewallsClient.patch({ |
| 44 | project: projectId, |
| 45 | firewall: firewallRuleName, |
| 46 | firewallResource: firewallRule, |
| 47 | }); |
| 48 | let operation = response.latestResponse; |
| 49 | |
| 50 | // Wait for the create operation to complete. |
| 51 | while (operation.status !== 'DONE') { |
| 52 | [operation] = await operationsClient.wait({ |
| 53 | operation: operation.name, |
| 54 | project: projectId, |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | console.log('Firewall rule updated'); |
| 59 | } |
| 60 | |
| 61 | patchFirewallPriority(); |
| 62 | // [END compute_firewall_patch] |
| 63 | } |
| 64 | |
| 65 | main(...process.argv.slice(2)); |
| 66 | process.on('unhandledRejection', err => { |
no test coverage detected