Skip to content

Commit e2904e0

Browse files
authored
Merge pull request #2 from jitsecurity/sc-19672-create-a-tool-to-generate-teams-from-github-part2
Sc 19672 create a tool to generate teams from GitHub part2
2 parents e107743 + 06334d1 commit e2904e0

25 files changed

Lines changed: 875 additions & 190 deletions

.github/workflows/linter.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Pre-Commit checks
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
- '!main'
8+
jobs:
9+
linter:
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python 3.8
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: 3.8
17+
- uses: pre-commit/action@v3.0.0

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
run-tests:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.8
18+
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r requirements-test.txt
23+
24+
- name: Run tests
25+
run: pytest --cov --setup-show --log-cli-level INFO tests
26+
27+
- name: Upload coverage reports to Codecov
28+
uses: codecov/codecov-action@v3
29+
env:
30+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- repo: https://github.com/PyCQA/flake8
8+
rev: 4.0.1
9+
hooks:
10+
- id: flake8
11+
exclude: tests/.
12+
args:
13+
- --max-line-length=120

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ configure:
1818
echo "JIT_CLIENT_SECRET=$$client_secret" >> .env; \
1919
echo "GITHUB_API_TOKEN=$$github_token" >> .env
2020

21-
run:
22-
source venv-jit/bin/activate && python main.py
21+
create-teams:
22+
source venv-jit/bin/activate && \
23+
export PYTHONPATH=$(CURDIR) && \
24+
python src/utils/github_topics_to_json_file.py && \
25+
python src/scripts/create_teams.py --input teams.json
2326

2427
help:
2528
@echo "Usage: make [target]"
2629
@echo ""
2730
@echo "Targets:"
28-
@echo " install Install dependencies"
29-
@echo " configure Configure environment variables"
30-
@echo " run Run the main script"
31-
@echo " help Show this help message"
31+
@echo " install Install dependencies"
32+
@echo " configure Configure environment variables"
33+
@echo " create-teams Create teams based on input file"
34+
@echo " help Show this help message"

README.md

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
# jit-create-teams-from-github-topics
1+
# Jit Customer Scripts
22

3-
This project is a Python script that interacts with the GitHub API and the JIT Teams API.\
4-
It lists the repository names and topics for a given GitHub organization and generates teams according to the topics from Github.
3+
[![codecov](https://codecov.io/gh/jitsecurity/jit-customer-scripts/graph/badge.svg?token=76IhFwTPjv)](https://codecov.io/gh/jitsecurity/jit-customer-scripts)
4+
5+
This project provides customer scripts to help them with their JIT solution. \
6+
The `create-teams.py` script's goal is to create teams and update assets based on the provided JSON file.
7+
8+
## Project Structure
9+
10+
The project has the following structure:
11+
12+
```
13+
jit-customer-scripts/
14+
├── src/
15+
│ └── scripts/
16+
│ └── create_teams.py
17+
├── src/
18+
│ └── utils/
19+
│ └── github_topic_to_json_file.py
20+
├── src/
21+
│ └── shared/
22+
│ └── models.py
23+
│ └── ...
24+
├── Makefile
25+
└── README.md
26+
```
27+
28+
- `scripts/`: Contains the customer scripts.
29+
- `src/shared/models.py`: Contains the data models used by the scripts.
30+
- `.env`: Configuration file generated by the Makefile.
31+
- `Makefile`: Provides commands to help with project setup and execution.
32+
- `README.md`: This file.
533

634
## Prerequisites
735

@@ -13,13 +41,13 @@ It lists the repository names and topics for a given GitHub organization and gen
1341
1. Clone the repository:
1442

1543
```shell
16-
git clone git@github.com:jitsecurity/jit-create-teams-from-github-topics.git
44+
git clone git@github.com:jitsecurity/jit-customer-scripts.git
1745
```
1846

1947
2. Change into the project directory:
2048

2149
```shell
22-
cd jit-create-teams-from-github-topics
50+
cd jit-customer-scripts
2351
```
2452

2553
3. Create a virtual environment and install the required dependencies:
@@ -39,42 +67,69 @@ Before running the script, you need to configure the necessary environment varia
3967
```
4068

4169
2. Enter the required information when prompted:
42-
- GitHub organization name
43-
- API client ID
44-
- API client secret
45-
- GitHub token
70+
- GitHub organization name
71+
- API client ID
72+
- API client secret
73+
- GitHub token
4674

4775
3. The command will generate a `.env` file with the provided information.
4876

4977
## Usage
5078

51-
To run the script and retrieve the repository names and topics, use the following command:
79+
To run the script and create teams and update assets, use the following command:
5280

5381
```shell
54-
make run
55-
```
82+
make create-teams
83+
```
84+
85+
This command is a convenience utility that extracts the teams to generate from Github topics. \
86+
It runs these commands:
87+
```bash
88+
python src/utils/github_topics_to_json_file.py
89+
python src/scripts/create_teams.py --input teams.json
90+
```
91+
92+
This command will fetch the repository names and topics from the GitHub API and generate the JSON file. And then it will create the teams and update the assets.
5693

57-
### Using external json file with the --input argument
94+
### Using External JSON File
5895

5996
You can also provide a JSON file containing team details using the `--input` argument. The JSON file should have the following structure:
6097

6198
```json
62-
[
63-
{
64-
"name": "Repository 1",
65-
"topics": ["topic1", "topic2"]
66-
},
67-
{
68-
"name": "Repository 2",
69-
"topics": ["topic3"]
70-
}
71-
]
99+
{
100+
"teams": [
101+
{
102+
"name": "Team 1",
103+
"members": ["user1", "user2"],
104+
"resources": [
105+
{
106+
"type": "{resource_type}",
107+
"name": "Resource 1"
108+
},
109+
{
110+
"type": "{resource_type}",
111+
"name": "Resource 2"
112+
}
113+
]
114+
},
115+
{
116+
"name": "Team 2",
117+
"members": ["user3", "user4"],
118+
"resources": [
119+
{
120+
"type": "{resource_type}",
121+
"name": "Resource 3"
122+
}
123+
]
124+
}
125+
]
126+
}
72127
```
73128

74129
To use the `--input` argument, run the following command:
75130

76131
```shell
77-
python main.py --input path/to/teams.json
132+
python scripts/create_teams.py --input path/to/teams.json
78133
```
79134

80135
Replace `path/to/teams.json` with the actual path to your JSON file.
@@ -83,4 +138,4 @@ Replace `path/to/teams.json` with the actual path to your JSON file.
83138

84139
To override the default Frontegg authentication endpoint, you can set the `FRONTEGG_AUTH_ENDPOINT` environment variable. If the variable is not set, the default value will be used.
85140

86-
To override Jit's API end point, you can set the `JIT_API_ENDPOINT` environment variable. If the variable is not set, the default value will be used.
141+
To override Jit's API endpoint, you can set the `JIT_API_ENDPOINT` environment variable. If the variable is not set, the default value will be used.

main.py

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)