Skip to content

Commit

Permalink
Update Scopes enum to support down to Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Mar 27, 2023
1 parent 5335f35 commit 173a3ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions analytix/oidc.py
Expand Up @@ -59,7 +59,7 @@
import re
import typing as t
from dataclasses import dataclass
from enum import StrEnum
from enum import Enum
from http import server
from pathlib import Path
from urllib.parse import parse_qsl, urlencode
Expand All @@ -77,7 +77,7 @@
_log = logging.getLogger(__name__)


class Scopes(StrEnum):
class Scopes(Enum):
"""An enum for API scopes.
The possible values are:
Expand Down Expand Up @@ -402,7 +402,7 @@ def auth_uri(secrets: Secrets, port: int, scopes: Scopes) -> AuthUriT:
"nonce": state_token(),
"response_type": "code",
"redirect_uri": secrets.redirect_uris[-1] + (f":{port}" if port != 80 else ""),
"scope": scopes,
"scope": scopes.value,
"state": state_token(),
"access_type": "offline",
}
Expand Down
7 changes: 4 additions & 3 deletions analytix/queries.py
Expand Up @@ -165,13 +165,14 @@ def validate(self, scopes: Scopes) -> None:
self.metrics = [
m for m in data.ALL_METRICS_ORDERED if m in self.rtype.metrics.values
]
_log.debug("Metrics set to: " + ", ".join(self.metrics))

if Scopes.MONETARY_READONLY not in scopes:
if Scopes.MONETARY_READONLY.value not in scopes.value:
self.metrics = [m for m in self.metrics if m not in data.REVENUE_METRICS]
elif Scopes.READONLY not in scopes:
elif Scopes.READONLY.value not in scopes.value:
self.metrics = [m for m in self.metrics if m in data.REVENUE_METRICS]

_log.debug("Metrics set to: " + ", ".join(self.metrics))

diff = {o.strip("-") for o in self.sort_options} - set(self.metrics)
if diff:
raise InvalidRequest.non_matching_sort_options(diff)
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Expand Up @@ -141,7 +141,7 @@ def create_auth_params():
"nonce": "34c5f166f6abb229ee092be1e7e92ca71434bcb1a27ba0664cd2fea834d85927",
"response_type": "code",
"redirect_uri": "http://localhost:8080",
"scope": oidc.Scopes.ALL,
"scope": "https://www.googleapis.com/auth/yt-analytics.readonly https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
"state": "34c5f166f6abb229ee092be1e7e92ca71434bcb1a27ba0664cd2fea834d85927",
"access_type": "offline",
}
Expand Down

0 comments on commit 173a3ff

Please sign in to comment.