Skip to content

Commit

Permalink
billing plans: disassociate from user role and don't list any
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Nov 21, 2023
1 parent 7cf6adc commit b03c4f4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 69 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file.

The format is roughly based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Current: 0.13.x]
-

## [Current: 0.14.x]

- Disassociate billing plans from user roles and don't list any for now ([openEOPlatform/architecture-docs#381](https://github.com/openEOPlatform/architecture-docs/issues/381))


## [0.13.x]

- Fix compatibility with `openeo_driver>=0.75.0` (new `enable_basic_auth` config, which is going to be disabled by default)


Expand Down
2 changes: 1 addition & 1 deletion src/openeo_aggregator/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Optional

__version__ = "0.13.0a1"
__version__ = "0.14.0a1"


def log_version_info(logger: Optional[logging.Logger] = None):
Expand Down
11 changes: 0 additions & 11 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,6 @@ def user_access_validation(self, user: User, request: flask.Request) -> User:
)
if roles:
user.add_roles(r.id for r in roles)
# TODO: better way of determining default_plan?
user.set_default_plan([r.billing_plan for r in roles][-1].name)
else:
_log.warning(f"user_access_validation failure: %r %r", enrollment_error_user_message, {
"user_id": user.user_id,
Expand Down Expand Up @@ -1391,15 +1389,6 @@ def capabilities_billing(self) -> dict:
# TODO #96 check that all upstream back-ends use the same currency (credits)
return {
"currency": "credits",
"plans": [
{
"name": p.name,
"description": p.description,
"url": p.url,
"paid": p.paid,
}
for p in openeo_aggregator.egi.OPENEO_PLATFORM_BILLING_PLANS
]
}

def postprocess_capabilities(self, capabilities: dict) -> dict:
Expand Down
43 changes: 3 additions & 40 deletions src/openeo_aggregator/egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,6 @@
BillingPlan = namedtuple("BillingPlan", ["name", "description", "url", "paid"])


_BILLING_PLAN_30DAY_TRIAL = BillingPlan(
name="30day-trial",
description="openEO.cloud 30 day free trial plan (experimental)",
url="https://docs.openeo.cloud/join/free_trial.html",
paid=False,
)

_BILLING_PLAN_EARLY_ADOPTER = BillingPlan(
name="early-adopter",
description="openEO.cloud early adopter plan",
url="https://openeo.cloud/early-adopters/",
paid=True,
)

# TODO: avoid using generic billing plan
_BILLING_PLAN_GENERIC = BillingPlan(
name="generic",
description="openEO.cloud generic plan",
url=None,
paid=True,
)

OPENEO_PLATFORM_BILLING_PLANS = [
_BILLING_PLAN_30DAY_TRIAL,
_BILLING_PLAN_EARLY_ADOPTER,
_BILLING_PLAN_GENERIC,
]


# Regex to parse eduperson_entitlement strings,
# like for example "urn:mace:egi.eu:group:vo.openeo.cloud:role=early_adopter#aai.egi.eu"
_eduperson_entitlement_regex = re.compile(
Expand Down Expand Up @@ -80,28 +51,20 @@ class UserRole:
"_id",
# Normalized version of role name (for case/whitespace-insensitive comparison)
"_normalized",
# Associated billing plan
"_billing_plan",
]

def __init__(self, title: str, billing_plan: BillingPlan = _BILLING_PLAN_GENERIC):
def __init__(self, title: str):
self._title = title
self._id = "".join(
w.title() if w.islower() else w
for w in self._title.replace("-", " ").replace("_", " ").split()
)
self._normalized = self.normalize_role(self._title)
self._billing_plan = billing_plan


@property
def id(self) -> str:
return self._id

@property
def billing_plan(self) -> BillingPlan:
return self._billing_plan

@staticmethod
def normalize_role(role: Union[str, None]) -> Union[str, None]:
if role:
Expand Down Expand Up @@ -137,8 +100,8 @@ def extract_roles(self, entitlements: List[str]) -> List[UserRole]:
# Based on https://github.com/openEOPlatform/documentation/issues/48
OPENEO_PLATFORM_USER_ROLES = OpeneoPlatformUserRoles(
[
UserRole("30-Day-Trial", billing_plan=_BILLING_PLAN_30DAY_TRIAL),
UserRole("Early_Adopter", billing_plan=_BILLING_PLAN_EARLY_ADOPTER),
UserRole("30-Day-Trial"),
UserRole("Early_Adopter"),
# TODO: define a dedicated billing plan for each user role?
UserRole("Basic_User"),
UserRole("Professional_User"),
Expand Down
1 change: 0 additions & 1 deletion tests/test_egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class TestUserRole:
def test_basic(self):
role = UserRole("Foo")
assert role.id == "Foo"
assert role.billing_plan.name == "generic"
assert role.entitlement_match(
"urn:mace:egi.eu:group:vo.openeo.cloud:role=Foo#aai.egi.eu"
)
Expand Down
20 changes: 6 additions & 14 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ def test_capabilities_validation(self, api100):

def test_billing_plans(self, api100):
capabilities = api100.get("/").assert_status_code(200).json
billing = capabilities["billing"]
assert billing["currency"] == "credits"
plans = {p["name"]: p for p in billing["plans"]}
assert "early-adopter" in plans
assert plans["early-adopter"]["paid"] is True
assert capabilities["billing"] == {
"currency": "credits",
}

def test_deploy_metadata(self, api100):
capabilities = api100.get("/").assert_status_code(200).json
Expand Down Expand Up @@ -449,23 +447,21 @@ def test_oidc_not_enrolled(
assert re.search(warn_regex, warnings)

@pytest.mark.parametrize(
["eduperson_entitlement", "expected_roles", "expected_plan"],
["eduperson_entitlement", "expected_roles"],
[
(
[
"urn:mace:egi.eu:group:vo.openeo.cloud:role=foo#aai.egi.eu",
"urn:mace:egi.eu:group:vo.openeo.cloud:role=30day-trial#aai.egi.eu",
],
["30DayTrial"],
"30day-trial",
),
(
[
"urn:mace:egi.eu:group:vo.openeo.cloud:role=foo#aai.egi.eu",
"urn:mace:egi.eu:group:vo.openeo.cloud:role=early_adopter#aai.egi.eu",
],
["EarlyAdopter"],
"early-adopter",
),
(
[
Expand All @@ -474,14 +470,10 @@ def test_oidc_not_enrolled(
"urn:mace:egi.eu:group:vo.openeo.cloud:role=Platform-developer#aai.egi.eu",
],
["BasicUser", "EarlyAdopter", "PlatformDeveloper"],
"generic",
),
],
)
def test_oidc_enrolled(
self, api100_with_entitlement_check, requests_mock,
eduperson_entitlement, expected_roles, expected_plan,
):
def test_oidc_enrolled(self, api100_with_entitlement_check, requests_mock, eduperson_entitlement, expected_roles):
requests_mock.get("https://egi.test/.well-known/openid-configuration", json={
"userinfo_endpoint": "https://egi.test/userinfo"
})
Expand All @@ -495,7 +487,7 @@ def test_oidc_enrolled(
data = res.json
assert data["user_id"] == "john"
assert data["roles"] == expected_roles
assert data["default_plan"] == expected_plan
assert "default_plan" not in data

@pytest.mark.parametrize(["whitelist", "main_test_oidc_issuer", "success"], [
(["https://egi.test"], "https://egi.test", True),
Expand Down

0 comments on commit b03c4f4

Please sign in to comment.