SamWheating commented on a change in pull request #9159:
URL: https://github.com/apache/airflow/pull/9159#discussion_r436680469



##########
File path: airflow/providers/google/cloud/hooks/gdm.py
##########
@@ -0,0 +1,103 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from typing import Any, Dict, List, Optional
+
+from googleapiclient.discovery import build
+
+from airflow.exceptions import AirflowException
+from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+
+
+class GoogleDeploymentManagerHook(GoogleBaseHook):  # pylint: 
disable=abstract-method
+    """
+    Interact with Google Cloud Deployment Manager using the Google Cloud 
Platform connection.
+    This allows for scheduled and programatic inspection and deletion fo 
resources managed by GDM.
+    """
+
+    def __init__(self, gcp_conn_id='google_cloud_default', delegate_to=None):
+        super(GoogleDeploymentManagerHook, self).__init__(gcp_conn_id, 
delegate_to=delegate_to)
+
+    def get_conn(self):
+        """
+        Returns a Google Deployment Manager service object.
+
+        :rtype: googleapiclient.discovery.Resource
+        """
+        http_authorized = self._authorize()
+        return build('deploymentmanager', 'v2', http=http_authorized, 
cache_discovery=False)
+
+    @GoogleBaseHook.fallback_to_default_project_id
+    def list_deployments(self, project_id: Optional[str] = None,  # pylint: 
disable=too-many-arguments
+                         deployment_filter: Optional[str] = None,
+                         max_results: Optional[int] = None,
+                         order_by: Optional[str] = None,
+                         page_token: Optional[str] = None) -> List[Dict[str, 
Any]]:
+        """
+        Lists deployments in a google cloud project.
+
+        :param project_id: The project ID for this request.
+        :type project_id: str
+        :param deployment_filter: A filter expression which limits resources 
returned in the response.
+        :type filter: str
+        :param max_results: The maximum number of results to return
+        :type max_results: Optional[int]
+        :param order_by: A field name to order by, ex: "creationTimestamp desc"
+        :type order_by: Optional[str]
+        :param page_token: specifies a page_token to use
+        :type page_token: str

Review comment:
       This option comes straight from the 
[API](https://cloud.google.com/deployment-manager/docs/reference/latest/deployments/list#parameters):
   
   _maxResults, unsigned integer:_
   _The maximum number of results per page that should be returned. If the 
number of available results is larger than maxResults, Compute Engine returns a 
nextPageToken that can be used to get the next page of results in subsequent 
list requests. Acceptable values are 0 to 500, inclusive. (Default: 500)_
   
   So there's no way to get all of the entries, though I would assume its super 
rare  to have >500 deployments in the same project. Can we leave this param in 
just so the hook doesn't become unusable past 500 deployments?

##########
File path: airflow/providers/google/cloud/hooks/gdm.py
##########
@@ -0,0 +1,103 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from typing import Any, Dict, List, Optional
+
+from googleapiclient.discovery import build
+
+from airflow.exceptions import AirflowException
+from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+
+
+class GoogleDeploymentManagerHook(GoogleBaseHook):  # pylint: 
disable=abstract-method
+    """
+    Interact with Google Cloud Deployment Manager using the Google Cloud 
Platform connection.
+    This allows for scheduled and programatic inspection and deletion fo 
resources managed by GDM.
+    """
+
+    def __init__(self, gcp_conn_id='google_cloud_default', delegate_to=None):
+        super(GoogleDeploymentManagerHook, self).__init__(gcp_conn_id, 
delegate_to=delegate_to)
+
+    def get_conn(self):
+        """
+        Returns a Google Deployment Manager service object.
+
+        :rtype: googleapiclient.discovery.Resource
+        """
+        http_authorized = self._authorize()
+        return build('deploymentmanager', 'v2', http=http_authorized, 
cache_discovery=False)
+
+    @GoogleBaseHook.fallback_to_default_project_id
+    def list_deployments(self, project_id: Optional[str] = None,  # pylint: 
disable=too-many-arguments
+                         deployment_filter: Optional[str] = None,
+                         max_results: Optional[int] = None,
+                         order_by: Optional[str] = None,
+                         page_token: Optional[str] = None) -> List[Dict[str, 
Any]]:
+        """
+        Lists deployments in a google cloud project.
+
+        :param project_id: The project ID for this request.
+        :type project_id: str
+        :param deployment_filter: A filter expression which limits resources 
returned in the response.
+        :type filter: str
+        :param max_results: The maximum number of results to return
+        :type max_results: Optional[int]
+        :param order_by: A field name to order by, ex: "creationTimestamp desc"
+        :type order_by: Optional[str]
+        :param page_token: specifies a page_token to use
+        :type page_token: str

Review comment:
       Oh now I see what you mean - thanks for the examples, that really helps. 
Will update and push changes now. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to