Skip to content

Commit fbc42a4

Browse files
committed
Merge branch 'master' into feature/add-session-service
2 parents 5a957b4 + 09a4362 commit fbc42a4

20 files changed

+1692
-90
lines changed

.deepsource.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version = 1
2+
3+
test_patterns = ["tests/**"]
4+
5+
[[analyzers]]
6+
name = "secrets"
7+
enabled = true
8+
9+
[[analyzers]]
10+
name = "python"
11+
enabled = true
12+
13+
[analyzers.meta]
14+
runtime_version = "3.x.x"

.github/workflows/master_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ArgoPy CI
1+
name: Master Coverage CI
22

33
on:
44
push:

.github/workflows/mr_ci.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,36 @@ jobs:
3838
flake8 --count --show-source --statistics --exclude .git,build_env,test_env,__init__.py --max-line-length 88 .
3939
- name: Coverage with pytest
4040
run: |
41-
pytest --no-cov-on-fail --cov argocd --cov-report html --cov-report term --cov-report xml tests
42-
./codecov -t ${CODECOV_TOKEN}
41+
pytest --no-cov-on-fail --cov argocd --cov-report html --cov-report term --cov-report xml tests/unit
42+
./codecov -t ${CODECOV_TOKEN} -F unit
43+
scan:
44+
runs-on: ubuntu-latest
45+
permissions:
46+
contents: read
47+
steps:
48+
- name: 'Checkout Repository'
49+
uses: actions/checkout@v3
50+
- name: 'Dependency Review'
51+
uses: actions/dependency-review-action@v2
52+
analyze:
53+
runs-on: ubuntu-latest
54+
permissions:
55+
actions: read
56+
contents: read
57+
security-events: write
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
language: [ 'python' ]
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v3
65+
- name: Initialize CodeQL
66+
uses: github/codeql-action/init@v2
67+
with:
68+
languages: ${{ matrix.language }}
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v2
71+
with:
72+
category: "/language:${{matrix.language}}"
73+

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.vscode/
2-
build_env/
3-
test_env/
2+
env*/
43
argocd.egg-info/
54
dist/
65
__pycache__/

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
argopy
1+
argocd
22
======
33

4+
## Actions
5+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/onlinejudge95/argocd/ArgoPy%20CI)
6+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/onlinejudge95/argocd/Production%20CD?label=release)
7+
8+
## Coverage
9+
[![codecov](https://codecov.io/gh/onlinejudge95/argocd/branch/master/graph/badge.svg?token=GMiBQNT6jf)](https://codecov.io/gh/onlinejudge95/argocd)
10+
![Codecov branch](https://img.shields.io/codecov/c/github/onlinejudge95/argocd/master?label=master%20coverage)
11+
12+
## GitHub
13+
![GitHub top language](https://img.shields.io/github/languages/top/onlinejudge95/argocd)
14+
![GitHub repo size](https://img.shields.io/github/repo-size/onlinejudge95/argocd)
15+
![GitHub repo file count](https://img.shields.io/github/directory-file-count/onlinejudge95/argocd)
16+
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/onlinejudge95/argocd)
17+
18+
## PyPI
19+
![PyPI - Downloads](https://img.shields.io/pypi/dm/argocd)
20+
![PyPI - Status](https://img.shields.io/pypi/status/argocd)
21+
![PyPI](https://img.shields.io/pypi/v/argocd)
22+
![PyPI - Implementation](https://img.shields.io/pypi/implementation/argocd)
23+
![PyPI - Wheel](https://img.shields.io/pypi/wheel/argocd)
24+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/argocd)
25+
26+
## License
27+
![GitHub](https://img.shields.io/github/license/onlinejudge95/argocd)
28+
29+
## DeepSource
30+
[![DeepSource](https://deepsource.io/gh/onlinejudge95/argocd.svg/?label=active+issues&show_trend=true&token=k4vYSD7ZovLMXroo2Kxi9z3q)](https://deepsource.io/gh/onlinejudge95/argocd/?ref=repository-badge)
31+
32+
## GitLocalization
33+
[![gitlocalized ](https://gitlocalize.com/repo/8068/whole_project/badge.svg)](https://gitlocalize.com/repo/8068/whole_project?utm_source=badge)
34+
435
Python client for argocd server. This provides unique interface for the argocd REST APIs.

argocd/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ class Config:
88
server_url: str = dataclasses.field(
99
default_factory=functools.partial(os.environ.get, "ARGOCD_API_BASE_URL")
1010
)
11+
authentication_token: str = dataclasses.field(
12+
default_factory=functools.partial(os.environ.get, "ARGOCD_API_AUTH_TOKEN")
13+
)

argocd/services/certificate.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from requests import sessions
2+
3+
from argocd import config
4+
5+
6+
class CertificateService:
7+
def __init__(self, token=None):
8+
self.config = config.Config()
9+
self.session = sessions.Session()
10+
self.base_url = self.config.server_url
11+
token = token or self.config.authentication_token
12+
13+
self.session.headers.update({"Authorization": f"Bearer {token}"})
14+
15+
def list(self, host_name_pattern="", cert_type="", cert_sub_type=""):
16+
"""
17+
List all available repository certificates
18+
"""
19+
params = {}
20+
if host_name_pattern:
21+
params["hostNamePattern"] = host_name_pattern
22+
if cert_type:
23+
params["certYype"] = cert_type
24+
if cert_sub_type:
25+
params["certSubType"] = cert_sub_type
26+
27+
response = self.session.get(
28+
f"{self.base_url}/api/v1/certificates", params=params
29+
)
30+
return response.json()
31+
32+
def create(self, payload, upsert=False):
33+
"""
34+
Creates repository certificates on the server
35+
"""
36+
params = {}
37+
if upsert:
38+
params["upsert"] = upsert
39+
40+
response = self.session.post(
41+
f"{self.base_url}/api/v1/certificates", params=params, json=payload
42+
)
43+
return response.json()
44+
45+
def delete(self, host_name_pattern="", cert_type="", cert_sub_type=""):
46+
"""
47+
Delete the certificates that match the RepositoryCertificateQuery
48+
"""
49+
params = {}
50+
if host_name_pattern:
51+
params["hostNamePattern"] = host_name_pattern
52+
if cert_type:
53+
params["certYype"] = cert_type
54+
if cert_sub_type:
55+
params["certSubType"] = cert_sub_type
56+
57+
response = self.session.delete(
58+
f"{self.base_url}/api/v1/certificates", params=params
59+
)
60+
return response.json()

argocd/services/repository.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
from requests import sessions
2+
3+
from argocd import config
4+
5+
6+
class RepositoryService:
7+
def __init__(self, token=None):
8+
self.config = config.Config()
9+
self.session = sessions.Session()
10+
self.base_url = self.config.server_url
11+
token = token or self.config.authentication_token
12+
13+
self.session.headers.update({"Authorization": f"Bearer {token}"})
14+
15+
def list(self, repo=None, force_refresh=False):
16+
"""ListRepositories gets a list of all configured repositories"""
17+
params = {}
18+
if repo:
19+
params["repo"] = repo
20+
if force_refresh:
21+
params["forceRefresh"] = force_refresh
22+
23+
response = self.session.get(
24+
f"{self.base_url}/api/v1/repositories", params=params
25+
)
26+
return response.json()
27+
28+
def create(self, payload, upsert=False, creds_only=False):
29+
"""CreateRepository creates a new repository configuration"""
30+
params = {}
31+
if upsert:
32+
params["upsert"] = upsert
33+
if creds_only:
34+
params["credsOnly"] = creds_only
35+
36+
response = self.session.post(
37+
f"{self.base_url}/api/v1/repositories", params=params, json=payload
38+
)
39+
return response.json()
40+
41+
def update(self, repo, payload):
42+
"""UpdateRepository updates a repository configuration"""
43+
response = self.session.put(
44+
f"{self.base_url}/api/v1/repositories/{repo}", json=payload
45+
)
46+
return response.json()
47+
48+
def get(self, repo, force_refresh=False):
49+
"""Get returns a repository or its credentials"""
50+
params = {}
51+
if force_refresh:
52+
params["forceRefresh"] = force_refresh
53+
54+
response = self.session.get(
55+
f"{self.base_url}/api/v1/repositories{repo}", params=params
56+
)
57+
return response.json()
58+
59+
def delete(self, repo, force_refresh=False):
60+
"""DeleteRepository deletes a repository from the configuration"""
61+
params = {}
62+
if force_refresh:
63+
params["forceRefresh"] = force_refresh
64+
65+
response = self.session.delete(
66+
f"{self.base_url}/api/v1/repositories{repo}", params=params
67+
)
68+
return response.json()
69+
70+
def list_apps(self, repo, revision=None):
71+
"""ListApps returns list of apps in the repo"""
72+
params = {}
73+
if revision:
74+
params["revision"] = revision
75+
76+
response = self.session.get(
77+
f"{self.base_url}/api/v1/repositories/{repo}/apps", params=params
78+
)
79+
return response.json()
80+
81+
def list_charts(self, repo, force_refresh=False):
82+
"""GetHelmCharts returns list of helm charts in the specified repository"""
83+
params = {}
84+
if force_refresh:
85+
params["forceRefresh"] = force_refresh
86+
87+
response = self.session.get(
88+
f"{self.base_url}/api/v1/repositories{repo}/helmcharts", params=params
89+
)
90+
return response.json()
91+
92+
def list_refs(self, repo, force_refresh=False):
93+
"""RepositoryService_ListRefs"""
94+
params = {}
95+
if force_refresh:
96+
params["forceRefresh"] = force_refresh
97+
98+
response = self.session.get(
99+
f"{self.base_url}/api/v1/repositories{repo}/refs", params=params
100+
)
101+
return response.json()
102+
103+
def validate_access(
104+
self,
105+
repo,
106+
username="",
107+
password="",
108+
ssh_private_key="",
109+
insecure=False,
110+
tls_client_cert_data="",
111+
tls_client_cert_key="",
112+
access_type="",
113+
name="",
114+
enable_oci=False,
115+
github_app_private_key="",
116+
github_app_id="",
117+
github_app_installation_id="",
118+
github_app_enterprise_base_url="",
119+
proxy="",
120+
project="",
121+
):
122+
"""ValidateAccess validates access to a repository with given parameters"""
123+
params = {}
124+
if username != "":
125+
params["username"] = username
126+
if password != "":
127+
params["password"] = password
128+
if ssh_private_key != "":
129+
params["sshPrivateKey"] = ssh_private_key
130+
if insecure:
131+
params["insecure"] = insecure
132+
if tls_client_cert_data != "":
133+
params["tlsClientCertData"] = tls_client_cert_data
134+
if tls_client_cert_key != "":
135+
params["tlsClientCertKey"] = tls_client_cert_key
136+
if access_type != "":
137+
params["type"] = access_type
138+
if name != "":
139+
params["name"] = name
140+
if enable_oci:
141+
params["enableOci"] = enable_oci
142+
if github_app_private_key != "":
143+
params["githubAppPrivateKey"] = github_app_private_key
144+
if github_app_id != "":
145+
params["githubAppID"] = github_app_id
146+
if github_app_installation_id != "":
147+
params["githubAppInstallationID"] = github_app_installation_id
148+
if github_app_enterprise_base_url != "":
149+
params["githubAppEnterpriseBaseUrl"] = github_app_enterprise_base_url
150+
if proxy != "":
151+
params["proxy"] = proxy
152+
if project != "":
153+
params["project"] = project
154+
response = self.session.post(
155+
f"{self.base_url}/api/v1/repositories{repo}/validate", json=repo
156+
)
157+
return response.json()
158+
159+
def get_app(self, repo, payload):
160+
"""GetAppDetails returns application details by given path"""
161+
response = self.session.post(
162+
f"{self.base_url}/api/v1/repositories{repo}/appdetails", json=payload
163+
)
164+
return response.json()

argocd/services/repository_creds.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from requests import sessions
2+
3+
from argocd import config
4+
5+
6+
class RepositoryCredsService:
7+
def __init__(self, token=None):
8+
self.config = config.Config()
9+
self.session = sessions.Session()
10+
self.base_url = self.config.server_url
11+
token = token or self.config.authentication_token
12+
13+
self.session.headers.update({"Authorization": f"Bearer {token}"})
14+
15+
def list(self, repo=""):
16+
"""
17+
ListRepositoryCredentials gets a list of all configured
18+
repository credential sets
19+
"""
20+
params = {}
21+
if repo != "":
22+
params["repo"] = repo
23+
24+
response = self.session.get(f"{self.base_url}/api/v1/repocreds", params=params)
25+
return response.json()
26+
27+
def create(self, payload, upsert=False):
28+
"""
29+
CreateRepositoryCredentials creates a new repository credential set
30+
"""
31+
params = {}
32+
if upsert:
33+
params["upsert"] = upsert
34+
35+
response = self.session.post(
36+
f"{self.base_url}/api/v1/repocreds", params=params, json=payload
37+
)
38+
return response.json()
39+
40+
def update(self, creds, payload):
41+
"""
42+
UpdateRepositoryCredentials updates a repository credential set
43+
"""
44+
response = self.session.put(
45+
f"{self.base_url}/api/v1/repocreds/{creds}", json=payload
46+
)
47+
return response.json()
48+
49+
def delete(self, creds):
50+
"""
51+
DeleteRepositoryCredentials deletes a repository credential set
52+
from the configuration
53+
"""
54+
response = self.session.delete(f"{self.base_url}/api/v1/repocreds/{creds}")
55+
return response.json()

0 commit comments

Comments
 (0)