Skip to content

Commit

Permalink
Ansible: return_if_object should only allow 404 on certain situations (
Browse files Browse the repository at this point in the history
…#481)

Merged PR #481.
  • Loading branch information
rambleraptor authored and modular-magician committed Sep 21, 2018
1 parent 06f0a80 commit 95c110b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build/ansible
Submodule ansible updated 43 files
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_address.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_backend_service.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_disk.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_firewall.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_global_address.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_health_check.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_http_health_check.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_https_health_check.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_image.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_instance.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_instance_group.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_instance_template.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_network.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_route.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_router.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_ssl_policy.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_target_pool.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_url_map.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel.py
+4 −4 lib/ansible/modules/cloud/google/gcp_container_cluster.py
+4 −4 lib/ansible/modules/cloud/google/gcp_container_node_pool.py
+4 −4 lib/ansible/modules/cloud/google/gcp_dns_managed_zone.py
+4 −4 lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py
+4 −4 lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py
+4 −4 lib/ansible/modules/cloud/google/gcp_pubsub_topic.py
+4 −4 lib/ansible/modules/cloud/google/gcp_spanner_database.py
+4 −4 lib/ansible/modules/cloud/google/gcp_spanner_instance.py
+3 −3 lib/ansible/modules/cloud/google/gcp_sql_database.py
+3 −3 lib/ansible/modules/cloud/google/gcp_sql_instance.py
+3 −3 lib/ansible/modules/cloud/google/gcp_sql_user.py
+4 −4 lib/ansible/modules/cloud/google/gcp_storage_bucket.py
+4 −4 lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py
2 changes: 1 addition & 1 deletion build/terraform
5 changes: 3 additions & 2 deletions templates/ansible/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,14 @@ def unwrap_resource(result, module):
<% end -%>
<%=
lines(method_decl('return_if_object', ['module', 'response',
('kind' if object.kind?)]))
('kind' if object.kind?),
'allow_not_found=False']))
-%>
<% if object.return_if_object -%>
<%= lines(indent(object.return_if_object, 4)) -%>
<% else # if object.return_if_object -%>
# If not found, return nothing.
if response.status_code == 404:
if allow_not_found and response.status_code == 404:
return None

# If no content, return nothing.
Expand Down
16 changes: 7 additions & 9 deletions templates/ansible/transport.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
<% if object.kind? -%>
def fetch_resource(module, link, kind):
<%=
method_decl('fetch_resource', ['module', 'link', ('kind' if object.kind?),
'allow_not_found=True'])
%>
auth = GcpSession(module, <%= quote_string(prod_name) -%>)
return return_if_object(module, auth.get(link), kind)
<% else # object.kind? -%>
def fetch_resource(module, link):
auth = GcpSession(module, <%= quote_string(prod_name) -%>)
return return_if_object(module, auth.get(link))

<% end # object.kind? -%>
return <%= method_call('return_if_object', ['module', 'auth.get(link)',
('kind' if object.kind?),
'allow_not_found']) %>

<% unless object.self_link_query.nil? -%>

Expand Down

0 comments on commit 95c110b

Please sign in to comment.