Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.

fix: fix client.quotas() method - #24

Merged
busunkim96 merged 6 commits into
masterfrom
fix-21
Oct 9, 2020
Merged

fix: fix client.quotas() method#24
busunkim96 merged 6 commits into
masterfrom
fix-21

Conversation

@busunkim96

@busunkim96 busunkim96 commented Oct 5, 2020

Copy link
Copy Markdown
Contributor

client.quotas() now properly handles quota resource with whitelistedKeySpecs.

This also removes the str -> int conversion for values in quotas. The API returns integers so there is no need to do the conversion. See https://cloud.google.com/dns/docs/reference/v1/projects#resource

Fixes #21 🦕

client.quotas() now properly handles quota resources
with ``whitelistedKeySpecs``.
client.quotas() now properly handles quota resources
with ``whitelistedKeySpecs``.
@busunkim96
busunkim96 requested a review from a team October 5, 2020 19:51
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 5, 2020
Comment thread tests/unit/test_client.py
@busunkim96 busunkim96 added the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 5, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 5, 2020
@busunkim96
busunkim96 requested review from crwilcox and tswast October 5, 2020 21:14
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.

: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 :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

4 participants