@@ -48,9 +48,9 @@ def list_firewall_rules(project_id: str) -> Iterable:
4848# [END compute_firewall_list]
4949
5050
51- def print_firewall_rule (project_id : str , firewall_rule_name : str ):
51+ def get_firewall_rule (project_id : str , firewall_rule_name : str ) -> compute_v1 . Firewall :
5252 firewall_client = compute_v1 .FirewallsClient ()
53- print ( firewall_client .get (project = project_id , firewall = firewall_rule_name ) )
53+ return firewall_client .get (project = project_id , firewall = firewall_rule_name )
5454
5555
5656# [START compute_firewall_create]
@@ -72,15 +72,17 @@ def create_firewall_rule(
7272 firewall_rule .name = firewall_rule_name
7373 firewall_rule .direction = compute_v1 .Firewall .Direction .INGRESS
7474
75- tcp_80_443_allowed = compute_v1 .Allowed ()
76- tcp_80_443_allowed .I_p_protocol = "tcp"
77- tcp_80_443_allowed .ports = ["80" , "443" ]
75+ allowed_ports = compute_v1 .Allowed ()
76+ allowed_ports .I_p_protocol = "tcp"
77+ allowed_ports .ports = ["80" , "443" ]
7878
79- firewall_rule .allowed = [tcp_80_443_allowed ]
79+ firewall_rule .allowed = [allowed_ports ]
8080 firewall_rule .source_ranges = ["0.0.0.0/0" ]
8181 firewall_rule .network = network
8282 firewall_rule .description = "Allowing TCP traffic on port 80 and 443 from Internet."
8383
84+ firewall_rule .target_tags = ['web' ]
85+
8486 # Note that the default value of priority for the firewall API is 1000.
8587 # If you check the value of `firewall_rule.priority` at this point it
8688 # will be equal to 0, however it is not treated as "set" by the library and thus
@@ -164,11 +166,11 @@ def delete_firewall_rule(project_id: str, firewall_rule_name: str):
164166 create_firewall_rule (default_project_id , rule_name )
165167 try :
166168 print ("Rule created:" )
167- print_firewall_rule ( default_project_id , rule_name )
169+ print ( get_firewall_rule ( default_project_id , rule_name ) )
168170 print ("Updating rule priority to 10..." )
169171 patch_firewall_priority (default_project_id , rule_name , 10 )
170172 print ("Rule updated: " )
171- print_firewall_rule ( default_project_id , rule_name )
173+ print ( get_firewall_rule ( default_project_id , rule_name ) )
172174 print (f"Deleting rule { rule_name } ..." )
173175 finally :
174176 delete_firewall_rule (default_project_id , rule_name )
0 commit comments