Skip to content

Commit

Permalink
Merge 9f895f2 into 16de349
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck committed Aug 20, 2018
2 parents 16de349 + 9f895f2 commit d2c85da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ import tes
task = tes.Task(
executors=[
Executor(
tes.Executor(
image="alpine",
command=["echo", "hello"]
)
Expand Down
27 changes: 20 additions & 7 deletions tes/client.py
Expand Up @@ -5,11 +5,13 @@
import time

from attr import attrs, attrib
from attr.validators import instance_of
from attr.validators import instance_of, optional
from builtins import str
from requests.utils import urlparse

from tes.models import (Task, ListTasksRequest, ListTasksResponse, ServiceInfo,
GetTaskRequest, CancelTaskRequest, CreateTaskResponse)
GetTaskRequest, CancelTaskRequest, CreateTaskResponse,
strconv)
from tes.utils import unmarshal, raise_for_status, TimeoutError


Expand All @@ -21,6 +23,12 @@ def process_url(value):
class HTTPClient(object):
url = attrib(convert=process_url)
timeout = attrib(default=10, validator=instance_of(int))
user = attrib(default=None,
convert=strconv,
validator=optional(instance_of(str)))
password = attrib(default=None,
convert=strconv,
validator=optional(instance_of(str)))

@url.validator
def __check_url(self, attribute, value):
Expand All @@ -34,7 +42,8 @@ def __check_url(self, attribute, value):
def get_service_info(self):
response = requests.get(
"%s/v1/tasks/service-info" % (self.url),
timeout=self.timeout
timeout=self.timeout,
auth=(self.user, self.password)
)
raise_for_status(response)
return unmarshal(response.json(), ServiceInfo)
Expand All @@ -48,7 +57,8 @@ def create_task(self, task):
"%s/v1/tasks" % (self.url),
data=msg,
headers={'Content-Type': 'application/json'},
timeout=self.timeout
timeout=self.timeout,
auth=(self.user, self.password)
)
raise_for_status(response)
return unmarshal(response.json(), CreateTaskResponse).id
Expand All @@ -59,7 +69,8 @@ def get_task(self, task_id, view="BASIC"):
response = requests.get(
"%s/v1/tasks/%s" % (self.url, req.id),
params=payload,
timeout=self.timeout
timeout=self.timeout,
auth=(self.user, self.password)
)
raise_for_status(response)
return unmarshal(response.json(), Task)
Expand All @@ -68,7 +79,8 @@ def cancel_task(self, task_id):
req = CancelTaskRequest(task_id)
response = requests.post(
"%s/v1/tasks/%s:cancel" % (self.url, req.id),
timeout=self.timeout
timeout=self.timeout,
auth=(self.user, self.password)
)
raise_for_status(response)
return
Expand All @@ -86,7 +98,8 @@ def list_tasks(self, view="MINIMAL", page_size=None, page_token=None):
response = requests.get(
"%s/v1/tasks" % (self.url),
params=msg,
timeout=self.timeout
timeout=self.timeout,
auth=(self.user, self.password)
)
raise_for_status(response)
return unmarshal(response.json(), ListTasksResponse)
Expand Down

0 comments on commit d2c85da

Please sign in to comment.