Skip to content

Commit 01b783a

Browse files
authored
BugFix/typo in documentation (#451)
1 parent 09d471a commit 01b783a

File tree

4 files changed

+89
-58
lines changed

4 files changed

+89
-58
lines changed

ads/common/auth.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,29 +158,29 @@ def set_auth(
158158
... )
159159
>>> ads.set_auth("security_token", config=config) # Set security token authentication from provided config
160160
161-
>>> singer = oci.signer.Signer(
161+
>>> signer = oci.signer.Signer(
162162
... user=ocid1.user.oc1..<unique_ID>,
163163
... fingerprint=<fingerprint>,
164164
... tenancy=ocid1.tenancy.oc1..<unique_ID>,
165165
... region=us-ashburn-1,
166166
... private_key_content=<private key content>,
167167
... )
168-
>>> ads.set_auth(singer=singer) # Set api keys authentication with private key content based on provided signer
168+
>>> ads.set_auth(signer=signer) # Set api keys authentication with private key content based on provided signer
169169
170-
>>> singer = oci.signer.Signer(
170+
>>> signer = oci.signer.Signer(
171171
... user=ocid1.user.oc1..<unique_ID>,
172172
... fingerprint=<fingerprint>,
173173
... tenancy=ocid1.tenancy.oc1..<unique_ID>,
174174
... region=us-ashburn-1,
175175
... private_key_file_location=<private key content>,
176176
... )
177-
>>> ads.set_auth(singer=singer) # Set api keys authentication with private key file location based on provided signer
177+
>>> ads.set_auth(signer=signer) # Set api keys authentication with private key file location based on provided signer
178178
179-
>>> singer = oci.auth.signers.get_resource_principals_signer()
180-
>>> ads.auth.create_signer(config={}, singer=signer) # resource principals authentication dictionary created
179+
>>> signer = oci.auth.signers.get_resource_principals_signer()
180+
>>> ads.auth.create_signer(config={}, signer=signer) # resource principals authentication dictionary created
181181
182182
>>> signer_callable = oci.auth.signers.ResourcePrincipalsFederationSigner
183-
>>> ads.set_auth(signer_callable=signer_callable) # Set resource principal federation singer callable
183+
>>> ads.set_auth(signer_callable=signer_callable) # Set resource principal federation signer callable
184184
185185
>>> signer_callable = oci.auth.signers.InstancePrincipalsSecurityTokenSigner
186186
>>> signer_kwargs = dict(log_requests=True) # will log the request url and response data when retrieving
@@ -400,7 +400,7 @@ def create_signer(
400400
... }
401401
>>> auth = ads.auth.create_signer(config=config) # api_key type of authentication dictionary with private key file location created based on provided config
402402
403-
>>> singer = oci.auth.signers.get_resource_principals_signer()
403+
>>> signer = oci.auth.signers.get_resource_principals_signer()
404404
>>> auth = ads.auth.create_signer(config={}, signer=signer) # resource principals authentication dictionary created
405405
406406
>>> auth = ads.auth.create_signer(auth_type='instance_principal') # instance principals authentication dictionary created
@@ -517,7 +517,7 @@ def get_signer(
517517
) -> Dict:
518518
"""
519519
Provides config and signer based given parameters. If oci_config (api key config file location) and
520-
oci_profile specified new signer will ge generated. Else singer of a type specified in OCI_CLI_AUTH
520+
oci_profile specified new signer will ge generated. Else signer of a type specified in OCI_CLI_AUTH
521521
environment variable will be used to generate signer and return. If OCI_CLI_AUTH not set,
522522
resource principal signer will be provided. Accepted values for OCI_CLI_AUTH: 'api_key',
523523
'instance_principal', 'resource_principal'.
@@ -929,9 +929,9 @@ def register(cls, signer_type: str, signer: Any) -> None:
929929
Parameters
930930
----------
931931
signer_type: str
932-
Singer type to be registers
932+
signer type to be registers
933933
signer: RecordParser
934-
A new Singer class to be registered.
934+
A new signer class to be registered.
935935
936936
Returns
937937
-------

docs/source/user_guide/cli/authentication.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ The ``~/.oci/config`` configuration allow for multiple configurations to be stor
109109
key_content=private_key_content,
110110
)
111111
ads.set_auth(config = config) # default signer is set to API Keys with private key content
112-
112+
113113
ads.set_auth("resource_principal") # default signer is set to resource principal authentication
114114
ads.set_auth("instance_principal") # default signer is set to instance principal authentication
115115
ads.set_auth("security_token") # default signer is set to security token authentication
116116
117-
singer = oci.auth.signers.ResourcePrincipalsFederationSigner()
118-
ads.set_auth(config={}, singer=signer) # default signer is set to ResourcePrincipalsFederationSigner
117+
signer = oci.auth.signers.ResourcePrincipalsFederationSigner()
118+
ads.set_auth(config={}, signer=signer) # default signer is set to ResourcePrincipalsFederationSigner
119119
120120
signer_callable = oci.auth.signers.ResourcePrincipalsFederationSigner
121121
ads.set_auth(signer_callable=signer_callable) # default signer is set ResourcePrincipalsFederationSigner callable
@@ -167,8 +167,8 @@ More signers can be created using the ``create_signer()`` method. With the ``aut
167167
auth = ads.auth.create_signer("security_token", profile="test_session")
168168
169169
# Example 3. Provide a ResourcePrincipalsFederationSigner object
170-
singer = oci.auth.signers.ResourcePrincipalsFederationSigner()
171-
auth = ads.auth.create_signer(config={}, singer=signer)
170+
signer = oci.auth.signers.ResourcePrincipalsFederationSigner()
171+
auth = ads.auth.create_signer(config={}, signer=signer)
172172
173173
# Example 4. Create signer that uses instance principals with log requests enabled
174174
signer_callable = oci.auth.signers.InstancePrincipalsSecurityTokenSigner

tests/unitary/default_setup/auth/test_auth.py

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"fingerprint": "test_fingerprint",
4343
"tenancy": "test_tenancy",
4444
"region": "us-ashburn-1",
45-
"key_file": "test_key_file"
45+
"key_file": "test_key_file",
4646
}
4747

4848

@@ -52,7 +52,11 @@ class TestEDAMixin(TestCase):
5252
@mock.patch("os.path.exists")
5353
@mock.patch("oci.signer.load_private_key_from_file")
5454
def test_set_auth_overwrite_profile(
55-
self, mock_load_key_file, mock_path_exists, mock_config_from_file, mock_validate_config
55+
self,
56+
mock_load_key_file,
57+
mock_path_exists,
58+
mock_config_from_file,
59+
mock_validate_config,
5660
):
5761
mock_config_from_file.return_value = MOCK_CONFIG_FROM_FILE
5862
set_auth(profile="TEST")
@@ -65,7 +69,11 @@ def test_set_auth_overwrite_profile(
6569
@mock.patch("os.path.exists")
6670
@mock.patch("oci.signer.load_private_key_from_file")
6771
def test_set_auth_overwrite_config_location(
68-
self, mock_load_key_file, mock_path_exists, mock_config_from_file, mock_validate_config
72+
self,
73+
mock_load_key_file,
74+
mock_path_exists,
75+
mock_config_from_file,
76+
mock_validate_config,
6977
):
7078
mock_config_from_file.return_value = MOCK_CONFIG_FROM_FILE
7179
mock_path_exists.return_value = True
@@ -77,14 +85,18 @@ def test_set_auth_overwrite_config_location(
7785
@mock.patch("oci.config.validate_config")
7886
@mock.patch("oci.config.from_file")
7987
@mock.patch("oci.signer.Signer")
80-
def test_api_keys_using_test_profile(self, mock_signer, mock_config_from_file, mock_validate_config):
88+
def test_api_keys_using_test_profile(
89+
self, mock_signer, mock_config_from_file, mock_validate_config
90+
):
8191
api_keys("test_path", "TEST_PROFILE")
8292
mock_config_from_file.assert_called_with("test_path", "TEST_PROFILE")
8393

8494
@mock.patch("oci.config.validate_config")
8595
@mock.patch("oci.config.from_file")
8696
@mock.patch("oci.signer.Signer")
87-
def test_api_keys_using_default_profile(self, mock_signer, mock_config_from_file, mock_validate_config):
97+
def test_api_keys_using_default_profile(
98+
self, mock_signer, mock_config_from_file, mock_validate_config
99+
):
88100
api_keys("test_path")
89101
mock_config_from_file.assert_called_with("test_path", "DEFAULT")
90102

@@ -108,14 +120,16 @@ def test_resource_principal(self, mock_rp_signer):
108120

109121
@mock.patch("oci.config.validate_config")
110122
@mock.patch("oci.signer.load_private_key")
111-
def test_set_auth_with_key_content(self, mock_load_private_key, mock_validate_config):
123+
def test_set_auth_with_key_content(
124+
self, mock_load_private_key, mock_validate_config
125+
):
112126
set_auth(
113127
config={
114128
"user": "test_user",
115129
"fingerprint": "test_fingerprint",
116130
"tenancy": "test_tenancy",
117131
"region": "us-ashburn-1",
118-
"key_content": "test_key_content"
132+
"key_content": "test_key_content",
119133
}
120134
)
121135
signer = default_signer()
@@ -141,7 +155,12 @@ def tearDown(self) -> None:
141155
@mock.patch("oci.signer.Signer")
142156
@mock.patch("oci.logging.LoggingManagementClient")
143157
def test_api_key_auth_with_logging(
144-
self, client, mock_signer, mock_path_exists, mock_config_from_file, mock_validate_config
158+
self,
159+
client,
160+
mock_signer,
161+
mock_path_exists,
162+
mock_config_from_file,
163+
mock_validate_config,
145164
):
146165
"""Tests initializing OCIMixin with default auth.
147166
Without any explicit config, the client should be initialized from DEFAULT OCI API key config.
@@ -264,9 +283,9 @@ def test_set_auth_value_errors(self):
264283
with pytest.raises(ValueError):
265284
AuthFactory().signerGenerator("not_existing_iam_type")
266285

267-
def test_register_singer(self):
268-
AuthFactory().register("new_singer_type", "signer_class")
269-
assert "new_singer_type" in AuthFactory.classes.keys()
286+
def test_register_signer(self):
287+
AuthFactory().register("new_signer_type", "signer_class")
288+
assert "new_signer_type" in AuthFactory.classes.keys()
270289

271290
@mock.patch("os.path.exists")
272291
@mock.patch(
@@ -281,7 +300,11 @@ def test_register_singer(self):
281300
@mock.patch("oci.config.validate_config")
282301
@mock.patch("oci.signer.load_private_key_from_file")
283302
def test_api_key_create_signer(
284-
self, mock_load_key_file, mock_config_from_file, mock_path_exists, mock_validate_config
303+
self,
304+
mock_load_key_file,
305+
mock_config_from_file,
306+
mock_path_exists,
307+
mock_validate_config,
285308
):
286309
"""
287310
Testing api key setup with set_auth() and getting it with default_signer()
@@ -358,7 +381,6 @@ def test_instance_principal_create_signer(self, mock_ip_signer):
358381
@mock.patch("ads.common.auth.AuthFactory")
359382
@mock.patch("oci.auth.signers.InstancePrincipalsSecurityTokenSigner")
360383
def test_create_signer(self, mock_ip_signer, mock_signer_generator):
361-
362384
auth = create_signer(signer="test")
363385
assert auth["signer"] == "test"
364386

@@ -389,7 +411,7 @@ def test_set_auth_multiple_times_with(
389411
mock_config_from_file,
390412
mock_rp_signer,
391413
mock_ip_signer,
392-
mock_validate_config
414+
mock_validate_config,
393415
):
394416
"""
395417
Testing behaviour when multiple times invoked set_auth() with different parameters and validate,
@@ -537,41 +559,39 @@ def test_with_set_auth_returns_error(self):
537559

538560

539561
class TestSecurityToken(TestCase):
540-
541562
@mock.patch("oci.auth.signers.SecurityTokenSigner.__init__")
542563
@mock.patch("oci.signer.load_private_key_from_file")
543564
@mock.patch("ads.common.auth.SecurityToken._read_security_token_file")
544565
@mock.patch("ads.common.auth.SecurityToken._validate_and_refresh_token")
545566
def test_security_token(
546567
self,
547-
mock_validate_and_refresh_token,
568+
mock_validate_and_refresh_token,
548569
mock_read_security_token_file,
549570
mock_load_private_key_from_file,
550-
mock_security_token_signer
571+
mock_security_token_signer,
551572
):
552573
config = {
553574
"fingerprint": "test_fingerprint",
554575
"tenancy": "test_tenancy",
555576
"region": "us-ashburn-1",
556577
"key_file": "test_key_file",
557-
"generic_headers": [1,2,3],
558-
"body_headers": [4,5,6]
578+
"generic_headers": [1, 2, 3],
579+
"body_headers": [4, 5, 6],
559580
}
560581

561582
with pytest.raises(
562583
ValueError,
563-
match="Parameter `security_token_file` must be provided for using `security_token` authentication."
584+
match="Parameter `security_token_file` must be provided for using `security_token` authentication.",
564585
):
565586
signer = security_token(
566587
oci_config=config,
567-
client_kwargs={"test_client_key":"test_client_value"}
588+
client_kwargs={"test_client_key": "test_client_value"},
568589
)
569590

570591
config["security_token_file"] = "test_security_token"
571592
mock_security_token_signer.return_value = None
572593
signer = security_token(
573-
oci_config=config,
574-
client_kwargs={"test_client_key":"test_client_value"}
594+
oci_config=config, client_kwargs={"test_client_key": "test_client_value"}
575595
)
576596

577597
mock_validate_and_refresh_token.assert_called_with(config)
@@ -593,50 +613,52 @@ def test_security_token(
593613
@mock.patch("oci.auth.security_token_container.SecurityTokenContainer.__init__")
594614
@mock.patch("ads.common.auth.SecurityToken._read_security_token_file")
595615
def test_validate_and_refresh_token(
596-
self,
597-
mock_read_security_token_file,
616+
self,
617+
mock_read_security_token_file,
598618
mock_security_token_container,
599619
mock_valid,
600620
mock_time,
601621
mock_get_jwt,
602-
mock_system
622+
mock_system,
603623
):
604624
security_token = SecurityToken(
605625
args={
606626
"oci_config_location": DEFAULT_LOCATION,
607-
"oci_key_profile": "test_profile"
627+
"oci_key_profile": "test_profile",
608628
}
609629
)
610630
mock_security_token_container.return_value = None
611-
631+
612632
mock_valid.return_value = False
613633
configuration = {
614634
"fingerprint": "test_fingerprint",
615635
"tenancy": "test_tenancy",
616636
"region": "us-ashburn-1",
617637
"key_file": "test_key_file",
618638
"security_token_file": "test_security_token",
619-
"generic_headers": [1,2,3],
620-
"body_headers": [4,5,6]
639+
"generic_headers": [1, 2, 3],
640+
"body_headers": [4, 5, 6],
621641
}
622642
with pytest.raises(
623643
SecurityTokenError,
624-
match="Security token has expired. Call `oci session authenticate` to generate new session."
644+
match="Security token has expired. Call `oci session authenticate` to generate new session.",
625645
):
626646
security_token._validate_and_refresh_token(configuration)
627-
647+
628648
mock_valid.return_value = True
629649
mock_time.return_value = 1
630-
mock_get_jwt.return_value = {"exp" : 1}
650+
mock_get_jwt.return_value = {"exp": 1}
631651
mock_system.return_value = 1
632-
652+
633653
security_token._validate_and_refresh_token(configuration)
634-
654+
635655
mock_read_security_token_file.assert_called_with("test_security_token")
636656
mock_security_token_container.assert_called()
637657
mock_time.assert_called()
638658
mock_get_jwt.assert_called()
639-
mock_system.assert_called_with(f"oci session refresh --config-file {DEFAULT_LOCATION} --profile test_profile")
659+
mock_system.assert_called_with(
660+
f"oci session refresh --config-file {DEFAULT_LOCATION} --profile test_profile"
661+
)
640662

641663
@mock.patch("builtins.open")
642664
@mock.patch("os.path.isfile")
@@ -645,8 +667,7 @@ def test_read_security_token_file(self, mock_isfile, mock_open):
645667

646668
mock_isfile.return_value = False
647669
with pytest.raises(
648-
ValueError,
649-
match="Invalid `security_token_file`. Specify a valid path."
670+
ValueError, match="Invalid `security_token_file`. Specify a valid path."
650671
):
651672
security_token._read_security_token_file("test_security_token")
652673

0 commit comments

Comments
 (0)