Skip to content

Commit 7bc6d54

Browse files
committed
Initial import
0 parents  commit 7bc6d54

File tree

11 files changed

+422
-0
lines changed

11 files changed

+422
-0
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request: ~
7+
8+
env:
9+
FORCE_COLOR: 1
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-20.04
14+
steps:
15+
- uses: actions/checkout@master
16+
- uses: actions/cache@v3
17+
with:
18+
path: ~/.local/share/virtualenvs
19+
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
20+
restore-keys: |
21+
${{ runner.os }}-poetry-
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.10'
25+
- name: Install poetry
26+
uses: abatilo/[email protected]
27+
with:
28+
poetry-version: '1.3.1'
29+
- name: Install pip dependencies
30+
run: poetry install
31+
- uses: pre-commit/[email protected]

.github/workflows/publish.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@master
12+
- uses: actions/setup-python@v4
13+
with:
14+
python-version: '3.10'
15+
- name: Install poetry
16+
uses: abatilo/[email protected]
17+
with:
18+
poetry-version: '1.3.1'
19+
- name: Install pip dependencies
20+
run: poetry install
21+
- name: Package
22+
run: poetry build
23+
- name: Publish to PyPI
24+
uses: pypa/gh-action-pypi-publish@master
25+
with:
26+
user: __token__
27+
password: ${{ secrets.pypi_token }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__/
2+
.venv/
3+
.mypy_cache/
4+
/.envrc

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-toml
9+
- id: check-added-large-files
10+
- repo: https://github.com/psf/black
11+
rev: 22.10.0
12+
hooks:
13+
- id: black
14+
- repo: https://github.com/pre-commit/mirrors-isort
15+
rev: v5.10.1
16+
hooks:
17+
- id: isort
18+
additional_dependencies: [toml]
19+
- repo: https://github.com/pre-commit/mirrors-mypy
20+
rev: v0.991
21+
hooks:
22+
- id: mypy
23+
additional_dependencies: [types-requests]

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Edge Addons API
2+
3+
An API client for publishing addons to the Edge store.
4+
5+
Based on the [PlasmHQ Edge Addons API](https://github.com/PlasmoHQ/edge-addons-api).
6+
7+
## Usage
8+
9+
Obtain the required options for your project. These can be obtained by following the [Microsoft Edge Add-Ons API guide](https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/publish/api/using-addons-api).
10+
11+
Once obtained you can submit you addon like below:
12+
13+
14+
```python
15+
from edge_addons_api.client import Options, Client
16+
17+
options = Options(
18+
product_id="Your product ID",
19+
client_id="Your client ID",
20+
client_secret="Your client secret",
21+
access_token_url="Your access token URL"
22+
)
23+
24+
client = Client(options)
25+
26+
client.submit(
27+
file_path="/path/to/extension.zip",
28+
notes="Your upload notes"
29+
)
30+
31+
```
32+
33+
## License
34+
35+
MIT

edge_addons_api/__init__.py

Whitespace-only changes.

edge_addons_api/client.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from dataclasses import dataclass
2+
3+
import requests
4+
5+
6+
@dataclass
7+
class Options:
8+
product_id: str
9+
client_id: str
10+
client_secret: str
11+
access_token_url: str
12+
13+
14+
class Client:
15+
16+
BASE_URL = "https://api.addons.microsoftedge.microsoft.com"
17+
18+
def __init__(self, options: Options):
19+
self.options = options
20+
21+
def submit(self, file_path: str, notes: str):
22+
access_token = self._get_access_token()
23+
self._upload(file_path, access_token)
24+
self._publish(notes, access_token)
25+
26+
def _publish(self, notes: str, access_token: str):
27+
response = requests.post(
28+
self._publish_endpoint(),
29+
data={"notes": notes},
30+
headers={
31+
"Authorization": f"Bearer {access_token}",
32+
},
33+
)
34+
35+
response.raise_for_status()
36+
37+
def _upload(self, file_path: str, access_token: str):
38+
39+
files = {"file": open(file_path, "rb")}
40+
41+
response = requests.post(
42+
self._upload_endpoint(),
43+
files=files,
44+
headers={
45+
"Authorization": f"Bearer {access_token}",
46+
"Content-Type": "application/zip",
47+
},
48+
)
49+
50+
response.raise_for_status()
51+
52+
def _get_access_token(self) -> str:
53+
response = requests.post(
54+
self.options.access_token_url,
55+
data={
56+
"client_id": self.options.client_id,
57+
"scope": f"{self.BASE_URL}/.default",
58+
"client_secret": self.options.client_secret,
59+
"grant_type": "client_credentials",
60+
},
61+
)
62+
63+
response.raise_for_status()
64+
65+
json = response.json()
66+
67+
return json["access_token"]
68+
69+
def _product_endpoint(self) -> str:
70+
return f"{self.BASE_URL}/v1/products/{self.options.product_id}"
71+
72+
def _publish_endpoint(self) -> str:
73+
return f"{self._product_endpoint()}/submissions"
74+
75+
def _upload_endpoint(self) -> str:
76+
return f"{self._publish_endpoint()}/draft/package"

poetry.lock

Lines changed: 181 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)