Skip to content

Commit 652350f

Browse files
committed
Implement first version
1 parent 4aad9e4 commit 652350f

File tree

241 files changed

+37698
-2
lines changed

Some content is hidden

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

241 files changed

+37698
-2
lines changed

poetry.lock

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

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ ucb-api = "ucb_api.main:app"
1111
[tool.poetry.dependencies]
1212
python = "^3.7"
1313
typer = {extras = ["all"], version = "^0.3.2"}
14+
pylint = "^2.6.0"
15+
python_dateutil = "^2.8.1"
16+
six = "^1.15.0"
17+
urllib3 = "^1.25.10"
18+
certifi = "^2020.6.20"
1419

1520
[tool.poetry.dev-dependencies]
1621
pytest = "^5.2"

ucb_api/api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .buildtargets_api import BuildtargetsApi

ucb_api/api/buildtargets_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List
2+
from ..python_client.swagger_client.api_client import ApiClient
3+
from ..python_client.swagger_client.api import BuildtargetsApi as BaseBuildtargetsApi
4+
from ..models import InlineBuildTarget
5+
6+
7+
class BuildtargetsApi(BaseBuildtargetsApi):
8+
def __init__(self, api_client=None):
9+
super().__init__(api_client=api_client)
10+
11+
def get_build_targets(self, orgid, projectid, **kwargs): # noqa: E501
12+
try:
13+
data = super().get_build_targets(orgid, projectid, **kwargs)
14+
result: List[InlineBuildTarget] = []
15+
for item in data:
16+
result.append(InlineBuildTarget.factory(item))
17+
return result
18+
except Exception as e:
19+
raise e

ucb_api/api_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .python_client.swagger_client.api_client import ApiClient as BaseApiClient
2+
3+
4+
class ApiClient(BaseApiClient):
5+
def update_params_for_auth(self, headers, querys, _):
6+
"""Updates header and query params based on authentication setting.
7+
8+
:param headers: Header parameters dict to be updated.
9+
:param querys: Query parameters tuple list to be updated.
10+
"""
11+
auth_setting = self.configuration.auth_settings().get('apikey')
12+
if auth_setting:
13+
if not auth_setting['value']:
14+
raise Exception('Value auth settings not found')
15+
elif auth_setting['in'] == 'header':
16+
headers[auth_setting['key']] = auth_setting['value']
17+
elif auth_setting['in'] == 'query':
18+
querys.append((auth_setting['key'], auth_setting['value']))
19+
else:
20+
raise ValueError(
21+
'Authentication token must be in `query` or `header`'
22+
)

ucb_api/configuration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import urllib3
2+
3+
from .python_client.swagger_client.configuration import Configuration as BaseConfiguration
4+
5+
6+
class Configuration(BaseConfiguration):
7+
def __init__(self, api_key):
8+
super().__init__()
9+
self.key = api_key
10+
self.host = 'https://build-api.cloud.unity3d.com/api/v1'
11+
12+
def get_basic_auth_token(self):
13+
"""Gets HTTP basic authentication header (string).
14+
15+
:return: The token for basic HTTP authentication.
16+
"""
17+
return f'Basic {self.key}'

ucb_api/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,53 @@
11
import typer
22

3+
from json import load
4+
from os import getenv, putenv, system
5+
from pprint import pprint
6+
from typing import Optional
7+
8+
from .api import BuildtargetsApi
9+
from .api_client import ApiClient
10+
from .configuration import Configuration
11+
from .python_client.swagger_client.rest import ApiException
12+
from .utils import get_buildtargets, set_envvar_buildtarget
13+
314

415
app = typer.Typer()
516

17+
buildtargets_app = typer.Typer()
18+
19+
app.add_typer(buildtargets_app, name='buildtargets')
20+
621

722
@app.callback()
823
def callback():
924
"""
1025
Python package for Unity Cloud Build api
1126
"""
27+
28+
29+
@buildtargets_app.command()
30+
def set_var_json(json_dir: str, platform: Optional[str] = typer.Option('all', help='android, ios or all'), replace: bool = typer.Option(False, '--replace'), app_name: Optional[str] = typer.Option('', '--name')):
31+
with open(json_dir) as file:
32+
json = load(file)
33+
buildtargetslist = get_buildtargets(platform, app_name)
34+
set_envvar_buildtarget(buildtargetslist, json, replace)
35+
36+
37+
@buildtargets_app.command()
38+
def set_var(name: str, value: str, platform: Optional[str] = typer.Option('all', help='android, ios or all'), replace: bool = typer.Option(False, '--replace'), app_name: Optional[str] = typer.Option('', '--name')):
39+
buildtargetslist = get_buildtargets(platform, app_name)
40+
set_envvar_buildtarget(buildtargetslist, {name: value}, replace)
41+
42+
43+
@buildtargets_app.command()
44+
def get_list(platform: Optional[str] = typer.Option('all', help='android, ios or all'), name: Optional[str] = typer.Option('')):
45+
result = get_buildtargets(platform, name)
46+
typer.echo([item.buildtargetid for item in result])
47+
48+
49+
@app.command()
50+
def show_env_vars():
51+
typer.echo(f'UCB_API_KEY: {getenv("UCB_API_KEY")}')
52+
typer.echo(f'UCB_ORG_ID: {getenv("UCB_ORG_ID")}')
53+
typer.echo(f'UCB_PROJECT_ID: {getenv("UCB_PROJECT_ID")}')

ucb_api/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .inline_build_target import InlineBuildTarget
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from ..python_client.swagger_client.models import InlineResponse2007
2+
3+
4+
class InlineBuildTarget(InlineResponse2007):
5+
def __init__(self, name=None, platform=None, buildtargetid=None, enabled=None, settings=None, last_built=None, credentials=None, builds=None, links=None):
6+
super().__init__(name=name, platform=platform, buildtargetid=buildtargetid, enabled=enabled, settings=settings, last_built=last_built, credentials=credentials, builds=builds, links=links)
7+
8+
@staticmethod
9+
def factory(obj: InlineResponse2007):
10+
return InlineBuildTarget(obj.name, obj.platform, obj.buildtargetid, obj.enabled, obj.settings, obj.last_built, obj.credentials, obj.builds, obj.links)

ucb_api/python_client/.gitignore

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
venv/
48+
.python-version
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
57+
# Sphinx documentation
58+
docs/_build/
59+
60+
# PyBuilder
61+
target/
62+
63+
#Ipython Notebook
64+
.ipynb_checkpoints

0 commit comments

Comments
 (0)