Skip to content

Commit

Permalink
Merge pull request #375 from aiven/acutaia/EH-829/remove-avn-account-…
Browse files Browse the repository at this point in the history
…authentication-method
  • Loading branch information
dogukancagatay authored Dec 21, 2023
2 parents dce793a + 90080c4 commit a87f8c8
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 128 deletions.
91 changes: 0 additions & 91 deletions aiven/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from aiven.client.connection_info.kafka import KafkaCertificateConnectionInfo, KafkaSASLConnectionInfo
from aiven.client.connection_info.pg import PGConnectionInfo
from aiven.client.connection_info.redis import RedisConnectionInfo
from aiven.client.pretty import TableLayout
from aiven.client.speller import suggest
from argparse import ArgumentParser
from ast import literal_eval
Expand All @@ -34,16 +33,6 @@
import sys
import time

AUTHENTICATION_METHOD_COLUMNS = [
"account_id",
"authentication_method_enabled",
"authentication_method_id",
"authentication_method_name",
"authentication_method_type",
"state",
"create_time",
"update_time",
]
USER_GROUP_COLUMNS = [
"user_group_name",
"user_group_id",
Expand Down Expand Up @@ -683,86 +672,6 @@ def _parse_auth_config_options(config_cmdline: Sequence[str], config_file: Seque
options[name] = value
return options

@arg.json
@arg.account_id
@arg("-n", "--name", required=True, help="Authentication method name")
@arg(
"-t",
"--type",
required=True,
help="Authentication method type",
choices=["saml"],
)
@arg.config_cmdline
@arg.config_file
def account__authentication_method__create(self) -> None:
"""Create new account authentication method"""
options = self._parse_auth_config_options(self.args.config_cmdline, self.args.config_file)
method = self.client.create_account_authentication_method(
self.args.account_id,
method_name=self.args.name,
method_type=self.args.type,
options=options,
)
acs_url = "https://api.aiven.io/v1/sso/saml/account/{}/method/{}/acs".format(
self.args.account_id, method["authentication_method_id"]
)
metadata_url = "https://api.aiven.io/v1/sso/saml/account/{}/method/{}/metadata".format(
self.args.account_id, method["authentication_method_id"]
)
acs_key = "ACS (Single Sign On / Recipient) URL"
metadata_key = "Metadata URL"
method[acs_key] = acs_url
method[metadata_key] = metadata_url
table_layout: TableLayout = [AUTHENTICATION_METHOD_COLUMNS, acs_key, metadata_key]
self.print_response(method, json=self.args.json, single_item=True, table_layout=table_layout)

@arg.json
@arg.account_id
@arg.authentication_id
@arg("-n", "--name", help="New name for the authentication method")
@arg("--enable", help="Enable the authentication method", action="store_true")
@arg("--disable", help="Disable the authentication method", action="store_true")
@arg.config_cmdline
@arg.config_file
def account__authentication_method__update(self) -> None:
"""Update an account authentication method"""
if self.args.enable and self.args.disable:
raise argx.UserError("Only set at most one of --enable and --disable")
enable = None
if self.args.enable:
enable = True
elif self.args.disable:
enable = False
options = self._parse_auth_config_options(self.args.config_cmdline, self.args.config_file)
account = self.client.update_account_authentication_method(
self.args.account_id,
self.args.authentication_id,
method_enable=enable,
method_name=self.args.name,
options=options,
)
self.print_response(
account,
json=self.args.json,
single_item=True,
table_layout=AUTHENTICATION_METHOD_COLUMNS,
)

@arg.account_id
@arg.authentication_id
def account__authentication_method__delete(self) -> None:
"""Delete an account authentication method"""
self.client.delete_account_authentication_method(self.args.account_id, self.args.authentication_id)
print("Deleted")

@arg.json
@arg.account_id
def account__authentication_method__list(self) -> None:
"""Lists all current account authentication methods"""
methods = self.client.get_account_authentication_methods(self.args.account_id)
self.print_response(methods, json=self.args.json, table_layout=AUTHENTICATION_METHOD_COLUMNS)

@arg.json
@arg.account_id
def account__team__list(self) -> None:
Expand Down
1 change: 0 additions & 1 deletion aiven/client/cliarg.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def wrapped(self: CommandLineTool) -> T:


arg.account_id = arg("account_id", help="Account identifier")
arg.authentication_id = arg("authentication_id", help="Account authentication method identifier")
arg.billing_address = arg("--billing-address", help="Physical billing address for invoices")
arg.billing_currency = arg("--billing-currency", help="Currency for charges")
arg.billing_extra_text = arg(
Expand Down
36 changes: 0 additions & 36 deletions aiven/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,42 +1618,6 @@ def update_account(self, account_id: str, account_name: str) -> Mapping:
def get_accounts(self) -> Mapping:
return self.verify(self.get, "/account", result_key="accounts")

def create_account_authentication_method(
self, account_id: str, method_name: str, method_type: str, options: Mapping[str, str] | None = None
) -> dict:
body = dict(options) if options else {}
body["authentication_method_name"] = method_name
body["authentication_method_type"] = method_type
path = self.build_path("account", account_id, "authentication")
return self.verify(self.post, path, body=body, result_key="authentication_method")

def delete_account_authentication_method(self, account_id: str, authentication_id: str) -> Mapping:
return self.verify(
self.delete,
self.build_path("account", account_id, "authentication", authentication_id),
)

def update_account_authentication_method(
self,
account_id: str,
authentication_id: str,
method_name: str | None = None,
method_enable: bool | None = None,
options: Mapping[str, str] | None = None,
) -> Mapping:
body: dict[str, Any] = dict(options) if options else {}
if method_name is not None:
body["authentication_method_name"] = method_name
if method_enable is not None:
body["authentication_method_enabled"] = method_enable

path = self.build_path("account", account_id, "authentication", authentication_id)
return self.verify(self.put, path, body=body, result_key="authentication_method")

def get_account_authentication_methods(self, account_id: str) -> Sequence[dict[str, Any]]:
path = self.build_path("account", account_id, "authentication")
return self.verify(self.get, path, result_key="authentication_methods")

def create_project(
self,
project: str,
Expand Down

0 comments on commit a87f8c8

Please sign in to comment.