Skip to content

Commit

Permalink
added logger to admin module
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim committed Sep 27, 2021
1 parent 5c9a4f9 commit ef90c5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
7 changes: 1 addition & 6 deletions artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import hashlib
import io
import json
import logging
import os
import pathlib
import re
Expand All @@ -51,6 +50,7 @@
from dohq_artifactory.auth import XJFrogArtApiAuth
from dohq_artifactory.auth import XJFrogArtBearerAuth
from dohq_artifactory.exception import ArtifactoryException
from dohq_artifactory.logger import logger

try:
import requests.packages.urllib3 as urllib3
Expand All @@ -64,11 +64,6 @@
default_config_path = "~/.artifactory_python.cfg"
global_config = None

# set logger to be configurable from external
logger = logging.getLogger(__name__)
# Set default logging handler to avoid "No handler found" warnings.
logger.addHandler(logging.NullHandler())


def read_config(config_path=default_config_path):
"""
Expand Down
34 changes: 17 additions & 17 deletions dohq_artifactory/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import logging
import random
import re
import string
Expand All @@ -11,6 +10,7 @@
from dateutil.parser import isoparse

from dohq_artifactory.exception import ArtifactoryException
from dohq_artifactory.logger import logger


def rest_delay():
Expand Down Expand Up @@ -99,7 +99,7 @@ def create(self):
Create object
:return: None
"""
logging.debug(
logger.debug(
f"Create {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
self._create_and_update(self._session.put)
Expand Down Expand Up @@ -137,18 +137,18 @@ def read(self):
True if object exist,
False else
"""
logging.debug(
logger.debug(
f"Read {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/{getattr(self, self.resource_name)}"
r = self._session.get(request_url, auth=self._auth)
if 404 == r.status_code or 400 == r.status_code:
logging.debug(
logger.debug(
f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] does not exist"
)
return False
else:
logging.debug(
logger.debug(
f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] exist"
)
raise_errors(r)
Expand All @@ -163,26 +163,26 @@ def list(self):
:return:
List of objects
"""
# logging.debug('List {x.__class__.__name__} [{x.name}]'.format(x=self))
logger.debug(f"List {self.__class__.__name__} [{self.name}]")
request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}"
response = self._session.get(
request_url,
auth=self._auth,
)
if response.status_code == 200:
# logging.debug('{x.__class__.__name__} [{x.name}] does not exist'.format(x=self))
logger.debug(f"{self.__class__.__name__} [{self.name}] does not exist")
json_response = response.json()
return [item.get(self.resource_name) for item in json_response]
else:
# logging.debug('{x.__class__.__name__} [{x.name}] exist'.format(x=self))
logger.debug(f"{self.__class__.__name__} [{self.name}] exist")
return "failed"

def update(self):
"""
Update object
:return: None
"""
logging.debug(
logger.debug(
f"Create {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
self._create_and_update(self._session.post)
Expand All @@ -192,7 +192,7 @@ def delete(self):
Remove object
:return: None
"""
logging.debug(
logger.debug(
f"Remove {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/{getattr(self, self.resource_name)}"
Expand Down Expand Up @@ -483,7 +483,7 @@ def delete(self):
TODO: New entrypoint would go like
/api/groups/delete and consumes ["list", "of", "groupnames"]
"""
logging.debug(
logger.debug(
f"Remove {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri_deletion}/{getattr(self, self.resource_name)}"
Expand All @@ -496,7 +496,7 @@ def create(self):
Create object
:return: None
"""
logging.debug(
logger.debug(
f"Create {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
data_json = self._create_json()
Expand Down Expand Up @@ -1270,19 +1270,19 @@ def read(self):
True if object exist,
False else
"""
logging.debug(
logger.debug(
f"Read {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}"
r = self._session.get(request_url, auth=self._auth)
if 404 == r.status_code or 400 == r.status_code:
logging.debug(
logger.debug(
f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] does not exist"
)
return False
else:
logging.debug(
"{self.__class__.__name__} [{getattr(self, self.resource_name)}] exist"
logger.debug(
f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] exist"
)
r.raise_for_status()
response = r.json()
Expand All @@ -1299,7 +1299,7 @@ def delete(self):
POST security/token/revoke
revoke (calling it deletion to be consistent with other classes) a token
"""
logging.debug(
logger.debug(
f"Delete {self.__class__.__name__} [{getattr(self, self.resource_name)}]"
)
request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/revoke"
Expand Down
6 changes: 6 additions & 0 deletions dohq_artifactory/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import logging

# set logger to be configurable from external
logger = logging.getLogger("artifactory")
# Set default logging handler to avoid "No handler found" warnings.
logger.addHandler(logging.NullHandler())

0 comments on commit ef90c5e

Please sign in to comment.