Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions google/cloud/dns/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,23 @@ def quotas(self):

:rtype: mapping
:returns: keys for the mapping correspond to those of the ``quota``
sub-mapping of the project resource.
sub-mapping of the project resource. ``kind`` is stripped
from the results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this to the comment. It seems we always stripped this away silently :)

"""
path = "/projects/%s" % (self.project,)
resp = self._connection.api_request(method="GET", path=path)

return {
key: int(value) for key, value in resp["quota"].items() if key != "kind"
}
quotas = resp["quota"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an advantage to getting the quotas and popping kind over a list comprehension? It appears the issue was the type conversion to int?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method started failing because there's a new key whitelistedKeySpecs in quota. str -> int conversion failed since it's a list

https://cloud.google.com/dns/docs/reference/v1/projects#resource

  "quota": {
    "kind": "dns#quota",
    "managedZones": integer,
    "rrsetsPerManagedZone": integer,
    "rrsetAdditionsPerChange": integer,
    "rrsetDeletionsPerChange": integer,
    "totalRrdataSizePerChange": integer,
    "resourceRecordsPerRrset": integer,
    "dnsKeysPerManagedZone": integer,
    "whitelistedKeySpecs": [
      {
        "kind": "dns#dnsKeySpec",
        "keyType": string,
        "algorithm": string,
        "keyLength": unsigned integer
      }
    ],
    "networksPerManagedZone": integer,
    "managedZonesPerNetwork": integer,
    "policies": integer,
    "networksPerPolicy": integer,
    "targetNameServersPerPolicy": integer,
    "targetNameServersPerManagedZone": integer
  }

Each entrywhitelistedKeySpecs also has a 'kind' that needs to be stripped. I found it easier to pop than to edit the existing list comprehension.

# Remove the key "kind"
# https://cloud.google.com/dns/docs/reference/v1/projects#resource
quotas.pop("kind", None)
if "whitelistedKeySpecs" in quotas:
# whitelistedKeySpecs is a list of dicts that represent keyspecs
# Remove "kind" here as well
for key_spec in quotas["whitelistedKeySpecs"]:
key_spec.pop("kind", None)

return quotas

def list_zones(self, max_results=None, page_token=None):
"""List zones for the project associated with this client.
Expand Down
29 changes: 29 additions & 0 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 Google LLC
#
# Licensed 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
#
# https://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 google.cloud import dns


def test_quota():
client = dns.Client()

quotas = client.quotas()

# check that kind is properly stripped from the resource
assert "kind" not in quotas
for keyspec in quotas["whitelistedKeySpecs"]:
assert "kind" not in keyspec
34 changes: 21 additions & 13 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ def test_quotas_defaults(self):
TOTAL_SIZE = 67890
DATA = {
"quota": {
"managedZones": str(MANAGED_ZONES),
"resourceRecordsPerRrset": str(RRS_PER_RRSET),
"rrsetsPerManagedZone": str(RRSETS_PER_ZONE),
"rrsetAdditionsPerChange": str(RRSET_ADDITIONS),
"rrsetDeletionsPerChange": str(RRSET_DELETIONS),
"totalRrdataSizePerChange": str(TOTAL_SIZE),
"managedZones": MANAGED_ZONES,
"resourceRecordsPerRrset": RRS_PER_RRSET,
"rrsetsPerManagedZone": RRSETS_PER_ZONE,
"rrsetAdditionsPerChange": RRSET_ADDITIONS,
"rrsetDeletionsPerChange": RRSET_DELETIONS,
"totalRrdataSizePerChange": TOTAL_SIZE,
}
Comment thread
busunkim96 marked this conversation as resolved.
}
CONVERTED = {key: int(value) for key, value in DATA["quota"].items()}
Expand All @@ -159,17 +159,25 @@ def test_quotas_w_kind_key(self):
TOTAL_SIZE = 67890
DATA = {
"quota": {
"managedZones": str(MANAGED_ZONES),
"resourceRecordsPerRrset": str(RRS_PER_RRSET),
"rrsetsPerManagedZone": str(RRSETS_PER_ZONE),
"rrsetAdditionsPerChange": str(RRSET_ADDITIONS),
"rrsetDeletionsPerChange": str(RRSET_DELETIONS),
"totalRrdataSizePerChange": str(TOTAL_SIZE),
"managedZones": MANAGED_ZONES,
"resourceRecordsPerRrset": RRS_PER_RRSET,
"rrsetsPerManagedZone": RRSETS_PER_ZONE,
"rrsetAdditionsPerChange": RRSET_ADDITIONS,
"rrsetDeletionsPerChange": RRSET_DELETIONS,
"totalRrdataSizePerChange": TOTAL_SIZE,
"whitelistedKeySpecs": [
{
"keyType": "keySigning",
"algorithm": "rsasha512",
"keyLength": 2048,
}
],
}
}
CONVERTED = {key: int(value) for key, value in DATA["quota"].items()}
CONVERTED = DATA["quota"]
WITH_KIND = {"quota": DATA["quota"].copy()}
WITH_KIND["quota"]["kind"] = "dns#quota"
WITH_KIND["quota"]["whitelistedKeySpecs"][0]["kind"] = "dns#dnsKeySpec"
creds = _make_credentials()
client = self._make_one(self.PROJECT, creds)
conn = client._connection = _Connection(WITH_KIND)
Expand Down