Skip to content

Commit

Permalink
fix(v2client): fix v2 client org header
Browse files Browse the repository at this point in the history
  • Loading branch information
smrutisenapati authored and pallabpain committed Sep 4, 2024
1 parent 4f5e9bb commit 313c660
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
50 changes: 19 additions & 31 deletions riocli/v2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@
from hashlib import md5
from typing import List, Optional, Dict, Any

import click
import magic
import requests
from munch import munchify, Munch
from rapyuta_io.utils.rest_client import HttpMethod, RestClient

from riocli.v2client.enums import DeploymentPhaseConstants
from riocli.v2client.error import RetriesExhausted, DeploymentNotRunning, ImagePullError


class DeploymentNotFound(Exception):
def __init__(self, message='deployment not found!'):
self.message = message
super().__init__(self.message)
from riocli.v2client.error import (RetriesExhausted, DeploymentNotRunning, ImagePullError,
NetworkNotFound)


def handle_server_errors(response: requests.Response):
Expand All @@ -58,12 +52,6 @@ def handle_server_errors(response: requests.Response):
raise Exception('unknown server error')


class NetworkNotFound(Exception):
def __init__(self, message='network not found!'):
self.message = message
super().__init__(self.message)


class Client(object):
"""
v2 API Client
Expand Down Expand Up @@ -738,7 +726,7 @@ def list_packages(
List all packages in a project
"""
url = "{}/v2/packages/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand Down Expand Up @@ -766,7 +754,7 @@ def create_package(self, payload: dict) -> Munch:
Create a new package
"""
url = "{}/v2/packages/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.POST).headers(
headers).execute(payload=payload)
handle_server_errors(response)
Expand All @@ -787,7 +775,7 @@ def get_package(
List all packages in a project
"""
url = "{}/v2/packages/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand All @@ -807,7 +795,7 @@ def delete_package(self, package_name: str,
Delete a secret
"""
url = "{}/v2/packages/{}/".format(self._host, package_name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand All @@ -831,7 +819,7 @@ def list_networks(
List all networks in a project
"""
url = "{}/v2/networks/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand Down Expand Up @@ -859,7 +847,7 @@ def create_network(self, payload: dict) -> Munch:
Create a new network
"""
url = "{}/v2/networks/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.POST).headers(
headers).execute(payload=payload)
handle_server_errors(response)
Expand All @@ -880,7 +868,7 @@ def get_network(
get a network in a project
"""
url = "{}/v2/networks/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand All @@ -904,7 +892,7 @@ def delete_network(self, network_name: str,
Delete a secret
"""
url = "{}/v2/networks/{}/".format(self._host, network_name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand All @@ -928,7 +916,7 @@ def list_deployments(
List all deployments in a project
"""
url = "{}/v2/deployments/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {
"continue": 0,
Expand Down Expand Up @@ -957,7 +945,7 @@ def create_deployment(self, deployment: dict) -> Munch:
Create a new deployment
"""
url = "{}/v2/deployments/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

deployment["metadata"]["projectGUID"] = headers["project"]
response = RestClient(url).method(HttpMethod.POST).headers(
Expand All @@ -976,7 +964,7 @@ def get_deployment(
query: dict = None
):
url = "{}/v2/deployments/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand All @@ -999,7 +987,7 @@ def update_deployment(self, name: str, dep: dict) -> Munch:
Update a deployment
"""
url = "{}/v2/deployments/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.PATCH).headers(
headers).execute(payload=dep)
handle_server_errors(response)
Expand All @@ -1015,7 +1003,7 @@ def delete_deployment(self, name: str, query: dict = None) -> Munch:
Delete a deployment
"""
url = "{}/v2/deployments/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
params = {}
params.update(query or {})
response = RestClient(url).method(
Expand Down Expand Up @@ -1070,7 +1058,7 @@ def list_disks(
List all disks in a project
"""
url = "{}/v2/disks/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()

params = {}
params.update(query or {})
Expand Down Expand Up @@ -1098,7 +1086,7 @@ def get_disk(self, name: str) -> Munch:
Get a Disk by its name
"""
url = "{}/v2/disks/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
response = RestClient(url).method(
HttpMethod.GET).headers(headers).execute()

Expand All @@ -1116,7 +1104,7 @@ def create_disk(self, disk: dict) -> Munch:
Create a new disk
"""
url = "{}/v2/disks/".format(self._host)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.POST).headers(
headers).execute(payload=disk)

Expand All @@ -1134,7 +1122,7 @@ def delete_disk(self, name: str) -> Munch:
Delete a disk by its name
"""
url = "{}/v2/disks/{}/".format(self._host, name)
headers = self._config.get_auth_header()
headers = self._get_auth_header()
response = RestClient(url).method(
HttpMethod.DELETE).headers(headers).execute()

Expand Down
16 changes: 14 additions & 2 deletions riocli/v2client/error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class RetriesExhausted(Exception):
def __init__(self, msg=None):
Exception.__init__(self, msg)
Expand All @@ -8,6 +7,19 @@ class DeploymentNotRunning(Exception):
def __init__(self, msg=None):
Exception.__init__(self, msg)


class ImagePullError(Exception):
def __init__(self, msg=None):
Exception.__init__(self, msg)
Exception.__init__(self, msg)


class NetworkNotFound(Exception):
def __init__(self, message='network not found!'):
self.message = message
super().__init__(self.message)


class DeploymentNotFound(Exception):
def __init__(self, message='deployment not found!'):
self.message = message
super().__init__(self.message)

0 comments on commit 313c660

Please sign in to comment.