-
Notifications
You must be signed in to change notification settings - Fork 13
Bugfix/defaultp not used #15
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
Changes from all commits
54fee8e
83d0887
a701469
4374a25
64f85d4
adf09c4
8972e93
d1065d7
cb7158e
9cf1440
fbfd12c
83c723a
995aac2
ee82ba4
862414e
6860160
08d793a
0ead656
6c46c9f
9aa27ca
2041476
a2d074b
60a87f2
340e48c
75934cf
80fd81f
ac2d172
9145c6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.4.0" | ||
__version__ = "0.4.1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
print_set_profile_help, | ||
print_no_existing_profile_message, | ||
) | ||
from code42cli.sdk_client import validate_connection | ||
|
||
|
||
class Code42Profile(object): | ||
|
@@ -33,7 +34,7 @@ def ignore_ssl_error(self): | |
return self._profile[ConfigAccessor.IGNORE_SSL_ERRORS_KEY] | ||
|
||
def get_password(self): | ||
pwd = password.get_password(self.name) | ||
pwd = password.get_stored_password(self.name) | ||
if not pwd: | ||
pwd = password.get_password_from_prompt() | ||
return pwd | ||
|
@@ -91,7 +92,7 @@ def show_profile(args): | |
print(u"\t* {0} = {1}".format(ConfigAccessor.USERNAME_KEY, profile.username)) | ||
print(u"\t* {0} = {1}".format(ConfigAccessor.AUTHORITY_KEY, profile.authority_url)) | ||
print(u"\t* {0} = {1}".format(ConfigAccessor.IGNORE_SSL_ERRORS_KEY, profile.ignore_ssl_error)) | ||
if password.get_password(args.profile_name) is not None: | ||
if password.get_stored_password(profile.name) is not None: | ||
print(u"\t* A password is set.") | ||
print(u"") | ||
|
||
|
@@ -109,7 +110,15 @@ def set_profile(args): | |
|
||
def prompt_for_password_reset(args): | ||
"""Securely prompts for your password and then stores it using keyring.""" | ||
password.set_password_from_prompt(args.profile_name) | ||
profile = get_profile(args.profile_name) | ||
new_password = password.get_password_from_prompt() | ||
if not validate_connection(profile.authority_url, profile.username, new_password): | ||
print_error( | ||
"Your password was not saved because your credentials failed to validate. " | ||
"Check your network connection and the spelling of your username and server URL." | ||
) | ||
exit(1) | ||
password.set_password(profile.name, new_password) | ||
|
||
|
||
def list_profiles(*args): | ||
|
@@ -130,7 +139,7 @@ def use_profile(args): | |
try: | ||
accessor.switch_default_profile(args.profile_name) | ||
except Exception as ex: | ||
print_error(ex) | ||
print_error(str(ex)) | ||
exit(1) | ||
|
||
|
||
|
@@ -198,9 +207,10 @@ def _verify_args_for_set(args): | |
missing_values = not args.c42_username and not args.c42_authority_url | ||
if missing_values: | ||
try: | ||
profile = get_profile(args.profile_name) | ||
accessor = get_config_accessor() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alanag13 This fixed an issue where you would get two error messages when only one made sense during |
||
profile = Code42Profile(accessor.get_profile(args.profile_name)) | ||
missing_values = not profile.username and not profile.authority_url | ||
except SystemExit: | ||
except Exception: | ||
missing_values = True | ||
|
||
if missing_values: | ||
|
@@ -231,10 +241,10 @@ def _missing_default_profile(args): | |
profile_name_arg_is_none = ( | ||
args.profile_name is None or args.profile_name == ConfigAccessor.DEFAULT_VALUE | ||
) | ||
return profile_name_arg_is_none and not _default_profile_exists() | ||
return profile_name_arg_is_none and not _default_profile_exist() | ||
|
||
|
||
def _default_profile_exists(): | ||
def _default_profile_exist(): | ||
try: | ||
accessor = get_config_accessor() | ||
profile = Code42Profile(accessor.get_profile()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from py42 import debug_level | ||
from py42 import settings | ||
from py42.sdk import SDK | ||
|
||
from code42cli.util import print_error | ||
|
||
|
||
def create_sdk(profile, is_debug_mode): | ||
if is_debug_mode: | ||
settings.debug_level = debug_level.DEBUG | ||
try: | ||
password = profile.get_password() | ||
return SDK.create_using_local_account(profile.authority_url, profile.username, password) | ||
except Exception: | ||
print_error( | ||
u"Invalid credentials or host address. " | ||
u"Verify your profile is set up correctly and that you are supplying the correct password." | ||
) | ||
exit(1) | ||
|
||
|
||
def validate_connection(authority_url, username, password): | ||
try: | ||
SDK.create_using_local_account(authority_url, username, password) | ||
return True | ||
except: | ||
print(username, password, authority_url) | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,24 +63,24 @@ def _verify_timestamp_order(min_timestamp, max_timestamp): | |
raise ValueError(u"Begin date cannot be after end date") | ||
|
||
|
||
def _parse_timestamp(date_tuple): | ||
def _parse_timestamp(date_and_time): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this method only get called if a min or max timestamp is present? if not, it looks like there would be some problem if |
||
try: | ||
date_str = _join_date_tuple(date_tuple) | ||
date_format = u"%Y-%m-%d" if len(date_tuple) == 1 else u"%Y-%m-%d %H:%M:%S" | ||
date_str = _join_date_and_time(date_and_time) | ||
date_format = u"%Y-%m-%d" if len(date_and_time) == 1 else u"%Y-%m-%d %H:%M:%S" | ||
time = datetime.strptime(date_str, date_format) | ||
except ValueError: | ||
raise ValueError(_FORMAT_VALUE_ERROR_MESSAGE) | ||
return convert_datetime_to_timestamp(time) | ||
|
||
|
||
def _join_date_tuple(date_tuple): | ||
if not date_tuple: | ||
def _join_date_and_time(date_and_time): | ||
if not date_and_time: | ||
return None | ||
date_str = date_tuple[0] | ||
if len(date_tuple) == 1: | ||
date_str = date_and_time[0] | ||
if len(date_and_time) == 1: | ||
return date_str | ||
if len(date_tuple) == 2: | ||
date_str = "{0} {1}".format(date_str, date_tuple[1]) | ||
if len(date_and_time) == 2: | ||
date_str = "{0} {1}".format(date_str, date_and_time[1]) | ||
else: | ||
raise ValueError(_FORMAT_VALUE_ERROR_MESSAGE) | ||
return date_str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will get the default profile if
args.profile_name
isNone
. Thus, profile.name will not beNone
anymore.