Skip to content

Commit

Permalink
[ACR] Throw warning when call the misspelled property (Azure#23562)
Browse files Browse the repository at this point in the history
  • Loading branch information
YalinLi0312 authored Mar 18, 2022
1 parent cf1f325 commit 30c2e62
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@
"nypg"
]
},
{
"filename": "sdk/containerregistry/azure-containerregistry/**",
"words": [
"udpated"
]
},
{
"filename": "sdk/formrecognizer/azure-ai-formrecognizer/tests/*.py",
"words": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Licensed under the MIT License.
# ------------------------------------

import warnings
from enum import Enum
from typing import TYPE_CHECKING, Dict, Any, List

Expand Down Expand Up @@ -200,6 +201,14 @@ def _to_generated(self):
can_list=self.can_list,
)

def __getattr__(self, name):
if name == "last_udpated_on":
warnings.warn(
"The property name with a typo called 'last_udpated_on' has been deprecated and will be retired in future versions", # pylint: disable=line-too-long
DeprecationWarning)
return self.last_updated_on
return super().__getattr__(self, name) # pylint: disable=no-member

@property
def created_on(self):
# type: () -> datetime
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: GET
uri: https://fake_url.azurecr.io/acr/v1/library%2Falpine?api-version=2021-07-01
response:
body:
string: '{"errors": [{"code": "UNAUTHORIZED", "message": "authentication required,
visit https://aka.ms/acr/authorization for more information.", "detail": [{"Type":
"repository", "Name": "library/alpine", "Action": "metadata_read"}]}]}'
headers:
access-control-expose-headers:
- Docker-Content-Digest
- WWW-Authenticate
- Link
- X-Ms-Correlation-Request-Id
connection:
- keep-alive
content-length:
- '217'
content-type:
- application/json; charset=utf-8
date:
- Thu, 17 Mar 2022 13:08:48 GMT
docker-distribution-api-version:
- registry/2.0
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
- max-age=31536000; includeSubDomains
www-authenticate:
- Bearer realm="https://fake_url.azurecr.io/oauth2/token",service="fake_url.azurecr.io",scope="fake_scope",error="invalid_token"
x-content-type-options:
- nosniff
status:
code: 401
message: Unauthorized
- request:
body: grant_type=access_token&service=fake_url.azurecr.io&access_token=REDACTED
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '1379'
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/exchange?api-version=2021-07-01
response:
body:
string: '{"refresh_token": "REDACTED"}'
headers:
connection:
- keep-alive
content-type:
- application/json; charset=utf-8
date:
- Thu, 17 Mar 2022 13:08:48 GMT
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
x-ms-ratelimit-remaining-calls-per-second:
- '166.65'
status:
code: 200
message: OK
- request:
body: service=fake_url.azurecr.io&scope=repository%3Alibrary%2Falpine%3Ametadata_read&refresh_token=REDACTED&grant_type=refresh_token
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '1156'
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/token?api-version=2021-07-01
response:
body:
string: '{"access_token": "REDACTED"}'
headers:
connection:
- keep-alive
content-type:
- application/json; charset=utf-8
date:
- Thu, 17 Mar 2022 13:08:49 GMT
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
x-ms-ratelimit-remaining-calls-per-second:
- '166.633333'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: GET
uri: https://fake_url.azurecr.io/acr/v1/library%2Falpine?api-version=2021-07-01
response:
body:
string: '{"registry": "yallacrtests.azurecr.io", "imageName": "library/alpine",
"createdTime": "2022-03-17T12:20:47.2455348Z", "lastUpdateTime": "2022-03-17T12:20:45.8750709Z",
"manifestCount": 8, "tagCount": 1, "changeableAttributes": {"deleteEnabled":
true, "writeEnabled": true, "readEnabled": true, "listEnabled": true}}'
headers:
access-control-expose-headers:
- Docker-Content-Digest
- WWW-Authenticate
- Link
- X-Ms-Correlation-Request-Id
connection:
- keep-alive
content-length:
- '296'
content-type:
- application/json; charset=utf-8
date:
- Thu, 17 Mar 2022 13:08:49 GMT
docker-distribution-api-version:
- registry/2.0
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: GET
uri: https://fake_url.azurecr.io/acr/v1/library%2Falpine?api-version=2021-07-01
response:
body:
string: '{"errors": [{"code": "UNAUTHORIZED", "message": "authentication required,
visit https://aka.ms/acr/authorization for more information.", "detail": [{"Type":
"repository", "Name": "library/alpine", "Action": "metadata_read"}]}]}'
headers:
access-control-expose-headers: X-Ms-Correlation-Request-Id
connection: keep-alive
content-length: '217'
content-type: application/json; charset=utf-8
date: Thu, 17 Mar 2022 13:15:58 GMT
docker-distribution-api-version: registry/2.0
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
www-authenticate: Bearer realm="https://fake_url.azurecr.io/oauth2/token",service="fake_url.azurecr.io",scope="fake_scope",error="invalid_token"
x-content-type-options: nosniff
status:
code: 401
message: Unauthorized
url: https://yallacrtests.azurecr.io/acr/v1/library%2Falpine?api-version=2021-07-01
- request:
body:
access_token: REDACTED
grant_type: !!python/object/apply:azure.containerregistry._generated.models._container_registry_enums.PostContentSchemaGrantType
- access_token
service: yallacrtests.azurecr.io
headers:
Accept:
- application/json
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/exchange?api-version=2021-07-01
response:
body:
string: '{"refresh_token": "REDACTED"}'
headers:
connection: keep-alive
content-type: application/json; charset=utf-8
date: Thu, 17 Mar 2022 13:15:59 GMT
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
transfer-encoding: chunked
x-ms-ratelimit-remaining-calls-per-second: '166.616667'
status:
code: 200
message: OK
url: https://yallacrtests.azurecr.io/oauth2/exchange?api-version=2021-07-01
- request:
body:
grant_type: refresh_token
refresh_token: REDACTED
scope: repository:library/alpine:metadata_read
service: yallacrtests.azurecr.io
headers:
Accept:
- application/json
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/token?api-version=2021-07-01
response:
body:
string: '{"access_token": "REDACTED"}'
headers:
connection: keep-alive
content-type: application/json; charset=utf-8
date: Thu, 17 Mar 2022 13:15:59 GMT
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
transfer-encoding: chunked
x-ms-ratelimit-remaining-calls-per-second: '166.6'
status:
code: 200
message: OK
url: https://yallacrtests.azurecr.io/oauth2/token?api-version=2021-07-01
- request:
body: null
headers:
Accept:
- application/json
User-Agent:
- azsdk-python-azure-containerregistry/1.0.1 Python/3.9.2 (Windows-10-10.0.22000-SP0)
method: GET
uri: https://fake_url.azurecr.io/acr/v1/library%2Falpine?api-version=2021-07-01
response:
body:
string: '{"registry": "yallacrtests.azurecr.io", "imageName": "library/alpine",
"createdTime": "2022-03-17T12:20:47.2455348Z", "lastUpdateTime": "2022-03-17T12:20:45.8750709Z",
"manifestCount": 8, "tagCount": 1, "changeableAttributes": {"deleteEnabled":
true, "writeEnabled": true, "readEnabled": true, "listEnabled": true}}'
headers:
access-control-expose-headers: X-Ms-Correlation-Request-Id
connection: keep-alive
content-length: '296'
content-type: application/json; charset=utf-8
date: Thu, 17 Mar 2022 13:15:59 GMT
docker-distribution-api-version: registry/2.0
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
status:
code: 200
message: OK
url: https://yallacrtests.azurecr.io/acr/v1/library%2Falpine?api-version=2021-07-01
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,13 @@ def test_set_api_version(self, containerregistry_endpoint):

with pytest.raises(ValueError):
client = self.create_registry_client(containerregistry_endpoint, api_version = "2019-08-15")

@acr_preparer()
def test_get_misspell_property(self, containerregistry_endpoint):
client = self.create_registry_client(containerregistry_endpoint)
properties = client.get_repository_properties(ALPINE)

with self.assertWarns(DeprecationWarning):
last_udpated_on = properties.last_udpated_on
last_updated_on = properties.last_updated_on
assert last_udpated_on == last_updated_on
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,13 @@ def test_set_api_version(self, containerregistry_endpoint):

with pytest.raises(ValueError):
client = self.create_registry_client(containerregistry_endpoint, api_version = "2019-08-15")

@acr_preparer()
async def test_get_misspell_property(self, containerregistry_endpoint):
client = self.create_registry_client(containerregistry_endpoint)
properties = await client.get_repository_properties(ALPINE)

with self.assertWarns(DeprecationWarning):
last_udpated_on = properties.last_udpated_on
last_updated_on = properties.last_updated_on
assert last_udpated_on == last_updated_on

0 comments on commit 30c2e62

Please sign in to comment.