Skip to main content

Poetry Plugin: (AWS) Code Artifact

PyPi Stable Version Pre-release Version Python Versions Code coverage Status PyTest Download Stats License: MIT pre-commit Code Style

This package is a plugin that attempts to give improved integration of AWS CodeArtifact repositories with poetry.

Installation

The easiest way to install the code-artifact plugin is via the self add command of Poetry.

poetry self add poetry-plugin-code-artifact

If you used pipx to install Poetry you can add the plugin via the pipx inject command.

pipx inject poetry poetry-plugin-code-artifact

Otherwise, if you used pip to install Poetry you can add the plugin packages via the pip install command.

pip install poetry-plugin-code-artifact

Prerequisites

It is assumed there are one or more AWS CodeArtifact repositories set up and that you have a set of credentials that have permissions to available either, to search and download, and/or, publish packages.

Identity policies

In order to grant access to a repository for read access, the following policy will need to be applied to the AWS identity for which credentials will be used to access the repository.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sts:GetServiceBearerToken"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "codeartifact:DescribeDomain",
                "codeartifact:GetAuthorizationToken",
                "codeartifact:ListRepositoriesInDomain"
            ],
            "Resource": "arn:aws:codeartifact:us-east-1:345125489763:domain/my-domain"
        },
        {
            "Effect": "Allow",
            "Action": [
                "codeartifact:Describe*",
                "codeartifact:List*",
                "codeartifact:GetPackageVersionReadme",
                "codeartifact:GetRepositoryEndpoint",
                "codeartifact:ReadFromRepository"
            ],
            "Resource": [
                "arn:aws:codeartifact:us-east-1:345125489763:repository/my-domain/my-repo",
                "arn:aws:codeartifact:us-east-1:345125489763:repository/my-domain/my-repo/*",
                "arn:aws:codeartifact:us-east-1:345125489763:package/my-domain/my-repo/*"
            ]
        }
    ]
}

In order to grant access to a repository for write access, the following policy will need to be applied to the AWS identity for which credentials will be used to access the repository.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codeartifact:GetRepositoryEndpoint",
                "codeartifact:PublishPackageVersion",
                "codeartifact:PutPackageMetadata"
            ],
            "Resource": [
                "arn:aws:codeartifact:us-east-1:345125489763:repository/my-domain/my-repo",
                "arn:aws:codeartifact:us-east-1:345125489763:repository/my-domain/my-repo/*",
                "arn:aws:codeartifact:us-east-1:345125489763:package/my-domain/my-repo/*"
            ]
        }
    ]
}

Cross-account policies

For cross-account access to the AWS CodeArtifact domain, the domain must have the resource policy,

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Principal": {
                "AWS": "arn:aws:iam::345125489763:root"
            },
            "Effect": "Allow",
            "Action": [
                "codeartifact:DescribeDomain",
                "codeartifact:GetAuthorizationToken",
                "codeartifact:ListRepositoriesInDomain"
            ],
            "Resource": "*"
        }
    ]
}

For cross-account read access to a repository, the repository will require the following resource policy,

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Principal": {
                "AWS": "arn:aws:iam::345125489763:root"
            },
            "Effect": "Allow",
            "Action": [
                "codeartifact:DescribePackageVersion",
                "codeartifact:DescribeRepository",
                "codeartifact:Get*",
                "codeartifact:List*",
                "codeartifact:ReadFromRepository"
            ],
            "Resource": "*"
        }
    ]
}

For cross-account write access, the repository will require the following resource policy,

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Principal": {
                "AWS": "arn:aws:iam::345125489763:root"
            },
            "Effect": "Allow",
            "Action": [
                "codeartifact:GetRepositoryEndpoint",
                "codeartifact:PublishPackageVersion",
                "codeartifact:PutPackageMetadata"
            ],
            "Resource": "*"
        }
    ]
}

Usage

Other than configuration, usage is the same as adding any other repository to poetry.

The plugin is configured in the pyproject.toml file, below is an example of adding three AWS CodeArtifact repositories..

[[tool.poetry-plugin-code-artifact.sources]]
name="dev"  # The name of the repositroy in poetry
aws-codeartifact-domain="my-domain"   # The AWS CodeArtifact domain.
aws-codeartifact-owner="564131876131" # The AWS CodeArtifact domain owner.
aws-codeartifact-region="us-east-1"   # The AWS CodeArtifact region.
aws-codeartifact-repository="dev"     # The AWS CodeArtifact repository name.

[[tool.poetry-plugin-code-artifact.sources]]
name="qa"
aws-codeartifact-domain="my-domain"
aws-codeartifact-owner="564131876131"
aws-codeartifact-region="us-east-1"
aws-codeartifact-repository="dev"

[[tool.poetry-plugin-code-artifact.sources]]
name="prod"
aws-codeartifact-domain="my-domain"
aws-codeartifact-owner="564131876131"
aws-codeartifact-region="eus-east-1"
aws-codeartifact-repository="dev"

To use the above repositories via poetry, just use the normal commands,

Note: You must first be logged into AWS with an identity that has the correct permissions as given in the prerequisites section above. For more information on configuring credentials, see https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

# To add a dependency,
poetry add my-lib  # Searches all repositories
# or
poetry add my-lib --source dev  # Prioritizes dev repository then searches all repositories.

# To publish a dependency,
poetry publish -r dev
  • website: The official Poetry website and blog
  • poetry-plugin-export: Export Poetry projects/lock files to foreign formats like requirements.txt (Used some test code from this project)
  • poetry-plugin-package-info: Poetry Plugin for including project and git information in your distributable files. (Shameless plug to one of my other poetry plugins)

Release files for poetry-plugin-code-artifact 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poetry-plugin-code-artifact 1.0.0
File Size Uploaded Provenance
poetry_plugin_code_artifact-1.0.0.tar.gz 7.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for poetry-plugin-code-artifact 1.0.0
File Interpreter ABI Platform
poetry_plugin_code_artifact-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / poetry_plugin_code_artifact-1.0.0.tar.gz

Download URL poetry_plugin_code_artifact-1.0.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e90114d9071613c49f7c459d1a71f61b72d7baa70a386ef8bb3b39d45fa5bf59
BLAKE2b-256 checksum
How to use checksums
2b433d87aa97ab47a7764a9552120e4d39c0abf6558829ed71f6b86d6abe9576
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

Release files / poetry_plugin_code_artifact-1.0.0-py3-none-any.whl

Download URL poetry_plugin_code_artifact-1.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a654004df3e4da3998548fcbf602e46a154823ce0ee160c4e49e2c539e7deb4f
BLAKE2b-256 checksum
How to use checksums
2305c67c45c84e5925606c9250539d16f2f9ebf11883f9347042f06fccd03463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

Security for poetry-plugin-code-artifact 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page