Skip to content

Commit

Permalink
fix the issue #31
Browse files Browse the repository at this point in the history
  • Loading branch information
wjo1212 committed Jun 7, 2018
1 parent 7dba112 commit 63fc96d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
32 changes: 27 additions & 5 deletions aliyunlogcli/cli_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,33 @@ def main():

# process normal log command
if arguments.get('log', False):
access_id, access_key, endpoint, jmes_filter, format_output, decode_output = load_config(system_options)
decode_output = _to_string_list(decode_output) # convert decode to list if any
try:
access_id, access_key, endpoint, jmes_filter, format_output, decode_output = load_config(system_options)

decode_output = _to_string_list(decode_output) # convert decode to list if any

method_name, args = normalize_inputs(arguments, method_types)
if not (endpoint and access_id and access_key):
raise IncompleteAccountInfoError("endpoint, access_id or key is not configured")

except IncompleteAccountInfoError as ex:
print("""
Error!
The default account is not configured or the command doesn't have a well-configured account passed.
Fix it by either configuring a default account as:
> aliyunlog configure <access_id> <access-key> <endpoint>
or use option --client-name to specify a well-configured account as:
> aliyunlog configure <access_id> <access-key> <endpoint> <user-bj>
> aliyunlog log ..... --client-name=user-bj
Refer to https://aliyun-log-cli.readthedocs.io/en/latest/tutorials/tutorial_configure_cli_en.html for more info.
""")
exit(2)

method_name, args = normalize_inputs(arguments, method_types)
assert endpoint and access_id and access_key, ValueError("endpoint, access_id or key is not configured")
client = LogClient(endpoint, access_id, access_key)
client.set_user_agent(USER_AGENT)

Expand All @@ -217,7 +239,7 @@ def main():
show_result(data, format_output)
else:
print(ex)
exit(2)
exit(3)

# process configure command
elif arguments.get('configure', False):
Expand Down
4 changes: 3 additions & 1 deletion aliyunlogcli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jmespath
from jmespath.exceptions import ParseError
import logging
from .exceptions import IncompleteAccountInfoError

LOG_CLIENT_METHOD_BLACK_LIST = (r'_.+', r'\w+acl', 'set_source', 'delete_shard', 'heart_beat',
'set_user_agent', 'get_unicode', 'list_logstores'
Expand Down Expand Up @@ -136,7 +137,8 @@ def load_config(system_options):
format_output = system_options.get('format-output', format_output)
decode_output = system_options.get('decode-output', decode_output)

assert access_id and access_key and endpoint, ValueError("Access id/key or endpoint is empty!")
if not (access_id and access_key and endpoint):
raise IncompleteAccountInfoError("Access id/key or endpoint is empty!")

# load jmes filter from cmd
jmes_filter = system_options.get('jmes-filter', '')
Expand Down
7 changes: 7 additions & 0 deletions aliyunlogcli/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CLIExceptionBase(Exception): pass


class ConfigurationError(CLIExceptionBase): pass


class IncompleteAccountInfoError(ConfigurationError): pass
2 changes: 1 addition & 1 deletion aliyunlogcli/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

__version__ = '0.1.12'
__version__ = '0.1.13'
from aliyun.log.version import USER_AGENT as SDK_USER_AGENT
USER_AGENT = 'log-cli-v-' + __version__ + ", " + SDK_USER_AGENT

0 comments on commit 63fc96d

Please sign in to comment.