Skip to content

Commit 717bd4f

Browse files
Deleted dangerous methods from MarketplaceResource
1 parent 495c63f commit 717bd4f

File tree

3 files changed

+0
-162
lines changed

3 files changed

+0
-162
lines changed

connect/exceptions.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,3 @@ class FileRetrievalError(Message):
145145
def __init__(self, message):
146146
# type: (str) -> None
147147
super(FileRetrievalError, self).__init__(message, 'fileretrieval')
148-
149-
150-
class UpdateResourceError(Message):
151-
def __init__(self, message):
152-
# type: (str) -> None
153-
super(UpdateResourceError, self).__init__(message, 'updateresource')
154-
155-
156-
class DeleteResourceError(Message):
157-
def __init__(self, message):
158-
# type: (str) -> None
159-
super(DeleteResourceError, self).__init__(message, 'deleteresource')

connect/resources/marketplace.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,16 @@
33
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
44
# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.
55

6-
from requests import RequestException
7-
86
from .base import BaseResource
9-
from connect.exceptions import DeleteResourceError, ServerError, UpdateResourceError
107
from ..models import Marketplace
118

129

1310
class MarketplaceResource(BaseResource):
1411
""" Resource to work with :py:class:`connect.models.Marketplace` models.
1512
:param Config config: Config object or ``None`` to use environment config (default).
1613
"""
17-
DELETE_ERR = 'Error deleting marketplace {}: {}'
18-
UPLOAD_ERR = 'Error uploading icon for Marketplace {}: {}'
19-
RESPONSE_ERR = 'Unexpected server response, returned code {} -- Raw response: {}'
2014
resource = 'marketplaces'
2115
model_class = Marketplace
2216

2317
def __init__(self, config=None):
2418
super(MarketplaceResource, self).__init__(config)
25-
26-
def set_icon(self, id_, path):
27-
""" Sets or updates the Marketplace icon.
28-
29-
:param str id_: Id of the Marketplace.
30-
:param str path: Path to the icon file that will be sent to Connect.
31-
"""
32-
icon = self._load_icon(id_, path)
33-
request_path, headers, multipart = self._setup_icon_request(id_, path, icon)
34-
self._post_icon_request(id_, request_path, headers, multipart)
35-
36-
def _load_icon(self, id_, path):
37-
# type: (str, str) -> bytes
38-
try:
39-
with open(path, 'rb') as f:
40-
return f.read()
41-
except IOError as ex:
42-
raise UpdateResourceError(self.UPLOAD_ERR.format(id_, ex))
43-
44-
def _setup_icon_request(self, id_, path, icon):
45-
# type: (str, str, bytes) -> (str, dict, dict)
46-
request_path = self._api.urljoin(id_, 'icon')
47-
headers = self._api.headers
48-
headers['Accept'] = 'application/json'
49-
del headers['Content-Type'] # This must NOT be set for multipart post requests
50-
multipart = {'icon': (path, icon)}
51-
self.logger.info('HTTP Request: {} - {} - {}'.format(request_path, headers, multipart))
52-
return request_path, headers, multipart
53-
54-
def _post_icon_request(self, id_, path, headers, multipart):
55-
# type: (str, str, dict, dict) -> None
56-
try:
57-
content, status = self._api.post(
58-
path=path,
59-
headers=headers,
60-
files=multipart)
61-
except (RequestException, ServerError) as ex:
62-
raise UpdateResourceError(self.UPLOAD_ERR.format(id_, ex))
63-
self._raise_if_invalid_status(200, status, content, UpdateResourceError)
64-
65-
def _raise_if_invalid_status(self, required, obtained, content, ex_class):
66-
# type: (int, int, str, type) -> None
67-
self.logger.info('HTTP Code: {}'.format(obtained))
68-
if obtained != required:
69-
msg = self.RESPONSE_ERR.format(obtained, content)
70-
self.logger.error(msg)
71-
raise ex_class(msg)
72-
73-
def delete(self, id_):
74-
""" Deletes a Marketplace.
75-
76-
:param id_: Id of the Marketplace.
77-
:return:
78-
"""
79-
try:
80-
content, status = self._api.delete(path=id_)
81-
except (RequestException, ServerError) as ex:
82-
raise DeleteResourceError(self.DELETE_ERR.format(id_, ex))
83-
self._raise_if_invalid_status(204, status, content, DeleteResourceError)

tests/test_marketplace.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)