All Projects → anancarv → python-artifactory

anancarv / python-artifactory

Licence: MIT license
Typed interactions with the Jfrog Artifactory REST API

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to python-artifactory

artifactory
Ansible role to install Artifactory, the Maven repository manager by JFrog.
Stars: ✭ 21 (-38.24%)
Mutual labels:  artifactory, jfrog
prisma-client-py
Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
Stars: ✭ 739 (+2073.53%)
Mutual labels:  python-types, pydantic
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+116335.29%)
Mutual labels:  python-types, pydantic
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-41.18%)
Mutual labels:  pydantic
redis-om-python
Object mapping, and more, for Redis and Python
Stars: ✭ 590 (+1635.29%)
Mutual labels:  pydantic
artifactory-secrets-plugin
HashiCorp Vault Artifactory Secrets Plugin
Stars: ✭ 17 (-50%)
Mutual labels:  artifactory
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-41.18%)
Mutual labels:  pydantic
go-arty
Go client library for Artifactory and Xray
Stars: ✭ 26 (-23.53%)
Mutual labels:  artifactory
go-artifactory
Go library for artifactory REST API
Stars: ✭ 21 (-38.24%)
Mutual labels:  artifactory
kubernetes example
5-Step Kubernetes CI/CD Process using Artifactory & Helm
Stars: ✭ 35 (+2.94%)
Mutual labels:  artifactory
pydantic-vault
A simple extension to Pydantic BaseSettings that can retrieve secrets from Hashicorp Vault
Stars: ✭ 35 (+2.94%)
Mutual labels:  pydantic
ebook-continuous-delivery-with-kubernetes-and-jenkins
Continuous Delivery for Java Apps: Build a CD Pipeline Step by Step Using Kubernetes, Docker, Vagrant, Jenkins, Spring, Maven and Artifactory
Stars: ✭ 39 (+14.71%)
Mutual labels:  artifactory
artifact-resolver
Standalone jar executable client Maven 2 artifact resolver based on Eclipse Aether.
Stars: ✭ 13 (-61.76%)
Mutual labels:  artifactory
morelia server
Server for MoreliaTalk network
Stars: ✭ 25 (-26.47%)
Mutual labels:  pydantic
terraform-provider-artifactory
Terraform provider for managing Artifactory
Stars: ✭ 17 (-50%)
Mutual labels:  artifactory
autodoc pydantic
Seamlessly integrate pydantic models in your Sphinx documentation.
Stars: ✭ 60 (+76.47%)
Mutual labels:  pydantic
mongox
Familiar async Python MongoDB ODM
Stars: ✭ 113 (+232.35%)
Mutual labels:  pydantic
pydantic-factories
Simple and powerful mock data generation using pydantic or dataclasses
Stars: ✭ 380 (+1017.65%)
Mutual labels:  pydantic
starlite
Light, Flexible and Extensible ASGI API framework
Stars: ✭ 1,525 (+4385.29%)
Mutual labels:  pydantic
pypackage
Cookiecutter python package using Poetry, mypy, black, isort, autoflake, pytest, mkdocs, and GitHub Actions
Stars: ✭ 12 (-64.71%)
Mutual labels:  pydantic

PyArtifactory

GitHub Actions workflow PyPI version Codacy Badge Codacy Badge Code style: black

pyartifactory is a Python library to access the Artifactory REST API.

This library enables you to manage Artifactory resources such as users, groups, permissions, repositories, artifacts and access tokens in your applications. Based on Python 3.6+ type hints.

Requirements

  • Python 3.6+

Install

pip install pyartifactory

Usage

Authentication

Since Artifactory 6.6.0 there is version 2 of the REST API for permission management, in case you have that version or higher, you need to pass api_version=2 to the constructor when you instantiate the class.

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=1)

SSL Cert Verification Options

Specify a local cert to use as client side certificate

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSORD_OR_API_KEY'), cert="/path_to_file/server.pem",api_version=1)

Disable host cert verification

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSORD_OR_API_KEY'), verify=False, api_version=1)

Admin objects

User

First, you need to create a new Artifactory object.

from pyartifactory import Artifactory
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSORD_OR_API_KEY'))

Get the list of users:

users = art.users.list()

Get a single user:

user = art.users.get("test_user")

Create a user:

from pyartifactory.models import NewUser

# Create User
user = NewUser(name="test_user", password="test_password", email="[email protected]")
new_user = art.users.create(user)

# Update user
user.email = "[email protected]"
updated_user = art.users.update(user)

Update a user:

from pyartifactory.models import User

user = art.users.get("test_user")

# Update user
user.email = "[email protected]"
updated_user = art.users.update(user)

Delete a user:

art.users.delete("test_user")

Unlock a user:

art.users.unlock("test_user")

Group

Get the list of groups:

groups = art.groups.list()

Get a single group:

group = art.groups.get("group_name")

Create/Update a group:

from pyartifactory.models import Group

# Create a Group
group = Group(name="test_group", description="test_group")
new_group = art.groups.create(group)

# Update a Group
group.description = "test_group_2"
updated_group = art.groups.update(group)

Delete a group:

art.groups.delete("test_group")

Security

A set of methods for performing operations on apiKeys, passwords ...

>>> art.security.
art.security.create_api_key(          art.security.get_encrypted_password(  art.security.revoke_api_key(
art.security.get_api_key(             art.security.regenerate_api_key(      art.security.revoke_user_api_key(

Create an access token (for a transient user):

token = art.security.create_access_token(user_name='transient_artifactory_user',
                                         groups=['g1', 'g2'],
                                         refreshable=True)

Create an access token for an existing user (groups are implied from the existing user):

token = art.security.create_access_token(user_name='existing_artifactory_user',
                                         refreshable=True)

Revoke an existing revocable token:

art.security.revoke_access_token(token.access_token)

Repository

Get the list of repositories:

repositories = art.repositories.list()

Get a single repository

repo = art.repositories.get_repo("repo_name")
# According to the repo type, you'll have either a local, virtual or remote repository returned

Create/Update a repository:

from pyartifactory.models import LocalRepository, VirtualRepository, RemoteRepository

# Create local repo
local_repo = LocalRepository(key="test_local_repo")
new_local_repo = art.repositories.create_repo(local_repo)

# Create virtual repo
virtual_repo = VirtualRepository(key="test_virtual_repo")
new_virtual_repo = art.repositories.create_repo(virtual_repo)

# Create remote repo
remote_repo = RemoteRepository(key="test_remote_repo")
new_remote_repo = art.repositories.create_repo(remote_repo)

# Update a repository
local_repo = art.repositories.get_repo("test_local_repo")
local_repo.description = "test_local_repo"
updated_local_repo = art.repositories.update_repo(local_repo)

Delete a repository:

art.repositories.delete("test_local_repo")

Permission

Get the list of permissions:

permissions = art.permissions.list()

Get a single permission:

users = art.permissions.get("test_permission")

Create/Update a permission:

Artifactory lower than 6.6.0
from pyartifactory.models import Permission

# Create a permission
permission = Permission(
    **{
        "name": "test_permission",
        "repositories": ["test_repository"],
        "principals": {
            "users": {"test_user": ["r", "w", "n", "d"]},
            "groups": {"developers": ["r"]},
        },
    }
)
perm = art.permissions.create(permission)

# Update permission
permission.repositories = ["test_repository_2"]
updated_permission = art.permissions.update(permission)
Artifactory 6.6.0 or higher
from pyartifactory import Artifactory
from pyartifactory.models import PermissionV2
from pyartifactory.models.permission import PermissionEnumV2, PrincipalsPermissionV2, RepoV2, BuildV2, ReleaseBundleV2

# To use PermissionV2, make sure to set api_version=2
art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=2)

# Create a permission
permission = PermissionV2(
    name="test_permission",
    repo=RepoV2(
        repositories=["test_repository"],
        actions=PrincipalsPermissionV2(
            users={
                "test_user": [
                    PermissionEnumV2.read,
                    PermissionEnumV2.annotate,
                    PermissionEnumV2.write,
                    PermissionEnumV2.delete,
                ]
            },
            groups={
                "developers": [
                    PermissionEnumV2.read,
                    PermissionEnumV2.annotate,
                    PermissionEnumV2.write,
                    PermissionEnumV2.delete,
                ],
            },
        ),
        includePatterns=["**"],
        excludePatterns=[],
    ),
    build=BuildV2(
          actions=PrincipalsPermissionV2(
              users={
                  "test_user": [
                      PermissionEnumV2.read,
                      PermissionEnumV2.write,
                  ]
              },
              groups={
                  "developers": [
                      PermissionEnumV2.read,
                      PermissionEnumV2.write,
                  ],
              },
          ),
          includePatterns=[""],
          excludePatterns=[""],
      ),
    releaseBundle=ReleaseBundleV2(
          repositories=["release-bundles"],
          actions=PrincipalsPermissionV2(
              users={
                  "test_user": [
                      PermissionEnumV2.read,
                  ]
              },
              groups={
                  "developers": [
                      PermissionEnumV2.read,
                  ],
              },
          ),
          includePatterns=[""],
          excludePatterns=[""],
      )
  # You don't have to set all the objects repo, build and releaseBundle
  # If you only need repo for example, you can set only the repo object
)
perm = art.permissions.create(permission)

# Update permission
permission.repo.repositories = ["test_repository_2"]
updated_permission = art.permissions.update(permission)

Delete a permission:

art.permissions.delete("test_permission")

Artifacts

Get the information about a file or folder

artifact_info = art.artifacts.info("<ARTIFACT_PATH_IN_ARTIFACTORY>")
# file_info = art.artifacts.info("my-repository/my/artifact/directory/file.txt")
# folder_info = art.artifacts.info("my-repository/my/artifact/directory")

Deploy an artifact

artifact = art.artifacts.deploy("<LOCAL_FILE_LOCATION>", "<ARTIFACT_PATH_IN_ARTIFACTORY>")
# artifact = art.artifacts.deploy("Desktop/myNewFile.txt", "my-repository/my/new/artifact/directory/file.txt")

Download an artifact

artifact = art.artifacts.download("<ARTIFACT_PATH_IN_ARTIFACTORY>", "<LOCAL_DIRECTORY_PATH>")
# artifact = art.artifacts.download("my-artifactory-repository/my/new/artifact/file.txt", "Desktop/my/local/directory")
# The artifact location is returned by the download method
# If you have not set a <LOCAL_DIRECTORY_PATH>, the artifact will be downloaded in the current directory

Retrieve artifact properties

artifact_properties = art.artifacts.properties("<ARTIFACT_PATH_IN_ARTIFACTORY>")  # returns all properties
# artifact_properties = art.artifacts.properties("my-repository/my/new/artifact/directory/file.txt")
artifact_properties = art.artifacts.properties("<ARTIFACT_PATH_IN_ARTIFACTORY>", ["prop1", "prop2"])  # returns specific properties
artifact_properties.properties["prop1"]  # ["value1", "value1-bis"]

Set artifact properties

artifact_properties = art.artifacts.set_properties("<ARTIFACT_PATH_IN_ARTIFACTORY>", {"prop1": "value", "prop2": "value"})  # recursive mode is enabled by default
artifact_properties = art.artifacts.set_properties("<ARTIFACT_PATH_IN_ARTIFACTORY>", {"prop1": "value", "prop2": "value"}, False) # disable recursive mode

Update artifact properties

artifact_properties = art.artifacts.update_properties("<ARTIFACT_PATH_IN_ARTIFACTORY>", {"prop1": "value", "prop2": "value"})  # recursive mode is enabled by default
artifact_properties = art.artifacts.update_properties("<ARTIFACT_PATH_IN_ARTIFACTORY>", {"prop1": "value", "prop2": "value"}, False) # disable recursive mode

Retrieve artifact stats

artifact_stats = art.artifacts.stats("<ARTIFACT_PATH_IN_ARTIFACTORY>")
# artifact_stats = art.artifacts.stats("my-repository/my/new/artifact/directory/file.txt")

Copy artifact to a new location

artifact = art.artifacts.copy("<CURRENT_ARTIFACT_PATH_IN_ARTIFACTORY>","<NEW_ARTIFACT_PATH_IN_ARTIFACTORY>")

# If you want to run a dryRun test, you can do the following:
# artifact = art.artifacts.copy("my-repository/current/artifact/path/file.txt","my-repository/new/artifact/path/file.txt", dryrun=True)
# It will return properties of the newly copied artifact

Move artifact to a new location

artifact = art.artifacts.move("<CURRENT_ARTIFACT_PATH_IN_ARTIFACTORY>","<NEW_ARTIFACT_PATH_IN_ARTIFACTORY>")

# You can also run a dryRun test with the move operation
# It will return properties of the newly moved artifact

Delete an artifact

art.artifacts.delete("<ARTIFACT_PATH_IN_ARTIFACTORY>")

Contributing

Please read the Development - Contributing guidelines.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].