Skip to content

Commit

Permalink
Remove parameters related to billing from avn project create/update c…
Browse files Browse the repository at this point in the history
…ommands [EH-766]

The following parameters are removed from `avn project create/update`
commands.

- `country-code`
- `billing-address`
- `billing-extra-text`
- `billing-currency`
- `vat-id`
- `billing-email`
- `card-id`

[EH-766]
  • Loading branch information
dogukancagatay committed Nov 10, 2023
1 parent bff1450 commit 94328e1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 101 deletions.
41 changes: 9 additions & 32 deletions aiven/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4295,14 +4295,19 @@ def _format_card_info(cls, project: Mapping[str, Any]) -> str:
return "{}/{}".format(project["card_info"]["user_email"], project["card_info"]["card_id"])

def _show_projects(self, projects: Sequence[dict[str, Any]], verbose: bool = True) -> None:
for project in projects:
project["credit_card"] = self._format_card_info(project)
if verbose:
layout: list = [
["project_name", "default_cloud"],
"billing_group_id",
"billing_group_name",
["project_name", "default_cloud", "billing_currency", "vat_id"],
"credit_card",
"billing_address",
"country_code",
]
if any(project["billing_extra_text"] for project in projects):
layout.append("billing_extra_text")
else:
layout = [["project_name", "default_cloud"]]
layout = [["project_name", "default_cloud", "credit_card"]]
self.print_response(projects, json=getattr(self.args, "json", False), table_layout=layout)

def _resolve_parent_id(self, parent_id: str) -> str:
Expand All @@ -4315,7 +4320,6 @@ def _resolve_parent_id(self, parent_id: str) -> str:

@arg("project_name", help="Project name")
@arg("--billing-group-id", help="Billing group ID of the project")
@arg.card_id
@arg.cloud
@arg(
"--no-fail-if-exists",
Expand All @@ -4338,30 +4342,17 @@ def _resolve_parent_id(self, parent_id: str) -> str:
"used by source project instead of creating a new one"
),
)
@arg.country_code
@arg.billing_address
@arg.billing_extra_text
@arg.billing_currency
@arg.vat_id
@arg.billing_email
@arg.tech_email
@arg.parent_id_mandatory
def project__create(self) -> None:
"""Create a project"""
try:
project = self.client.create_project(
account_id=self._resolve_parent_id(self.args.parent_id),
billing_address=self.args.billing_address,
billing_currency=self.args.billing_currency,
billing_extra_text=self.args.billing_extra_text,
billing_group_id=self.args.billing_group_id,
card_id=self.args.card_id,
cloud=self.args.cloud,
copy_from_project=self.args.copy_from_project,
country_code=self.args.country_code,
project=self.args.project_name,
vat_id=self.args.vat_id,
billing_emails=self.args.billing_email,
tech_emails=self.args.tech_email,
use_source_project_billing_group=self.args.use_source_project_billing_group,
)
Expand Down Expand Up @@ -4398,15 +4389,8 @@ def project__list(self) -> None:

@arg.project
@arg("--name", help="New project name")
@arg("--card-id", help="Card ID")
@arg.parent_id
@arg.cloud
@arg.country_code
@arg.billing_address
@arg.billing_extra_text
@arg.billing_currency
@arg.vat_id
@arg.billing_email
@arg.tech_email
def project__update(self) -> None:
"""Update a project"""
Expand All @@ -4415,15 +4399,8 @@ def project__update(self) -> None:
project = self.client.update_project(
new_project_name=self.args.name,
account_id=self._resolve_parent_id(self.args.parent_id) if self.args.parent_id else None,
billing_address=self.args.billing_address,
billing_currency=self.args.billing_currency,
billing_extra_text=self.args.billing_extra_text,
card_id=self.args.card_id,
cloud=self.args.cloud,
country_code=self.args.country_code,
project=project_name,
vat_id=self.args.vat_id,
billing_emails=self.args.billing_email,
tech_emails=self.args.tech_email,
)
except client.Error as ex:
Expand Down
41 changes: 0 additions & 41 deletions aiven/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,20 +1641,12 @@ def create_project(
project: str,
account_id: str,
billing_group_id: str | None = None,
card_id: str | None = None,
cloud: str | None = None,
copy_from_project: str | None = None,
country_code: str | None = None,
billing_address: str | None = None,
billing_currency: str | None = None,
billing_extra_text: str | None = None,
vat_id: str | None = None,
billing_emails: Sequence[str] | None = None,
tech_emails: Sequence[str] | None = None,
use_source_project_billing_group: bool | None = None,
) -> Mapping:
body: dict[str, Any] = {
"card_id": card_id,
"cloud": cloud,
"project": project,
"account_id": account_id,
Expand All @@ -1663,18 +1655,6 @@ def create_project(
body["billing_group_id"] = billing_group_id
if copy_from_project is not None:
body["copy_from_project"] = copy_from_project
if country_code is not None:
body["country_code"] = country_code
if billing_address is not None:
body["billing_address"] = billing_address
if billing_currency is not None:
body["billing_currency"] = billing_currency
if billing_extra_text is not None:
body["billing_extra_text"] = billing_extra_text
if vat_id is not None:
body["vat_id"] = vat_id
if billing_emails is not None:
body["billing_emails"] = [{"email": email} for email in billing_emails]
if tech_emails is not None:
body["tech_emails"] = [{"email": email} for email in tech_emails]
if use_source_project_billing_group is not None:
Expand All @@ -1696,37 +1676,16 @@ def update_project(
project: str,
new_project_name: str | None = None,
account_id: str | None = None,
card_id: str | None = None,
cloud: str | None = None,
country_code: str | None = None,
billing_address: str | None = None,
billing_currency: str | None = None,
billing_extra_text: str | None = None,
vat_id: str | None = None,
billing_emails: Sequence[str] | None = None,
tech_emails: Sequence[str] | None = None,
) -> Mapping:
body: dict[str, Any] = {}
if new_project_name is not None:
body["project_name"] = new_project_name
if account_id is not None:
body["account_id"] = account_id
if card_id is not None:
body["card_id"] = card_id
if cloud is not None:
body["cloud"] = cloud
if country_code is not None:
body["country_code"] = country_code
if billing_address is not None:
body["billing_address"] = billing_address
if billing_currency is not None:
body["billing_currency"] = billing_currency
if billing_extra_text is not None:
body["billing_extra_text"] = billing_extra_text
if vat_id is not None:
body["vat_id"] = vat_id
if billing_emails is not None:
body["billing_emails"] = [{"email": email} for email in billing_emails]
if tech_emails is not None:
body["tech_emails"] = [{"email": email} for email in tech_emails]

Expand Down
28 changes: 0 additions & 28 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,16 +1335,9 @@ def test_project_create__parent_id_requested_correctly() -> None:
aiven_client.create_project.assert_called_with(
account_id=account_id,
project=project_name,
billing_address=None,
billing_currency=None,
billing_extra_text=None,
billing_group_id=None,
card_id=None,
cloud=None,
copy_from_project=None,
country_code=None,
vat_id=None,
billing_emails=None,
tech_emails=None,
use_source_project_billing_group=False,
)
Expand Down Expand Up @@ -1386,16 +1379,9 @@ def test_project_create__parent_id_as_org_id_requested_correctly() -> None:
aiven_client.create_project.assert_called_with(
account_id=account_id,
project=project_name,
billing_address=None,
billing_currency=None,
billing_extra_text=None,
billing_group_id=None,
card_id=None,
cloud=None,
copy_from_project=None,
country_code=None,
vat_id=None,
billing_emails=None,
tech_emails=None,
use_source_project_billing_group=False,
)
Expand Down Expand Up @@ -1431,15 +1417,8 @@ def test_project_update__parent_id_requested_correctly() -> None:
aiven_client.update_project.assert_called_with(
new_project_name=new_project_name,
account_id=account_id,
billing_address=None,
billing_currency=None,
billing_extra_text=None,
card_id=None,
cloud=None,
country_code=None,
project=project_name,
vat_id=None,
billing_emails=None,
tech_emails=None,
)

Expand Down Expand Up @@ -1484,14 +1463,7 @@ def test_project_update__parent_id_as_org_id_requested_correctly() -> None:
aiven_client.update_project.assert_called_with(
new_project_name=new_project_name,
account_id=account_id,
billing_address=None,
billing_currency=None,
billing_extra_text=None,
card_id=None,
cloud=None,
country_code=None,
project=project_name,
vat_id=None,
billing_emails=None,
tech_emails=None,
)

0 comments on commit 94328e1

Please sign in to comment.