Skip to main content

DevOps tools

Project description

devops-driver

status sheild status sheild GitHub GitHub contributors PR's Welcome

commit sheild activity sheild GitHub top language size sheild

example workflow status sheild issues sheild GitHub pull requests

follow sheild watch sheild

Python Azure Gmail

OS: Windows macOS Linux

Devops-driver is a collection of tools to help streamline developer's experience and gain insights into various processes.

Tools

devopsdriver is a toolbox that helps to quickly put together reports. Some of the items in the toolbox are:

  • Settings: store data, constants, settings, keys, tokens, etc. both in and out of the repository
  • send_email: send emails over SMTP (including SSL), using Settings to store credentials
  • Template: Simplify generating reports using .mako templates
  • Azure.workitem: Search for and inspect Azure DevOps work items

Example use-case

To allow seamless work in both pipelines as well as in the development environment, the Settings object gives you access to common settings among multiple scripts, secrets, and configuration constants in a way the helps keep secrets out of the repository but runs just as well in the pipeline as your machine.

Say you want a pipeline that looks for User Stories that are newer than 3 days and send out an email.

<platform dependent path>/devopsdriver.yml

smtp:
    sender: JohnDoe@company.com

secrets:
    azure.token: azure/token
    smtp.password: smtp/password

This file is in a global place (location varies by OS) and stores information that you may not want in your repository or is specific to development.

Platform Global Directory
Windows %APPDATA%\
Linux ~/.devopsdriver/
macOS ~/Library/Preferences/

The secrets are extra sensative and are stored in the OS keychain.

Set secrets in the keychain

$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install devopsdriver
$ settings --secrets
secret: smtp.password  key: smtp/password
smtp.password (smtp/password): ****
secret: azure.token  key: azure/token
smtp.password (azure/token): ****
$ settings --secrets
secret: azure.token  key: azure/token
    Value set
secret: smtp.password  key: smtp/password
    Value set
$

The first call to settings will look for every secret and check if they are already set in the keychain. For any secret that has not been set in the keychain, you will be prompted to enter the password to store. The second call to settings will verify that all the values have been set in the keychain.

Note: If your secrets, cli, or env are in a yaml file named after your script, you can call settings --secrets --script my_script.py.

devopsdriver.yml

azure:
    url: https://dev.azure.com/MyCompany

smtp:
    server: smtp.company.com
    port: 465

cli:
    azure.token: --azure-token
    smtp.password: --smtp-password
    smtp.sender: --smtp-sender

env:
    azure.token: AZURE_TOKEN
    smtp.sender: SMTP_SENDER
    smtp.password: SMTP_PASSWORD

This file lives next to your scripts in your repository. These are settings that would be used by everyone, including the pipeline. The cli and env map command line switches and environment variables to those keys. This allows for many options for setting values depending on your needs.

new_stories.yml

scrum masters:
    - JohnDoe@company.com
    - JaneDoe@company.com

This file is specific to your script and not shared. These are values that you want to use in your script but have them here for easy adjustment.

new_stories.html.mako

<h1>Stories created in the last ${days} days</h1>
<ul>
    % for story in stories:
    <li>${story.id} ${story.title}</li>
    % endfor
</ul>

This file is the template for the email body.

new_stories.py

from datetime import date, timedelta

from devopsdriver import Settings, Azure, send_email, Template
from devopsdriver.azdo import Wiql, GreaterThan

# Parse all the settings from files, command line, environment, and keychain
settings = Settings(__file__).key("secrets").cli("cli").env("env")

# Create connection to Azure Devops
azure = Azure(settings)

# Get User Stories created in the last three days
three_days_ago = date.today() - timedelta(days=settings["days of recent stories"])
new_stories = azure.workitem.find(
    Wiql().where(GreaterThan("CreatedDate", three_days_ago))
)

# Generate html body of the email
message = Template(__file__).render(
    days=settings["days of recent stories"],
    stories=new_stories,
)

# Send the email
send_email(
    recipients=settings["scrum masters"],
    subject=f'Stories created in the last {settings["days of recent stories"]} days',
    html_body=message,
    settings=settings,
)

The email sent

From: JohnDoe@company.com

To: JohnDoe@company.com, JaneDoe@company.com

Subject: Stories created in the last 3 days

Stories created in the last 3 days

  • 745 Needs a preprocessing step that makes it case insensitive
  • 749 Create GitHub action to automate process
  • 750 Create GitHub action to automate process
  • 751 Test
  • 752 Feedback Capture
  • 753 draft doc history retrieval method
  • 754 frontend - store to schema
  • 755 Transfer job to production. Setup migrations to move to production
  • 756 Query subscription status from App

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

devopsdriver-0.1.57.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

devopsdriver-0.1.57-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file devopsdriver-0.1.57.tar.gz.

File metadata

  • Download URL: devopsdriver-0.1.57.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for devopsdriver-0.1.57.tar.gz
Algorithm Hash digest
SHA256 80928fe9746ee6c7a938fa8570e4a234b4c34e7ca85270642291f4ab268d2fc3
MD5 d24867b420140fef57a5c5ee7d905692
BLAKE2b-256 e455d533564741ec63b2199efe5c15e262563f98d2aa86dc063439d726dc9052

See more details on using hashes here.

File details

Details for the file devopsdriver-0.1.57-py3-none-any.whl.

File metadata

  • Download URL: devopsdriver-0.1.57-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for devopsdriver-0.1.57-py3-none-any.whl
Algorithm Hash digest
SHA256 44c1b614f6ecb5b402637a16996e525b099ca9ea8a455e2a3fcc1b90270f9f26
MD5 b0749d4d09eef6ba9c5b8fbfab66484e
BLAKE2b-256 d13fb1b7db297423be8a877a63f892e8c290e3f92e09a3ef5e4d298ec46d8b49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page