Skip to content

Commit b323c5b

Browse files
author
Yue Tu
committed
change 2FA_enabled back to bool
1 parent 0a13c8a commit b323c5b

File tree

7 files changed

+19
-22
lines changed

7 files changed

+19
-22
lines changed

src/sagemaker/estimator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def __init__(
993993
results in cloning the repo specified in 'repo', then checkout the 'master' branch, and checkout
994994
the specified commit.
995995
``2FA_enabled``, ``username``, ``password`` and ``token`` are for authentication purpose.
996-
``2FA_enabled`` must be 'True' or 'False' if it is provided. If ``2FA_enabled`` is not provided,
996+
``2FA_enabled`` must be ``True`` or ``False`` if it is provided. If ``2FA_enabled`` is not provided,
997997
we consider 2FA as disabled. For GitHub and other Git repos, when ssh urls are provided, it does not
998998
make a difference whether 2FA is enabled or disabled; an ssh passphrase should be in local storage.
999999
When https urls are provided: if 2FA is disabled, then either token or username+password will

src/sagemaker/git_utils.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def git_clone_repo(git_config, entry_point, source_dir=None, dependencies=None):
2525
and set ``entry_point``, ``source_dir`` and ``dependencies`` to the right file or directory in the repo cloned.
2626
2727
Args:
28-
git_config (dict[str, str]): Git configurations used for cloning files, including ``repo``, ``branch``,
28+
git_config (dict[str, object]): Git configurations used for cloning files, including ``repo``, ``branch``,
2929
``commit``, ``2FA_enabled``, ``username``, ``password`` and ``token``. The fields are optional except
3030
``repo``. If ``branch`` is not specified, master branch will be used. If ``commit`` is not specified,
3131
the latest commit in the required branch will be used. ``2FA_enabled``, ``username``, ``password`` and
3232
``token`` are for authentication purpose.
33-
``2FA_enabled`` must be 'True' or 'False' if it is provided. If ``2FA_enabled`` is not provided, we
33+
``2FA_enabled`` must be ``True`` or ``False`` if it is provided. If ``2FA_enabled`` is not provided, we
3434
consider 2FA as disabled. For GitHub and other Git repos, when ssh urls are provided, it does not make a
3535
difference whether 2FA is enabled or disabled; an ssh passphrase should be in local storage. When
3636
https urls are provided: if 2FA is disabled, then either token or username+password will be used for
@@ -97,14 +97,11 @@ def _validate_git_config(git_config):
9797
if "repo" not in git_config:
9898
raise ValueError("Please provide a repo for git_config.")
9999
for key in git_config:
100-
if key in git_config and not isinstance(git_config[key], six.string_types):
100+
if key == "2FA_enabled":
101+
if not isinstance(git_config["2FA_enabled"], bool):
102+
raise ValueError("Please enter a bool type for 2FA_enabled'.")
103+
elif not isinstance(git_config[key], six.string_types):
101104
raise ValueError("'{}' must be a string.".format(key))
102-
if (
103-
"2FA_enabled" in git_config
104-
and git_config["2FA_enabled"] != "True"
105-
and git_config["2FA_enabled"] != "False"
106-
):
107-
raise ValueError("Please enter 'True' or 'False' for 2FA_enabled'.")
108105

109106

110107
def _generate_and_run_clone_command(git_config, dest_dir):
@@ -140,7 +137,7 @@ def _clone_command_for_github_like(git_config, dest_dir):
140137
raise ValueError("Invalid Git url provided.")
141138
if is_ssh:
142139
_clone_command_for_github_like_ssh(git_config, dest_dir)
143-
elif "2FA_enabled" in git_config and git_config["2FA_enabled"] == "True":
140+
elif "2FA_enabled" in git_config and git_config["2FA_enabled"] is True:
144141
_clone_command_for_github_like_https_2fa_enabled(git_config, dest_dir)
145142
else:
146143
_clone_command_for_github_like_https_2fa_disabled(git_config, dest_dir)

src/sagemaker/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def __init__(
534534
results in cloning the repo specified in 'repo', then checkout the 'master' branch, and checkout
535535
the specified commit.
536536
``2FA_enabled``, ``username``, ``password`` and ``token`` are for authentication purpose.
537-
``2FA_enabled`` must be 'True' or 'False' if it is provided. If ``2FA_enabled`` is not provided,
537+
``2FA_enabled`` must be ``True`` or ``False`` if it is provided. If ``2FA_enabled`` is not provided,
538538
we consider 2FA as disabled. For GitHub and other Git repos, when ssh urls are provided, it does not
539539
make a difference whether 2FA is enabled or disabled; an ssh passphrase should be in local storage.
540540
When https urls are provided: if 2FA is disabled, then either token or username+password will

tests/integ/test_git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_git_support_with_mxnet(sagemaker_local_session):
8787
"repo": PRIVATE_GIT_REPO,
8888
"branch": PRIVATE_BRANCH,
8989
"commit": PRIVATE_COMMIT,
90-
"2FA_enabled": "False",
90+
"2FA_enabled": False,
9191
"username": "git-support-test",
9292
"password": "passw0rd@ %",
9393
}
@@ -152,7 +152,7 @@ def test_git_support_with_sklearn(sagemaker_local_session, sklearn_full_version)
152152
"repo": PRIVATE_GIT_REPO_2FA,
153153
"branch": PRIVATE_BRANCH_2FA,
154154
"commit": PRIVATE_COMMIT_2FA,
155-
"2FA_enabled": "True",
155+
"2FA_enabled": True,
156156
"token": PRIVATE_REPO_TOKEN,
157157
}
158158
source_dir = "sklearn"

tests/unit/test_estimator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ def test_git_support_with_token_2fa(git_clone_repo, sagemaker_session):
10661066
"branch": PRIVATE_BRANCH,
10671067
"commit": PRIVATE_COMMIT,
10681068
"token": "my-token",
1069-
"2FA_enabled": "True",
1069+
"2FA_enabled": True,
10701070
}
10711071
entry_point = "entry_point"
10721072
fw = DummyFramework(

tests/unit/test_git_utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def test_git_clone_repo_with_token_no_2fa(isfile, mkdtemp, check_call):
214214
"branch": PRIVATE_BRANCH,
215215
"commit": PRIVATE_COMMIT,
216216
"token": "08c13d80a861f37150cb5c64520bfe14a85ca191",
217-
"2FA_enabled": "False",
217+
"2FA_enabled": False,
218218
}
219219
entry_point = "entry_point"
220220
env = os.environ.copy()
@@ -244,7 +244,7 @@ def test_git_clone_repo_with_token_2fa(isfile, mkdtemp, check_call):
244244
"repo": PRIVATE_GIT_REPO,
245245
"branch": PRIVATE_BRANCH,
246246
"commit": PRIVATE_COMMIT,
247-
"2FA_enabled": "True",
247+
"2FA_enabled": True,
248248
"username": "username",
249249
"token": "08c13d80a861f37150cb5c64520bfe14a85ca191",
250250
}
@@ -325,7 +325,7 @@ def test_git_clone_repo_with_token_2fa_unnecessary_creds_provided(isfile, mkdtem
325325
"repo": PRIVATE_GIT_REPO,
326326
"branch": PRIVATE_BRANCH,
327327
"commit": PRIVATE_COMMIT,
328-
"2FA_enabled": "True",
328+
"2FA_enabled": True,
329329
"username": "username",
330330
"token": "08c13d80a861f37150cb5c64520bfe14a85ca191",
331331
}
@@ -363,7 +363,7 @@ def test_git_clone_repo_with_username_and_password_wrong_creds(mkdtemp, check_ca
363363
"repo": PRIVATE_GIT_REPO,
364364
"branch": PRIVATE_BRANCH,
365365
"commit": PRIVATE_COMMIT,
366-
"2FA_enabled": "False",
366+
"2FA_enabled": False,
367367
"username": "username",
368368
"password": "wrong-password",
369369
}
@@ -387,7 +387,7 @@ def test_git_clone_repo_with_token_wrong_creds(mkdtemp, check_call):
387387
"repo": PRIVATE_GIT_REPO,
388388
"branch": PRIVATE_BRANCH,
389389
"commit": PRIVATE_COMMIT,
390-
"2FA_enabled": "False",
390+
"2FA_enabled": False,
391391
"token": "wrong-token",
392392
}
393393
entry_point = "entry_point"
@@ -410,7 +410,7 @@ def test_git_clone_repo_with_and_token_2fa_wrong_creds(mkdtemp, check_call):
410410
"repo": PRIVATE_GIT_REPO,
411411
"branch": PRIVATE_BRANCH,
412412
"commit": PRIVATE_COMMIT,
413-
"2FA_enabled": "False",
413+
"2FA_enabled": False,
414414
"token": "wrong-token",
415415
}
416416
entry_point = "entry_point"

tests/unit/test_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def test_git_support_with_token_2fa(tar_and_upload_dir, git_clone_repo, sagemake
717717
"branch": PRIVATE_BRANCH,
718718
"commit": PRIVATE_COMMIT,
719719
"token": "my-token",
720-
"2FA_enabled": "True",
720+
"2FA_enabled": True,
721721
}
722722
model = DummyFrameworkModelForGit(
723723
sagemaker_session=sagemaker_session, entry_point=entry_point, git_config=git_config

0 commit comments

Comments
 (0)