mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 10:15:35 +01:00
Build python swagger client for V2.0
Add v2 swagger.yaml python library. Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
parent
86b3e47f81
commit
03668ad372
9
Makefile
9
Makefile
@ -496,9 +496,12 @@ swagger_client:
|
|||||||
@echo "Generate swagger client"
|
@echo "Generate swagger client"
|
||||||
wget -q https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar -O swagger-codegen-cli.jar
|
wget -q https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar -O swagger-codegen-cli.jar
|
||||||
rm -rf harborclient
|
rm -rf harborclient
|
||||||
mkdir harborclient
|
mkdir -p harborclient/harbor_swagger_client
|
||||||
java -jar swagger-codegen-cli.jar generate -i api/v2.0/legacy_swagger.yaml -l python -o harborclient
|
mkdir -p harborclient/harbor_v2_swagger_client
|
||||||
cd harborclient; python ./setup.py install
|
java -jar swagger-codegen-cli.jar generate -i api/v2.0/legacy_swagger.yaml -l python -o harborclient/harbor_swagger_client -DpackageName=swagger_client
|
||||||
|
java -jar swagger-codegen-cli.jar generate -i api/v2.0/swagger.yaml -l python -o harborclient/harbor_v2_swagger_client -DpackageName=v2_swagger_client
|
||||||
|
cd harborclient/harbor_swagger_client; python ./setup.py install
|
||||||
|
cd harborclient/harbor_v2_swagger_client; python ./setup.py install
|
||||||
pip install docker -q
|
pip install docker -q
|
||||||
pip freeze
|
pip freeze
|
||||||
|
|
||||||
|
9
tests/apitests/python/library/artifact.py
Normal file
9
tests/apitests/python/library/artifact.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import base
|
||||||
|
import v2_swagger_client
|
||||||
|
from v2_swagger_client.rest import ApiException
|
||||||
|
|
||||||
|
class Artifact(base.Base):
|
||||||
|
def create_artifact(self, expect_status_code = 201, expect_response_body = None, **kwargs):
|
||||||
|
return None
|
@ -3,6 +3,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import swagger_client
|
import swagger_client
|
||||||
|
import v2_swagger_client
|
||||||
try:
|
try:
|
||||||
from urllib import getproxies
|
from urllib import getproxies
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -19,7 +20,7 @@ class Credential:
|
|||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
def _create_client(server, credential, debug):
|
def _create_client(server, credential, debug, api_type="products"):
|
||||||
cfg = swagger_client.Configuration()
|
cfg = swagger_client.Configuration()
|
||||||
cfg.host = server.endpoint
|
cfg.host = server.endpoint
|
||||||
cfg.verify_ssl = server.verify_ssl
|
cfg.verify_ssl = server.verify_ssl
|
||||||
@ -32,8 +33,10 @@ def _create_client(server, credential, debug):
|
|||||||
proxy = proxies.get('http', proxies.get('all', None))
|
proxy = proxies.get('http', proxies.get('all', None))
|
||||||
if proxy:
|
if proxy:
|
||||||
cfg.proxy = proxy
|
cfg.proxy = proxy
|
||||||
|
return {
|
||||||
return swagger_client.ProductsApi(swagger_client.ApiClient(cfg))
|
"products": swagger_client.ProductsApi(swagger_client.ApiClient(cfg)),
|
||||||
|
"artifact": v2_swagger_client.ArtifactApi(v2_swagger_client.ApiClient(cfg)),
|
||||||
|
}.get(api_type,'Error: Wrong API type')
|
||||||
|
|
||||||
def _assert_status_code(expect_code, return_code):
|
def _assert_status_code(expect_code, return_code):
|
||||||
if str(return_code) != str(expect_code):
|
if str(return_code) != str(expect_code):
|
||||||
@ -64,18 +67,21 @@ class Base:
|
|||||||
def __init__(self,
|
def __init__(self,
|
||||||
server = Server(endpoint="http://localhost:8080/api", verify_ssl=False),
|
server = Server(endpoint="http://localhost:8080/api", verify_ssl=False),
|
||||||
credential = Credential(type="basic_auth", username="admin", password="Harbor12345"),
|
credential = Credential(type="basic_auth", username="admin", password="Harbor12345"),
|
||||||
debug = True):
|
debug = True, api_type = "products"):
|
||||||
if not isinstance(server.verify_ssl, bool):
|
if not isinstance(server.verify_ssl, bool):
|
||||||
server.verify_ssl = server.verify_ssl == "True"
|
server.verify_ssl = server.verify_ssl == "True"
|
||||||
self.server = server
|
self.server = server
|
||||||
self.credential = credential
|
self.credential = credential
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.client = _create_client(server, credential, debug)
|
self.api_type = api_type
|
||||||
|
self.client = _create_client(server, credential, debug, api_type=api_type)
|
||||||
|
|
||||||
def _get_client(self, **kwargs):
|
def _get_client(self, **kwargs):
|
||||||
if len(kwargs) == 0:
|
if len(kwargs) == 0:
|
||||||
return self.client
|
return self.client
|
||||||
server = self.server
|
server = self.server
|
||||||
|
if "api_type" in kwargs:
|
||||||
|
server.api_type = kwargs.get("api_type")
|
||||||
if "endpoint" in kwargs:
|
if "endpoint" in kwargs:
|
||||||
server.endpoint = kwargs.get("endpoint")
|
server.endpoint = kwargs.get("endpoint")
|
||||||
if "verify_ssl" in kwargs:
|
if "verify_ssl" in kwargs:
|
||||||
|
Loading…
Reference in New Issue
Block a user