Skip to main content
Made with pop, a Python implementation of Plugin Oriented Programming Made with Python

Gitlab provider for idem.

About

Manage Gitlab with idem.

What is POP?

This project is built with pop, a Python-based implementation of Plugin Oriented Programming (POP). POP seeks to bring together concepts and wisdom from the history of computing in new ways to solve modern computing problems.

For more information:

Getting Started

Prerequisites

  • Python 3.9+

  • git (if installing from source, or contributing to the project)

Installation

If wanting to use idem-gitlab, you can do so by either installing from PyPI or from source.

Install from PyPI

pip install idem-gitlab

Install from source

# clone repo
git clone git@gitlab.com/vmware/idem/idem-gitlab.git
cd idem-gitlab

# Setup venv
python3 -m venv .venv
source .venv/bin/activate
pip install pip==21 -e .

Usage

credentials

The preferred authentication method to idem-gitlab is with a personal access token. To create a personal access token, see the Gitlab documentation. Create an acct_file with the following format:

gitlab:
   default:
      token: <personal_access_token>
      # Optional parameters
      endpoint_url: https://gitlab.com
      api_version: v4
      sudo: <user>
      owned: True

Encrypt the acct_file with:

idem encrypt /path/to/acct_file

The first time this command is run, it will output an ACCT_KEY that can be used to decrypt the file. Put the ACCT_KEY and the ACCT_FILE in the environment variables and idem will find and use your gitlab profile automatically.

export ACCT_KEY="<acct_key>"
export ACCT_FILE=/path/to/acct_file

Once your credentials are in place, you can test them by running any of the following commands:

idem exec gitlab.version.get
idem exec gitlab.metadata.get
idem exec gitlab.avatar.get email="gitlab_user@example.com"
idem exec gitlab.namespace.get
idem exec gitlab.project.commit.get "<commit_sha/branch/tag/null>" project_id="<project_id>"

Supported Resources

The following are REFs for resources that are currently supported by idem-gitlab.

  • gitlab.group

  • gitlab.group.member

  • gitlab.group.variable

  • gitlab.impersonation_token

  • gitlab.personal_access_token

  • gitlab.project

  • gitlab.project.branch

  • gitlab.project.member

  • gitlab.project.protected_branch

  • gitlab.project.protected_tag

  • gitlab.project.tag

  • gitlab.project.variable

  • gitlab.runner

  • gitlab.user

For each ref, there are functions for create, list, get, update, and delete operations.

Idem-gitlab uses the “auto_state” contract to combine these CRUD operations into present and absent states.

Examples

Run CRUD operations using the idem exec commands:

idem exec gitlab.project.create path=new_project
idem exec gitlab.project.list
idem exec gitlab.project.get "<new_project_id>"
idem exec gitlab.project.update "<new_project_id>" repository_access_level=private
idem exec gitlab.project.delete "<new_project_id>"

Create an SLS files based on existing resource:

idem describe gitlab.group > /srv/idem/gitlab/group.sls
idem describe gitlab.group.member > /srv/idem/gitlab/group_member.sls
idem describe gitlab.group.variable > /srv/idem/gitlab/group_variable.sls
idem describe gitlab.project > /srv/idem/gitlab/project.sls
idem describe gitlab.project.branch > /srv/idem/gitlab/branch.sls
idem describe gitlab.project.member > /srv/idem/gitlab/project_member.sls
idem describe gitlab.project.protected_branch > /srv/idem/gitlab/protected_branch.sls
idem describe gitlab.project.protected_tag > /srv/idem/gitlab/protected_tag.sls
idem describe gitlab.project.tag > /srv/idem/gitlab/tag.sls
idem describe gitlab.project.variable > /srv/idem/gitlab/project_variable.sls
idem describe gitlab.runner > /srv/idem/gitlab/runner.sls
idem describe gitlab.user > /srv/idem/gitlab/user.sls

Create a top-level SLS file that sources all the others:

# /srv/idem/gitlab/init.sls
include:
  - group
  - group_member
  - group_variable
  - project_member
  - project
  - branch
  - protected_branch
  - protected_tag
  - tag
  - project_variable
  - runner
  - user

Run “idem state” to idempotently enforce changes to the any of the files created:

idem state /srv/idem/gitlab

And that’s it! You are now using idem-gitlab to manage your gitlab resources.

Testing

To run the tests using a gitlab docker image, first run:

docker run -d -p 80:80 --env GITLAB_ROOT_PASSWORD=not_secure gitlab/gitlab-ce

For testing you can use the sample credentials file for tests:

export ACCT_FILE=$PWD/example/credentials.yaml

Run the test suite with nox:

pip3 install nox
nox -p 3.11

Autogeneration

Autogeneration utilizes pop-create to parse the gitlab api and generate modules for new resources. To perform the autogeneration, first you need to install idem-gitlab with the autogen extras:

pip3 install idem-gitlab[autogen]

Next, run pop-create to generate the modules in the current directory:

pop-create gitlab --directory $PWD --create-plugin auto_state
pop-create gitlab --directory $PWD --create-plugin tests

These modules won’t work out-of-the-box, they will likely need manual changes to conform them to the rest of idem-gitlab and make them functional. Once you have fully implemented a new resource, submit a PR and we will review it and hopefully add it to idem-gitlab’s functionality!

Roadmap

Reference the open issues for a list of proposed features (and known issues).

Acknowledgements

Metadata

Release files for idem-gitlab 2.0.1

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

Source distribution (sdist)

Source distribution for idem-gitlab 2.0.1
File Size Uploaded Provenance Actions
idem-gitlab-2.0.1.tar.gz 40.0 kB Without provenance Details for idem-gitlab-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for idem-gitlab 2.0.1
File Interpreter ABI Platform Actions
idem_gitlab-2.0.1-py3-none-any.whl Python 3 none any Details for idem_gitlab-2.0.1-py3-none-any.whl

Total release size: 107.2 kB

Release files / idem-gitlab-2.0.1.tar.gz

Download URL idem-gitlab-2.0.1.tar.gz
Size 40.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5ca215c2c78025d2ebc4fefd1aa522c27d2bf06b9bf58cf962d305bd2d48620d
BLAKE2b-256 checksum
How to use checksums
836a19c46dc9dede25db92abd6a5aeb574a725e4373ed3bd54e4014af4420d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/41.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.5 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.18

Release files / idem_gitlab-2.0.1-py3-none-any.whl

Download URL idem_gitlab-2.0.1-py3-none-any.whl
Size 67.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a0e2a0be37736353c9328bb942e7bd3fd1a9c612d02cb05defc7ecdf23883c9
BLAKE2b-256 checksum
How to use checksums
826a9da32a62ffc04bf436e2983c7cda358fc1e0d9f248657609ea33d8b997a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/41.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.5 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.18

Security for idem-gitlab 2.0.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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