diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..bd50568 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,26 @@ +name: ci +"on": + push: + branches: + - master + pull_request: + branches: + - master +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - uses: actions/checkout@v4 + - uses: pre-commit/action@v3.0.1 + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - uses: actions/checkout@v4 + - run: pip install build + - run: python -m build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7b41b68 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.4 + hooks: + - id: ruff + args: + - --fix + - id: ruff-format + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-merge-conflict + - id: check-yaml + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: trailing-whitespace + - id: mixed-line-ending + args: + - --fix=lf + - repo: https://github.com/crate-ci/typos + rev: v1.21.0 + hooks: + - id: typos + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier diff --git a/README.md b/README.md index 5873b1e..beef70b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,16 @@ -G Suite Tools -============= +# G Suite Tools A growing collection tools for managing a G Suite organization. -Before you begin ----------------- +## Before you begin -* Install the requirements into a Python 3.8+ virtualenv. (`pip install -r requirements.txt`) -* Set up an OAuth application for Google APIs. +- Install the requirements into a Python 3.8+ virtualenv. (`pip install -e .`) +- Set up an OAuth application for Google APIs. Follow the instructions on [this page](https://developers.google.com/admin-sdk/directory/v1/guides/authorizing.html) for "installed software" authentication and once you have a `client_secret.json` file, plop it in the working directory here. -Retrieve all groups and their members -------------------------------------- +## Retrieve all groups and their members ``` python -m gst.get_group_info --domain=mydomain.com --write-json=groups.json @@ -31,9 +28,7 @@ To convert `groups.json` into human-readable Markdown: python -m gst.format_group_info --json=groups.json --write-markdown=- ``` -Retrieve information for all users ----------------------------------- - +## Retrieve information for all users ``` python -m gst.get_user_info --domain=mydomain.com --write-json=users.json @@ -41,7 +36,6 @@ python -m gst.get_user_info --domain=mydomain.com --write-json=users.json To list users with their email aliases: - ``` python -m gst.list_user_emails --json=groups.json -w- ``` diff --git a/gst/__init__.py b/gst/__init__.py index e69de29..3dc1f76 100644 --- a/gst/__init__.py +++ b/gst/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/gst/credentials.py b/gst/credentials.py index d30ad0b..d830e89 100644 --- a/gst/credentials.py +++ b/gst/credentials.py @@ -1,13 +1,17 @@ +import logging import os import pickle from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build +log = logging.getLogger(__name__) + def get_credentials(key, scopes): cached_credentials_file = f"./{key}.credentials.pickle" if os.path.isfile(cached_credentials_file): + log.info("Using cached credentials from %s", cached_credentials_file) with open(cached_credentials_file, "rb") as infp: return pickle.load(infp) flow = InstalledAppFlow.from_client_secrets_file( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cf7f57e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,42 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "g-suite-tools" +dynamic = ["version"] +description = 'Tools for managing G Suites' +readme = "README.md" +requires-python = ">=3.8" +license = "MIT" +keywords = [] +authors = [ + { name = "Aarni Koskela", email = "akx@iki.fi" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = [ + "google-api-python-client~=1.7", + "google-auth-oauthlib~=0.4", + "tqdm~=4.38", +] + +[project.urls] +Documentation = "https://github.com/valohai/g-suite-tools#readme" +Issues = "https://github.com/valohai/g-suite-tools/issues" +Source = "https://github.com/valohai/g-suite-tools" + +[tool.hatch.version] +path = "gst/__init__.py" + +[tool.hatch.build.targets.wheel] +packages = ["gst"] diff --git a/requirements.in b/requirements.in deleted file mode 100644 index e80b51d..0000000 --- a/requirements.in +++ /dev/null @@ -1,3 +0,0 @@ -google-api-python-client -google-auth-oauthlib -tqdm diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a7d5433..0000000 --- a/requirements.txt +++ /dev/null @@ -1,58 +0,0 @@ -# -# This file is autogenerated by pip-compile -# To update, run: -# -# pip-compile requirements.in -# -cachetools==3.1.1 - # via google-auth -certifi==2019.9.11 - # via requests -chardet==3.0.4 - # via requests -google-api-python-client==1.7.11 - # via -r requirements.in -google-auth-httplib2==0.0.3 - # via google-api-python-client -google-auth-oauthlib==0.4.1 - # via -r requirements.in -google-auth==1.7.1 - # via - # google-api-python-client - # google-auth-httplib2 - # google-auth-oauthlib -httplib2==0.19.0 - # via - # google-api-python-client - # google-auth-httplib2 -idna==2.8 - # via requests -oauthlib==3.1.0 - # via requests-oauthlib -pyasn1-modules==0.2.7 - # via google-auth -pyasn1==0.4.8 - # via - # pyasn1-modules - # rsa -pyparsing==2.4.7 - # via httplib2 -requests-oauthlib==1.3.0 - # via google-auth-oauthlib -requests==2.22.0 - # via requests-oauthlib -rsa==4.0 - # via google-auth -six==1.13.0 - # via - # google-api-python-client - # google-auth -tqdm==4.38.0 - # via -r requirements.in -uritemplate==3.0.0 - # via google-api-python-client -urllib3==1.25.7 - # via requests - -# The following packages are considered to be unsafe in a requirements file: -# setuptools