Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not raise an error about the missing project in non-auth commands #255

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
short_ver = 2.14.6
short_ver = 2.14.7
long_ver = $(shell git describe --long 2>/dev/null || echo $(short_ver)-0-unknown-g`git describe --always`)
generated = aiven/client/version.py
PYTHON ?= python3
Expand Down
8 changes: 4 additions & 4 deletions aiven/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ def confirm(self, prompt: str = "confirm (y/N)? "):
answer = input(prompt)
return is_truthy(answer)

def get_project(self):
def get_project(self, raise_if_none=True):
"""Return project given as cmdline argument or the default project from config file"""
if getattr(self.args, "project", None) and self.args.project:
return self.args.project
rominf marked this conversation as resolved.
Show resolved Hide resolved
default_project = self.config.get("default_project")
if not default_project:
if raise_if_none and not default_project:
raise argx.UserError(
"Specify project: use --project in the command line or the default_project item in the config file."
)
Expand Down Expand Up @@ -398,7 +398,7 @@ def user__login(self):
if auth_token:
self.client.set_auth_token(auth_token)

project = self.get_project()
project = self.get_project(raise_if_none=False)
projects = self.client.get_projects()
if project and any(p["project_name"] == project for p in projects):
# default project exists
Expand Down Expand Up @@ -575,7 +575,7 @@ def events(self):
@arg.json
def cloud__list(self):
"""List cloud types"""
project = self.get_project()
project = self.get_project(raise_if_none=False)
if project and not self.client.auth_token:
raise argx.UserError("authentication is required to list clouds for a specific project")
self.print_response(self.client.get_clouds(project=project), json=self.args.json)
Expand Down