Skip to content

Commit

Permalink
Merge pull request #255 from aiven/rominf-get_non_none_project
Browse files Browse the repository at this point in the history
Do not raise an error about the missing project in non-auth commands

#255
  • Loading branch information
dmitrii-vasilev committed Jan 17, 2022
2 parents 3c9da94 + 9e3131b commit a8c0dea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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
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

0 comments on commit a8c0dea

Please sign in to comment.