@@ -74,13 +74,27 @@ def compute_networks_insert(project_name: str):
7474 ), 200 , {'Content-Type' : 'application/json' }
7575 return '{"msg": "Disallowed"}' , 401 , {'Content-Type' : 'application/json' }
7676
77+ def _extrapolate_target_from_operation (operation_name : str , project_name : str , host_name : str ) -> str :
78+ """
79+ Extrapolates the target link from the operation name and project name.
80+ """
81+ if project_name == 'mutable-project' and operation_name == 'operation-100000000001-10000000001-10000001-10000001' :
82+ network_name = 'auto-test-01'
83+ return f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/networks/{ network_name } '
84+ if project_name == 'mutable-project' and operation_name == 'operation-100000000002-10000000002-10000002-10000002' :
85+ firewall_name = 'replacable-firewall'
86+ return f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/firewalls/{ firewall_name } '
87+ if project_name == 'mutable-project' and operation_name == 'operation-100000000003-10000000003-10000003-10000003' :
88+ firewall_name = 'updatable-firewall'
89+ return f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/firewalls/{ firewall_name } '
90+ raise ValueError (f"Unsupported operation name: { operation_name } for project: { project_name } " )
91+
7792@app .route ('/compute/v1/projects/<project_name>/global/operations/<operation_name>' , methods = ['GET' ])
7893def projects_testing_project_global_operation_detail (project_name : str , operation_name : str ):
79- if project_name == 'mutable-project' and 'operation-100000000001-10000000001-10000001-10000001' :
94+ try :
8095 operation_id = '1000000000001'
81- network_name = 'auto-test-01'
8296 host_name = 'host.docker.internal' if _IS_DOCKER else 'localhost'
83- target_link = f'https:// { host_name } :1080/compute/v1/projects/ { project_name } /global/networks/ { network_name } '
97+ target_link = _extrapolate_target_from_operation ( operation_name , project_name , host_name )
8498 return render_template (
8599 'global-operation.jinja.json' ,
86100 target_link = target_link ,
@@ -93,7 +107,8 @@ def projects_testing_project_global_operation_detail(project_name: str, operatio
93107 progress = 100 ,
94108 end_time = '2025-07-05T19:43:34.491-07:00' ,
95109 ), 200 , {'Content-Type' : 'application/json' }
96- return '{"msg": "Disallowed"}' , 401 , {'Content-Type' : 'application/json' }
110+ except :
111+ return '{"msg": "Disallowed"}' , 401 , {'Content-Type' : 'application/json' }
97112
98113@app .route ('/compute/v1/projects/<project_name>/global/networks/<network_name>' , methods = ['GET' ])
99114def projects_testing_project_global_network_detail (project_name : str , network_name : str ):
@@ -281,13 +296,69 @@ def v1_projects_testing_project_assets():
281296 # Increment the call counter
282297 return render_template ('route_32_template.json' ), 200 , {'Content-Type' : 'application/json' }
283298
284- @app .route ('/compute/v1/projects/testing-project/global/firewalls/allow-spark-ui' , methods = ['PUT' ])
285- def projects_testing_project_global_firewalls_allow_spark_ui ():
286- return render_template ('route_33_template.json' ), 200 , {'Content-Type' : 'application/json' }
299+ @app .route ('/compute/v1/projects/<project_name>/global/firewalls/<firewall_name>' , methods = ['PUT' ])
300+ def projects_testing_project_global_firewalls_replace (project_name : str , firewall_name : str ):
301+ _permitted_combinations = (('testing-project' , 'allow-spark-ui' ), ('mutable-project' , 'replacable-firewall' ))
302+ if (project_name , firewall_name ) not in _permitted_combinations :
303+ return '{"msg": "Disallowed"}' , 500 , {'Content-Type' : 'application/json' }
304+ body = request .get_json ()
305+ operation_id = '1000000000002'
306+ operation_name = 'operation-100000000002-10000000002-10000002-10000002'
307+ host_name = 'host.docker.internal' if _IS_DOCKER else 'localhost'
308+ target_link = f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/firewalls/{ firewall_name } '
309+ if not body :
310+ return '{"msg": "Invalid request body"}' , 400 , {'Content-Type' : 'application/json' }
311+ if not project_name :
312+ return '{"msg": "Invalid request: project not supplied"}' , 400 , {'Content-Type' : 'application/json' }
313+ return render_template (
314+ 'global-operation.jinja.json' ,
315+ target_link = target_link ,
316+ operation_id = operation_id ,
317+ operation_name = operation_name ,
318+ project_name = project_name ,
319+ host_name = host_name ,
320+ kind = 'compute#operation' ,
321+ operation_type = 'put' ,
322+ progress = 0 ,
323+ ), 200 , {'Content-Type' : 'application/json' }
324+
325+ @app .route ('/compute/v1/projects/<project_name>/global/firewalls/<firewall_name>' , methods = ['PATCH' ])
326+ def projects_testing_project_global_firewalls_update (project_name : str , firewall_name : str ):
327+ _permitted_combinations = (('testing-project' , 'some-other-firewall' ), ('mutable-project' , 'updatable-firewall' ))
328+ if (project_name , firewall_name ) not in _permitted_combinations :
329+ return '{"msg": "Disallowed"}' , 500 , {'Content-Type' : 'application/json' }
330+ body = request .get_json ()
331+ operation_id = '1000000000003'
332+ operation_name = 'operation-100000000003-10000000003-10000003-10000003'
333+ host_name = 'host.docker.internal' if _IS_DOCKER else 'localhost'
334+ target_link = f'https://{ host_name } :1080/compute/v1/projects/{ project_name } /global/firewalls/{ firewall_name } '
335+ if not body :
336+ return '{"msg": "Invalid request body"}' , 400 , {'Content-Type' : 'application/json' }
337+ if not project_name :
338+ return '{"msg": "Invalid request: project not supplied"}' , 400 , {'Content-Type' : 'application/json' }
339+ return render_template (
340+ 'global-operation.jinja.json' ,
341+ target_link = target_link ,
342+ operation_id = operation_id ,
343+ operation_name = operation_name ,
344+ project_name = project_name ,
345+ host_name = host_name ,
346+ kind = 'compute#operation' ,
347+ operation_type = 'patch' ,
348+ progress = 0 ,
349+ ), 200 , {'Content-Type' : 'application/json' }
287350
288- @app .route ('/compute/v1/projects/testing-project/global/firewalls/some-other-firewall' , methods = ['PATCH' ])
289- def projects_testing_project_global_firewalls_some_other_firewall ():
290- return render_template ('route_34_template.json' ), 200 , {'Content-Type' : 'application/json' }
351+ @app .route ('/compute/v1/projects/<project_name>/global/firewalls/<firewall_name>' , methods = ['GET' ])
352+ def projects_testing_project_global_firewalls_some_other_firewall (project_name : str , firewall_name : str ):
353+ _permitted_combinations = (('testing-project' , 'some-other-firewall' ), ('mutable-project' , 'updatable-firewall' ), ('mutable-project' , 'replacable-firewall' ))
354+ if (project_name , firewall_name ) not in _permitted_combinations :
355+ return '{"msg": "Disallowed"}' , 500 , {'Content-Type' : 'application/json' }
356+ jinja_context = {
357+ 'project_name' : project_name ,
358+ 'firewall_name' : firewall_name ,
359+ 'host_name' : 'host.docker.internal' if _IS_DOCKER else 'localhost' ,
360+ }
361+ return render_template ('firewall-detail.jinja.json' , ** jinja_context ), 200 , {'Content-Type' : 'application/json' }
291362
292363@app .route ('/compute/v1/projects/testing-project/global/firewalls' , methods = ['GET' ])
293364def projects_testing_project_global_firewalls ():
0 commit comments