Skip to content

Commit

Permalink
Refactored client
Browse files Browse the repository at this point in the history
  • Loading branch information
Rimobul committed Feb 1, 2024
1 parent 3faf8ce commit 5adae98
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
24 changes: 24 additions & 0 deletions azure-devops/azure/devops/azure_devops_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.core import PipelineClient
from azure.core.pipeline.policies import UserAgentPolicy, HeadersPolicy
from .version import VERSION


class AzureDevOpsClient(PipelineClient):
def __init__(self, base_url=None, credentials=None, user_agent=None):
if not base_url:
raise ValueError('base_url is required.')
if not credentials:
raise ValueError('credentials is required.')
base_url = base_url.rstrip('/')
user_agent_policy = UserAgentPolicy('azure-devops/{}'.format(VERSION))
if user_agent is not None:
user_agent_policy.add_user_agent(user_agent)
headers_policy = HeadersPolicy()
headers_policy.add_header('Authentication', credentials)
policies = [user_agent_policy, headers_policy]
super(AzureDevOpsClient, self).__init__(base_url=base_url, policies=policies)
9 changes: 3 additions & 6 deletions azure-devops/azure/devops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import uuid

from azure.core.rest import HttpRequest, HttpResponse
from azure.core.rest.exceptions import DeserializationError, SerializationError
from azure.core.rest.service_client import ServiceClient
from azure.core.exceptions import DeserializationError, SerializationError
from .exceptions import AzureDevOpsAuthenticationError, AzureDevOpsClientRequestError, AzureDevOpsServiceError
from .client_configuration import ClientConfiguration
from .azure_devops_client import AzureDevOpsClient
from . import _models
from ._file_cache import OPTIONS_CACHE as OPTIONS_FILE_CACHE

Expand All @@ -29,9 +28,7 @@ class Client(object):
"""

def __init__(self, base_url=None, creds=None):
self.config = ClientConfiguration(base_url)
self.config.credentials = creds
self._client = ServiceClient(creds, config=self.config)
self._client = AzureDevOpsClient(base_url=base_url, credentials=creds)
_base_client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
self._base_deserialize = Deserializer(_base_client_models)
self._base_serialize = Serializer(_base_client_models)
Expand Down
17 changes: 0 additions & 17 deletions azure-devops/azure/devops/client_configuration.py

This file was deleted.

13 changes: 4 additions & 9 deletions azure-devops/azure/devops/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import logging

from azure.core.rest.service_client import ServiceClient
from ._file_cache import RESOURCE_CACHE as RESOURCE_FILE_CACHE
from .client_configuration import ClientConfiguration
from .azure_devops_client import AzureDevOpsClient
from .exceptions import AzureDevOpsClientRequestError
from .released.client_factory import ClientFactory
from .v7_2.location.location_client import LocationClient
Expand All @@ -21,16 +20,12 @@ class Connection(object):
"""Connection.
"""

def __init__(self, base_url=None, creds=None, user_agent=None):
self._config = ClientConfiguration(base_url)
self._config.credentials = creds
def __init__(self, base_url=None, credentials=None, user_agent=None):
self._addition_user_agent = user_agent
if user_agent is not None:
self._config.add_user_agent(user_agent)
self._client = ServiceClient(creds, self._config)
self._client = AzureDevOpsClient(base_url=base_url, credentials=credentials, user_agent=user_agent)
self._client_cache = {}
self.base_url = base_url
self._creds = creds
self._creds = credentials
self._resource_areas = None
self.clients = ClientFactory(self)
self.clients_v7_2 = ClientFactoryV7_2(self)
Expand Down
15 changes: 5 additions & 10 deletions azure-devops/azure/devops/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.core.rest.exceptions import (
ClientException,
ClientRequestError,
AuthenticationError,
from azure.core.exceptions import (
ClientAuthenticationError,
ServiceResponseError
)


class AzureDevOpsClientError(ClientException):
class AzureDevOpsAuthenticationError(ClientAuthenticationError):
pass


class AzureDevOpsAuthenticationError(AuthenticationError):
pass


class AzureDevOpsClientRequestError(ClientRequestError):
class AzureDevOpsClientRequestError(ServiceResponseError):
pass


Expand Down

0 comments on commit 5adae98

Please sign in to comment.