- Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -158,9 +158,7 @@ def get(self, url, return_response_object=False, **kwargs): | ||
| r = self.requests_session.get(self.server_url + url, headers=self.get_headers(), **kwargs) | ||
| try: | ||
| r.raise_for_status() | ||
| if return_response_object: | ||
| return r | ||
| return r.json() | ||
| return r if return_response_object else r.json() | ||
| except requests.exceptions.HTTPError as e: | ||
| logging.error(r.text) | ||
| raise e | ||
| @@ -169,9 +167,7 @@ def put(self, url, data, return_response_object=False, **kwargs): | ||
| r = self.requests_session.put(self.server_url + url, json=data, headers=self.get_headers(), **kwargs) | ||
| try: | ||
| r.raise_for_status() | ||
| if return_response_object: | ||
| return r | ||
| return r.json() | ||
| return r if return_response_object else r.json() | ||
Comment on lines
-172
to
+170
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| except requests.exceptions.HTTPError as e: | ||
| logging.error(r.text) | ||
| raise e | ||
| @@ -180,9 +176,7 @@ def post(self, url, data, return_response_object=False, **kwargs): | ||
| r = self.requests_session.post(self.server_url + url, json=data, headers=self.get_headers(), **kwargs) | ||
| try: | ||
| r.raise_for_status() | ||
| if return_response_object: | ||
| return r | ||
| return r.json() | ||
| return r if return_response_object else r.json() | ||
Comment on lines
-183
to
+179
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| except requests.exceptions.HTTPError as e: | ||
| logging.error(r.text) | ||
| raise e | ||
| @@ -247,12 +241,10 @@ def iterate_resources(self, params: Optional[dict] = None): | ||
| params = params or {} | ||
| url_params = urllib.parse.urlencode(params) | ||
| if url_params: | ||
| url_params = "?" + url_params | ||
| response = self.get("/resources.json" + url_params) | ||
| url_params = f"?{url_params}" | ||
| response = self.get(f"/resources.json{url_params}") | ||
| assert "body" in response.keys(), f"Key 'body' not found in response keys: {response.keys()}" | ||
| resources = response["body"] | ||
| for resource in resources: | ||
| yield resource | ||
| yield from response["body"] | ||
Comment on lines
-250
to
+247
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| def list_resources(self, folder_id: Optional[PassboltFolderIdType] = None): | ||
| params = { | ||
| @@ -261,8 +253,8 @@ def list_resources(self, folder_id: Optional[PassboltFolderIdType] = None): | ||
| } | ||
| url_params = urllib.parse.urlencode(params) | ||
| if url_params: | ||
| url_params = "?" + url_params | ||
| response = self.get("/folders.json" + url_params) | ||
| url_params = f"?{url_params}" | ||
| response = self.get(f"/folders.json{url_params}") | ||
Comment on lines
-264
to
+257
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| assert "body" in response.keys(), f"Key 'body' not found in response keys: {response.keys()}" | ||
| response = response["body"][0] | ||
| assert "children_resources" in response.keys(), ( | ||
| @@ -292,7 +284,7 @@ def list_users( | ||
| else: | ||
| params = {"filter[has-access]": resource_or_folder_id, "contain[user]": 1} | ||
| params["contain[permission]"] = True | ||
| response = self.get(f"/users.json", params=params) | ||
| response = self.get("/users.json", params=params) | ||
Comment on lines
-295
to
+287
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| assert "body" in response.keys(), f"Key 'body' not found in response keys: {response.keys()}" | ||
| response = response["body"] | ||
| users = constructor( | ||
| @@ -465,8 +457,11 @@ def update_resource( | ||
| payload["secrets"] = self._encrypt_secrets(secret_text=secret_text, recipients=recipients) | ||
| if payload: | ||
| r = self.put(f"/resources/{resource_id}.json", payload, return_response_object=True) | ||
| return r | ||
| return self.put( | ||
| f"/resources/{resource_id}.json", | ||
| payload, | ||
| return_response_object=True, | ||
| ) | ||
Comment on lines
-468
to
+464
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| def describe_group(self, group_id: PassboltGroupIdType): | ||
| response = self.get(f"/groups/{group_id}.json", params={"contain[groups_users]": 1}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,7 +4,7 @@ | ||
| def get_my_passwords(passbolt_obj): | ||
| result = list() | ||
| result = [] | ||
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| for i in passbolt_obj.get(url="/resources.json?api-version=v2")["body"]: | ||
| result.append({ | ||
| "id": i["id"], | ||
| @@ -14,8 +14,7 @@ def get_my_passwords(passbolt_obj): | ||
| }) | ||
| print(i) | ||
| for i in result: | ||
| resource = passbolt_obj.get( | ||
| "/secrets/resource/{}.json?api-version=v2".format(i["id"])) | ||
| resource = passbolt_obj.get(f'/secrets/resource/{i["id"]}.json?api-version=v2') | ||
| i["password"] = passbolt_obj.decrypt(resource["body"]["data"]) | ||
| print(result) | ||
| @@ -24,7 +23,7 @@ def get_passwords_basic(): | ||
| # A simple example to show how to retrieve passwords of a user. | ||
| # Note the config file is placed in the project directory. | ||
| passbolt_obj = passboltapi.PassboltAPI(config_path="config.ini") | ||
| result = list() | ||
| result = [] | ||
Comment on lines
-27
to
+26
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
| ||
| for i in passbolt_obj.get(url="/resources.json?api-version=v2")["body"]: | ||
| result.append({ | ||
| "id": i["id"], | ||
| @@ -34,8 +33,7 @@ def get_passwords_basic(): | ||
| }) | ||
| print(i) | ||
| for i in result: | ||
| resource = passbolt_obj.get( | ||
| "/secrets/resource/{}.json?api-version=v2".format(i["id"])) | ||
| resource = passbolt_obj.get(f'/secrets/resource/{i["id"]}.json?api-version=v2') | ||
| i["password"] = passbolt_obj.decrypt(resource["body"]["data"]) | ||
| print(result) | ||
| passbolt_obj.close_session() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
APIClient.getrefactored with the following changes:reintroduce-else)assign-if-exp)