Skip to content

Commit

Permalink
Rename endpoint to access
Browse files Browse the repository at this point in the history
  • Loading branch information
dheyay committed Sep 5, 2024
1 parent 3f9b9d4 commit e757449
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Subscription status api
Feature: Access status api

@uses.config.contract_token
Scenario Outline: Subscription api when attached/unattached
Scenario Outline: Access api when attached/unattached
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed
When I attach `contract_token` with sudo
When I set the machine token overlay to the following yaml:
Expand All @@ -16,7 +16,8 @@ Feature: Subscription status api
name: "TestAAName"
machineId: "TestMId"
"""
When I run `pro api u.pro.subscription.v1` with sudo
When I verify root and non-root `pro api u.pro.access.v1` calls have the same output
When I run `pro api u.pro.access.v1` with sudo
Then API data field output matches regexp:
"""
{
Expand Down Expand Up @@ -44,12 +45,13 @@ Feature: Subscription status api
"meta": {
"environment_vars": []
},
"type": "Subscription"
"type": "Access"
}
"""
When I run `pro detach --assume-yes` with sudo
Then the machine is unattached
When I run `pro api u.pro.subscription.v1` with sudo
When I verify root and non-root `pro api u.pro.access.v1` calls have the same output
When I run `pro api u.pro.access.v1` with sudo
Then API data field output matches regexp:
"""
{
Expand Down Expand Up @@ -77,7 +79,7 @@ Feature: Subscription status api
"meta": {
"environment_vars": []
},
"type": "Subscription"
"type": "Access"
}
"""

Expand Down
2 changes: 1 addition & 1 deletion features/api/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Feature: Client behaviour for the API endpoints
@arm64
Scenario Outline: all API endpoints can be imported individually
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed
When I run `python3 -c "from uaclient.api.u.pro.access.v1 import access"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.attach.auto.configure_retry_service.v1 import configure_retry_service"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.attach.auto.full_auto_attach.v1 import full_auto_attach"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.attach.auto.should_auto_attach.v1 import should_auto_attach"` as non-root
Expand All @@ -22,7 +23,6 @@ Feature: Client behaviour for the API endpoints
When I run `python3 -c "from uaclient.api.u.pro.services.list.v1 import list"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.status.enabled_services.v1 import enabled_services"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.status.is_attached.v1 import is_attached"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.subscription.v1 import subscription"` as non-root
When I run `python3 -c "from uaclient.api.u.pro.version.v1 import version"` as non-root
When I run `python3 -c "from uaclient.api.u.security.package_manifest.v1 import package_manifest"` as non-root
When I run `python3 -c "from uaclient.api.u.unattended_upgrades.status.v1 import status"` as non-root
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion uaclient/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from uaclient.version import check_for_new_version

VALID_ENDPOINTS = [
"u.pro.access.v1",
"u.pro.version.v1",
"u.pro.attach.auto.configure_retry_service.v1",
"u.pro.attach.auto.full_auto_attach.v1",
Expand All @@ -34,7 +35,6 @@
"u.pro.services.list.v1",
"u.pro.status.enabled_services.v1",
"u.pro.status.is_attached.v1",
"u.pro.subscription.v1",
"u.apt_news.current_news.v1",
"u.security.package_manifest.v1",
"u.unattended_upgrades.status.v1",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(
self.name = name


class SubscriptionResult(DataObject, AdditionalInfo):
class AccessResult(DataObject, AdditionalInfo):
fields = [
Field("contract", ContractInfo, doc="Contract Information"),
Field("account", AccountInfo, doc="Account information"),
Expand Down Expand Up @@ -138,16 +138,17 @@ def __init__(
self.machine_is_attached = machine_is_attached


def subscription() -> SubscriptionResult:
return _subscription(UAConfig())
def access() -> AccessResult:
return _access(UAConfig())


def _subscription(cfg: UAConfig) -> SubscriptionResult:
def _access(cfg: UAConfig) -> AccessResult:
"""
Returns the Ubuntu Pro subscription information for the machine.
Returns the Ubuntu Pro access information for the machine including
the account and product information.
"""
if not _is_attached(cfg).is_attached:
return SubscriptionResult(
return AccessResult(
contract=ContractInfo(
created_at="",
id="",
Expand Down Expand Up @@ -201,7 +202,7 @@ def _subscription(cfg: UAConfig) -> SubscriptionResult:
# Subscription Result
activity_id = machine_token_file.activity_id or ""
machine_is_attached = True
return SubscriptionResult(
return AccessResult(
contract=contract,
account=account,
machine_id=machineTokenInfo["machineId"],
Expand All @@ -212,21 +213,21 @@ def _subscription(cfg: UAConfig) -> SubscriptionResult:

endpoint = APIEndpoint(
version="v1",
name="Subscription",
fn=_subscription,
name="Access",
fn=_access,
options_cls=None,
)

_doc = {
"introduced_in": "35",
"requires_network": False,
"example_python": """
from uaclient.api.u.pro.subscription.v1 import subscription
result = subscription()
from uaclient.api.u.pro.access.v1 import access
result = access()
""", # noqa: E501
"result_class": SubscriptionResult,
"result_class": AccessResult,
"exceptions": [],
"example_cli": "pro api u.pro.subscription.v1",
"example_cli": "pro api u.pro.access.v1",
"example_json": """
{
"attributes": {
Expand All @@ -252,7 +253,7 @@ def _subscription(cfg: UAConfig) -> SubscriptionResult:
"meta": {
"environment_vars": []
},
"type": "Subscription"
"type": "Access"
}
""",
}
24 changes: 12 additions & 12 deletions uaclient/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
util,
version,
)
from uaclient.api.u.pro.access.v1 import _access
from uaclient.api.u.pro.config.v1 import _config
from uaclient.api.u.pro.status.is_attached.v1 import _is_attached
from uaclient.api.u.pro.subscription.v1 import _subscription
from uaclient.config import UAConfig
from uaclient.contract import get_available_resources, get_contract_information
from uaclient.defaults import ATTACH_FAIL_DATE_FORMAT, PRINT_WRAP_WIDTH
Expand Down Expand Up @@ -217,29 +217,29 @@ def _attached_status(cfg: UAConfig) -> Dict[str, Any]:

response = copy.deepcopy(DEFAULT_STATUS)
machine_token_file = machine_token.get_machine_token_file(cfg)
subscriptionInfo = _subscription(cfg)
accessInfo = _access(cfg)
tech_support_level = UserFacingStatus.INAPPLICABLE.value
support_level = subscriptionInfo.contract.tech_support_level
support_level = accessInfo.contract.tech_support_level
if support_level:
tech_support_level = support_level
response.update(
{
"machine_id": subscriptionInfo.machine_id,
"machine_id": accessInfo.machine_id,
"attached": True,
"origin": subscriptionInfo.contract.origin,
"origin": accessInfo.contract.origin,
"notices": notices.list() or [],
"contract": {
"id": subscriptionInfo.contract.id,
"name": subscriptionInfo.contract.name,
"created_at": subscriptionInfo.contract.created_at,
"products": subscriptionInfo.contract.products,
"id": accessInfo.contract.id,
"name": accessInfo.contract.name,
"created_at": accessInfo.contract.created_at,
"products": accessInfo.contract.products,
"tech_support_level": tech_support_level, # noqa
},
"account": subscriptionInfo.account.to_dict(),
"account": accessInfo.account.to_dict(),
}
)
response["expires"] = subscriptionInfo.contract.expires
response["effective"] = subscriptionInfo.contract.effective
response["expires"] = accessInfo.contract.expires
response["effective"] = accessInfo.contract.effective

resources = machine_token_file.machine_token.get("availableResources")
if not resources:
Expand Down

0 comments on commit e757449

Please sign in to comment.