Skip to content

Commit

Permalink
fix logging and aql debug for devopshq#131 and devopshq#235
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim committed Sep 8, 2021
1 parent f6eb408 commit f2a79b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package.

- [Install](#install)
- [Usage](#usage)
* [Enable logging](#enable-logging)
* [Authentication](#authentication)
* [Artifactory SaaS](#artifactory-saas)
* [Walking Directory Tree](#walking-directory-tree)
Expand Down Expand Up @@ -85,6 +86,19 @@ pip install dohq-artifactory==0.5.dev243
```

# Usage
## Enable logging
For purpose of debugging or need of additional information you can configure logger to work with current library
Just configure logging module in your python script. Simpliest example:
~~~python
import logging
from artifactory import ArtifactoryPath

logging.basicConfig(level=logging.DEBUG)
path = ArtifactoryPath(
"http://my-artifactory/artifactory/myrepo/restricted-path", apikey="MY_API_KEY"
)
~~~
This will add debug messages to StdOut

## Authentication ##

Expand Down Expand Up @@ -474,19 +488,19 @@ You can use [Artifactory Query Language](https://www.jfrog.com/confluence/displa
```python
from artifactory import ArtifactoryPath

aql = ArtifactoryPath(
arti_path = ArtifactoryPath(
"http://my-artifactory/artifactory"
) # path to artifactory, NO repo

# dict support
# Send query:
# items.find({"repo": "myrepo"})
artifacts = aql.aql("items.find", {"repo": "myrepo"})
artifacts = arti_path.aql("items.find", {"repo": "myrepo"})

# list support.
# Send query:
# items.find().include("name", "repo")
artifacts = aql.aql("items.find()", ".include", ["name", "repo"])
artifacts = arti_path.aql("items.find()", ".include", ["name", "repo"])

# support complex query
# Example 1
Expand All @@ -498,7 +512,7 @@ artifacts = aql.aql("items.find()", ".include", ["name", "repo"])
# ]
# }
# )
args = [
aqlargs = [
"items.find",
{
"$and": [
Expand All @@ -515,7 +529,7 @@ args = [

# artifacts_list contains raw data (list of dict)
# Send query
artifacts_list = aql.aql(*args)
artifacts_list = arti_path.aql(*aqlargs)

# Example 2
# The query will find all items in repo docker-prod that are of type file and were created after timecode. The
Expand All @@ -541,11 +555,11 @@ aqlargs = [
".sort",
{"$asc": ["repo", "path", "name"]},
]
artifacts_list = aql.aql(*args)
artifacts_list = arti_path.aql(*aqlargs)

# You can convert to pathlib object:
artifact_pathlib = map(aql.from_aql, artifacts_list)
artifact_pathlib_list = list(map(aql.from_aql, artifacts_list))
artifact_pathlib = map(arti_path.from_aql, artifacts_list)
artifact_pathlib_list = list(map(arti_path.from_aql, artifacts_list))
```


Expand Down
9 changes: 8 additions & 1 deletion artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
default_config_path = "~/.artifactory_python.cfg"
global_config = None

# set logger to be configurable from external
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())


def read_config(config_path=default_config_path):
"""
Expand Down Expand Up @@ -397,6 +401,7 @@ def quote_url(url):
quoted_path = requests.utils.quote(url.rpartition(parsed_url.host)[2])
quoted_url = f"{parsed_url.scheme}://{parsed_url.host}{quoted_path}"

logging.debug(f"Percent-encoded URL: {quoted_url}")
return quoted_url


Expand Down Expand Up @@ -1920,7 +1925,7 @@ def aql(self, *args):
@staticmethod
def create_aql_text(*args):
"""
Create AQL querty from string or list or dict arguments
Create AQL query from string or list or dict arguments
"""
aql_query_text = ""
for arg in args:
Expand All @@ -1929,6 +1934,8 @@ def create_aql_text(*args):
elif isinstance(arg, list):
arg = "({})".format(json.dumps(arg)).replace("[", "").replace("]", "")
aql_query_text += arg

logging.debug(f"AQL query request text: {aql_query_text}")
return aql_query_text

def from_aql(self, result):
Expand Down

0 comments on commit f2a79b4

Please sign in to comment.