diff --git a/features/api/status_subscription.feature b/features/api/access.feature similarity index 84% rename from features/api/status_subscription.feature rename to features/api/access.feature index 363e85f4fa..5afaf03aaa 100644 --- a/features/api/status_subscription.feature +++ b/features/api/access.feature @@ -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 `` `` machine with ubuntu-advantage-tools installed When I attach `contract_token` with sudo When I set the machine token overlay to the following yaml: @@ -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: """ { @@ -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: """ { @@ -77,7 +79,7 @@ Feature: Subscription status api "meta": { "environment_vars": [] }, - "type": "Subscription" + "type": "Access" } """ diff --git a/features/api/api.feature b/features/api/api.feature index adf0dd772e..8b9f24842e 100644 --- a/features/api/api.feature +++ b/features/api/api.feature @@ -3,6 +3,7 @@ Feature: Client behaviour for the API endpoints @arm64 Scenario Outline: all API endpoints can be imported individually Given a `` `` 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 @@ -23,7 +24,6 @@ Feature: Client behaviour for the API endpoints 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.status.notices.v1 import notices"` 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.token_info.v1 import get_token_info"` 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 diff --git a/features/api/status_config.feature b/features/api/config.feature similarity index 100% rename from features/api/status_config.feature rename to features/api/config.feature diff --git a/uaclient/api/api.py b/uaclient/api/api.py index f08058a1b2..e4951c1875 100644 --- a/uaclient/api/api.py +++ b/uaclient/api/api.py @@ -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", @@ -35,7 +36,6 @@ "u.pro.status.enabled_services.v1", "u.pro.status.is_attached.v1", "u.pro.status.notices.v1", - "u.pro.subscription.v1", "u.pro.token_info.v1", "u.apt_news.current_news.v1", "u.security.package_manifest.v1", diff --git a/uaclient/api/u/pro/subscription/__init__.py b/uaclient/api/u/pro/access/__init__.py similarity index 100% rename from uaclient/api/u/pro/subscription/__init__.py rename to uaclient/api/u/pro/access/__init__.py diff --git a/uaclient/api/u/pro/subscription/v1.py b/uaclient/api/u/pro/access/v1.py similarity index 91% rename from uaclient/api/u/pro/subscription/v1.py rename to uaclient/api/u/pro/access/v1.py index 005d9b409c..13689e53bc 100644 --- a/uaclient/api/u/pro/subscription/v1.py +++ b/uaclient/api/u/pro/access/v1.py @@ -69,7 +69,7 @@ def __init__( tech_support_level: Optional[str], origin: Optional[str], effective: Optional[datetime], - expires: Optional[datetime], + expires: Optional[datetime] ): self.created_at = created_at self.id = id @@ -101,7 +101,7 @@ def __init__( created_at: str, external_account_ids: List[str], id: str, - name: str, + name: str ): self.created_at = created_at self.external_account_ids = external_account_ids @@ -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"), @@ -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="", @@ -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"], @@ -212,8 +213,8 @@ def _subscription(cfg: UAConfig) -> SubscriptionResult: endpoint = APIEndpoint( version="v1", - name="Subscription", - fn=_subscription, + name="Access", + fn=_access, options_cls=None, ) @@ -221,12 +222,12 @@ def _subscription(cfg: UAConfig) -> SubscriptionResult: "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": { @@ -252,7 +253,7 @@ def _subscription(cfg: UAConfig) -> SubscriptionResult: "meta": { "environment_vars": [] }, - "type": "Subscription" + "type": "Access" } """, } diff --git a/uaclient/status.py b/uaclient/status.py index f347ce2c26..6753cb9a69 100644 --- a/uaclient/status.py +++ b/uaclient/status.py @@ -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 @@ -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: