Skip to content

Commit b787a5b

Browse files
authored
Feat: reimplement in Python (#2)
2 parents 391abb6 + a33caa6 commit b787a5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2002
-405
lines changed

.devcontainer/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.11
2+
3+
RUN apt-get update && apt-get -y install swig libpcsclite-dev
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
USER=compiler
8+
9+
RUN useradd --create-home --shell /bin/bash $USER && \
10+
chown -R $USER /home/$USER
11+
12+
USER $USER
13+
ENV PATH "$PATH:/home/$USER/.local/bin"
14+
WORKDIR /home/$USER/admin
15+
16+
RUN python -m pip install --upgrade pip
17+
18+
COPY compiler_admin compiler_admin
19+
COPY pyproject.toml pyproject.toml
20+
RUN pip install -e .[dev,test]
21+
22+
# install pre-commit environments in throwaway Git repository
23+
# https://stackoverflow.com/a/68758943
24+
COPY .pre-commit-config.yaml .
25+
RUN git init . && \
26+
pre-commit install-hooks && \
27+
rm -rf .git
28+
29+
CMD ["sleep", "infinity"]

.devcontainer/devcontainer.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "compilerla/admin",
3+
"dockerComposeFile": ["../compose.yaml"],
4+
"service": "dev",
5+
"workspaceFolder": "/home/compiler/admin",
6+
"customizations": {
7+
"vscode": {
8+
// Set *default* container specific settings.json values on container create.
9+
"settings": {
10+
"terminal.integrated.defaultProfile.linux": "bash",
11+
"terminal.integrated.profiles.linux": {
12+
"bash": {
13+
"path": "/bin/bash"
14+
}
15+
}
16+
},
17+
// Add the IDs of extensions you want installed when the container is created.
18+
"extensions": [
19+
"eamodio.gitlens",
20+
"esbenp.prettier-vscode",
21+
"mhutchie.git-graph",
22+
"ms-python.python",
23+
"ms-python.black-formatter",
24+
"ms-python.flake8",
25+
"tamasfe.even-better-toml"
26+
]
27+
}
28+
}
29+
}

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GYB-GMail-Backup-*
2+
*.csv

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 127

.github/dependabot.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "pip"
9+
directory: "/" # pyproject.toml
10+
schedule:
11+
interval: "daily"
12+
commit-message:
13+
prefix: "chore"
14+
include: "scope"
15+
labels:
16+
- "dependencies"
17+
- package-ecosystem: "github-actions"
18+
# Workflow files stored in the
19+
# default location of `.github/workflows`
20+
directory: "/"
21+
schedule:
22+
interval: "daily"
23+
commit-message:
24+
prefix: "chore"
25+
include: "scope"
26+
labels:
27+
- "dependencies"

.github/workflows/.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

.github/workflows/pytest.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Pytest
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
pytest:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@v3
13+
14+
- name: Install system packages
15+
run: |
16+
sudo apt-get update -y
17+
sudo apt-get install -y swig libpcsclite-dev
18+
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version-file: .github/workflows/.python-version
22+
cache: pip
23+
cache-dependency-path: "**/pyproject.toml"
24+
25+
- name: Install Python dependencies
26+
run: pip install -e .[test]
27+
28+
- name: Run tests
29+
run: ./tests/run.sh
30+
31+
- name: Upload coverage report
32+
uses: actions/upload-artifact@v3
33+
with:
34+
name: coverage-report
35+
path: ./tests/coverage

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
GYB-GMail-Backup-*
1+
GYB-GMail-Backup-*/
2+
__pycache__
3+
.config
4+
.coverage
5+
.downloads
6+
.pytest_cache
27
*.csv
8+
*.egg-info

.pre-commit-config.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
ci:
2+
autofix_commit_msg: "chore(pre-commit): autofix run"
3+
autoupdate_commit_msg: "chore(pre-commit): autoupdate hooks"
4+
5+
repos:
6+
- repo: https://github.com/compilerla/conventional-pre-commit
7+
rev: v2.3.0
8+
hooks:
9+
- id: conventional-pre-commit
10+
stages: [commit-msg]
11+
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v4.4.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: mixed-line-ending
17+
- id: end-of-file-fixer
18+
- id: check-yaml
19+
args: ["--unsafe"]
20+
- id: check-added-large-files
21+
22+
- repo: https://github.com/psf/black
23+
rev: 23.7.0
24+
hooks:
25+
- id: black
26+
types:
27+
- python
28+
29+
- repo: https://github.com/PyCQA/flake8
30+
rev: 6.1.0
31+
hooks:
32+
- id: flake8
33+
types:
34+
- python
35+
36+
- repo: https://github.com/pycqa/bandit
37+
rev: 1.7.5
38+
hooks:
39+
- id: bandit
40+
args: ["-ll"]
41+
files: .py$

.vscode/settings.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true,
4+
"files.encoding": "utf8",
5+
"files.eol": "\n",
6+
"files.insertFinalNewline": true,
7+
"files.trimFinalNewlines": true,
8+
"files.trimTrailingWhitespace": true,
9+
"[python]": {
10+
"editor.defaultFormatter": "ms-python.black-formatter"
11+
},
12+
"python.formatting.provider": "none",
13+
"python.languageServer": "Pylance",
14+
"python.linting.enabled": true,
15+
"python.linting.flake8Enabled": true,
16+
"python.testing.pytestArgs": ["tests"],
17+
"python.testing.pytestEnabled": true,
18+
"python.testing.unittestEnabled": false
19+
}

README.md

+88-31
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,119 @@
1-
# Google Admin
1+
# Compiler Admin
22

3-
Administrative tasks in Compiler's Google Workspace.
3+
Automating Compiler's administrative tasks.
44

55
Built on top of [GAMADV-XTD3](https://github.com/taers232c/GAMADV-XTD3) and [GYB](https://github.com/GAM-team/got-your-back).
66

7-
## Initial setup
7+
**Note:** This tool can only be used by those with administrator access to Compiler's Google Workspace.
88

9-
Initial setup of a GAMADV-XTD3 project is required to provide necessary API access to the Google Workspace.
9+
## Usage
1010

11-
Follow the steps in the [GAMADV-XTD3 Wiki](https://github.com/taers232c/GAMADV-XTD3/wiki/#requirements), and read
12-
[Compiler's setup notes](https://docs.google.com/document/d/1UEwQzJZyJEkRs3PRwOi0-KXwBFne70am4Nk9-_qYItE/edit#heading=h.gbmx14gcpp2a)
13-
for more information.
11+
```bash
12+
$ compiler-admin -h
13+
usage: compiler-admin [-h] [-v] {info,init,create,convert,delete,offboard,restore,signout} ...
14+
15+
positional arguments:
16+
{info,init,create,convert,delete,offboard,restore,signout}
17+
info Print configuration and debugging information.
18+
init Initialize a new admin project. This command should be run once before any others.
19+
create Create a new user in the Compiler domain.
20+
convert Convert a user account to a new type.
21+
delete Delete a user account.
22+
offboard Offboard a user account.
23+
restore Restore an email backup from a prior offboarding.
24+
signout Signs a user out from all active sessions.
25+
26+
options:
27+
-h, --help show this help message and exit
28+
-v, --version show program's version number and exit
29+
```
1430
15-
Additionally, GYB is used for Gmail backup/restore. See the [GYB Wiki](https://github.com/GAM-team/got-your-back/wiki)
16-
for more information.
31+
## Getting started
1732
18-
**Note:** This setup can only be performed by those with administrator access to Compiler's Google Workspace.
33+
```bash
34+
git clone https://github.com/compilerla/compiler-admin.git
1935
20-
## Creating a user
36+
cd compiler-admin
37+
```
38+
39+
Now open in VS Code, and when prompted, reopen in the devcontainer.
2140
22-
**Usage:**
41+
## Initial setup
42+
43+
Initial setup of a GAMADV-XTD3 project and GYB project is required to provide necessary API access to the Google Workspace.
2344
2445
```bash
25-
bin/create.sh USER [OPTIONS]
46+
$ compiler-admin init -h
47+
usage: compiler-admin init [-h] username
48+
49+
positional arguments:
50+
username The user's account name, sans domain.
51+
52+
options:
53+
-h, --help show this help message and exit
2654
```
2755

28-
- `USER` is the username (sans domain) to create
29-
- `OPTIONS` is a list of options for [GAM user create](https://github.com/taers232c/GAMADV-XTD3/wiki/Users#create-a-user)
56+
The `init` commands follows the steps in the [GAMADV-XTD3 Wiki](https://github.com/taers232c/GAMADV-XTD3/wiki/#requirements).
3057

31-
## Convert a user
58+
Additionally, GYB is used for Gmail backup/restore. See the [GYB Wiki](https://github.com/GAM-team/got-your-back/wiki) for more information.
3259

33-
**Usage:**
60+
## Creating a user
3461

3562
```bash
36-
bin/convert.sh USER TYPE
63+
$ compiler-admin create -h
64+
usage: compiler-admin create [-h] username [OPTIONS]
65+
66+
positional arguments:
67+
username The user's account name, sans domain.
68+
69+
options:
70+
-h, --help show this help message and exit
3771
```
3872
39-
- `USER` is the username (sans domain) to convert
40-
- `TYPE` is either `STAFF` to convert the user to a staff member, or `PARTNER` to conver the user to a partner.
73+
Additional options are passed through to GAM, see more about [GAM user create](https://github.com/taers232c/GAMADV-XTD3/wiki/Users#create-a-user)
4174
42-
## Offboarding a user
75+
## Convert a user
76+
77+
```bash
78+
$ compiler-admin convert -h
79+
usage: compiler-admin convert [-h] username {contractor,partner,staff}
80+
81+
positional arguments:
82+
username A Compiler user account name, sans domain.
83+
{contractor,partner,staff}
84+
Target account type for this conversion.
85+
86+
options:
87+
-h, --help show this help message and exit
88+
```
4389
44-
**Usage:**
90+
## Offboarding a user
4591
4692
```bash
47-
bin/offboard.sh USER [ALIAS]
93+
$ compiler-admin offboard -h
94+
usage: compiler-admin offboard [-h] [--alias ALIAS] username
95+
96+
positional arguments:
97+
username A Compiler user account name, sans domain.
98+
99+
options:
100+
-h, --help show this help message and exit
101+
--alias ALIAS Account to assign username as an alias.
48102
```
49103
50-
- `USER` is the username (sans domain) to offboard
51-
- `ALIAS` is optional, and is a username (sans domain) that will get an alias
52-
added for the offboarded `USER`
104+
This script creates a local backup of `USER`'s inbox, see [Restore](#restore-an-email-backup)
53105

54-
Read more about the [offboarding process in Compiler's notes](https://docs.google.com/document/d/1UEwQzJZyJEkRs3PRwOi0-KXwBFne70am4Nk9-_qYItE/edit#heading=h.liqi1hwxykhs).
106+
## Restore an email backup
55107

56-
This script creates a local backup of `USER`'s inbox; a separate script can be run to archive this backup into the `[email protected]` account:
108+
Retore a backup from a prior [Offboarding](#offboarding-a-user) into the `[email protected]` account.
57109

58110
```bash
59-
bin/archive-gmail-backup.sh USER
60-
```
111+
$ compiler-admin restore -h
112+
usage: compiler-admin restore [-h] username
113+
114+
positional arguments:
115+
username The user's account name, sans domain.
61116
62-
- `USER` is the account in compiler.la (sans domain) with a local backup to archive
117+
options:
118+
-h, --help show this help message and exit
119+
```

bin/archive-gmail-backup.sh

-39
This file was deleted.

0 commit comments

Comments
 (0)