Skip to content

Commit

Permalink
docs: add api docs to magic revoke
Browse files Browse the repository at this point in the history
  • Loading branch information
orndorffgrant committed Jun 20, 2024
1 parent 9f1acef commit 2ef5f22
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions uaclient/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
IncompatibleServiceStopsEnable,
InvalidProImage,
LockHeldError,
MagicAttachTokenAlreadyActivated,
MagicAttachTokenError,
MagicAttachUnavailable,
NonAutoAttachImageError,
NonRootUserError,
Expand All @@ -28,6 +30,8 @@
"EntitlementNotFoundError",
"InvalidProImage",
"LockHeldError",
"MagicAttachTokenAlreadyActivated",
"MagicAttachTokenError",
"MagicAttachUnavailable",
"NonAutoAttachImageError",
"NonRootUserError",
Expand Down
59 changes: 58 additions & 1 deletion uaclient/api/u/pro/attach/magic/revoke/v1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from uaclient.api import exceptions
from uaclient.api.api import APIEndpoint
from uaclient.api.data_types import AdditionalInfo
from uaclient.config import UAConfig
Expand All @@ -7,7 +8,11 @@

class MagicAttachRevokeOptions(DataObject):
fields = [
Field("magic_token", StringDataValue),
Field(
"magic_token",
StringDataValue,
doc="The Token provided by the initiate endpoint.",
),
]

def __init__(self, magic_token):
Expand All @@ -25,6 +30,9 @@ def revoke(options: MagicAttachRevokeOptions) -> MagicAttachRevokeResult:
def _revoke(
options: MagicAttachRevokeOptions, cfg: UAConfig
) -> MagicAttachRevokeResult:
"""
This endpoint revokes a Magic Attach Token.
"""
contract = UAContractClient(cfg)
contract.revoke_magic_attach_token(options.magic_token)

Expand All @@ -37,3 +45,52 @@ def _revoke(
fn=_revoke,
options_cls=MagicAttachRevokeOptions,
)

_doc = {
"introduced_in": "27.11",
"example_python": """
from uaclient.api.u.pro.attach.magic.revoke.v1 import MagicAttachRevokeOptions, revoke
options = MagicAttachWaitOptions(magic_token="<magic_token>")
result = revoke(options)
""", # noqa: E501
"result_cls": MagicAttachRevokeResult,
"exceptions": [
(
exceptions.ConnectivityError,
(
"Raised if it is not possible to connect to the contracts"
" service."
),
),
(
exceptions.ContractAPIError,
(
"Raised if there is an unexpected error in the contracts"
" service interaction."
),
),
(
exceptions.MagicAttachTokenAlreadyActivated,
(
"Raised when trying to revoke a Token which was already"
" activated through the UI."
),
),
(
exceptions.MagicAttachTokenError,
"Raised when an invalid/expired Token is sent.",
),
(
exceptions.MagicAttachUnavailable,
(
"Raised if the Magic Attach service is busy or unavailable at"
" the moment."
),
),
],
"example_cli": "pro api u.pro.attach.magic.revoke.v1 --args magic_token=<token>", # noqa: E501
"example_json": """
{}
""",
}

0 comments on commit 2ef5f22

Please sign in to comment.