-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/cs 40545 metadata class implemetation (#15)
* Metadata class implementation * Deleted sast-scan.yml file * Fixed PR comments * Code optimisation and handling custom error exception * Removed uids * Feat/cs 40549 roles class implementation (#16) * Created roles class with unit testcases, mock test cases and api test cases * Updated coverage report github workflow file * Added coverage install command * Added pytest install command * Updated stack class unit test file * Added html coverage * Added coverage reports and visualizations * Removed visualisation * Generating coverage report in svg format * Added coverage-badge install command * Fixed PR comments and code optimisation * Added coverage reports graphical visualisation in github page * Created readme file * changed variable name * Updated readme file * Update README.md * Added auditlog class and license file (#17) * Added auditlog class and license file * Added test case for invalid inputs * commented the idiom It Allows You to Execute Code When the File Runs as a Script, but Not When It’s Imported as a Module --------- Co-authored-by: Shailesh Mishra <[email protected]> --------- Co-authored-by: Shailesh Mishra <[email protected]>
- Loading branch information
1 parent
dae66d7
commit 92e2a31
Showing
38 changed files
with
2,884 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
name: Pytest Workflow | ||
name: Coverage Report | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
on: [push] # You can adjust the trigger events as needed | ||
|
||
jobs: | ||
coverage-report: | ||
strategy: | ||
matrix: | ||
python-version: | ||
- 3.9 | ||
coverage: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install build dependencies | ||
run: pip install --upgrade setuptools | ||
- name: Install dot env | ||
run: pip install python-dotenv | ||
- name: Install requests | ||
run: pip install requests | ||
- name: Change to test directory | ||
run: cd tests/unit | ||
- uses: lpenz/ghaction-pytest-cov@v1 | ||
- uses: AndreMiras/coveralls-python-action@v20201129 | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
parallel: true | ||
flag-name: python-${{ matrix.python-version }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
|
||
coverage-finish: | ||
needs: coverage-report | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: AndreMiras/coveralls-python-action@v20201129 | ||
python-version: 3.11 # Choose the appropriate Python version | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt # If you have a requirements file | ||
pip install coverage | ||
pip install pytest | ||
pip install coverage-badge | ||
- name: Run tests and coverage | ||
run: | | ||
coverage run -m pytest tests/unit/ | ||
coverage report --include="tests/unit/*" -m > coverage_report.txt | ||
coverage xml --include="tests/unit/*" -o coverage.xml | ||
coverage html --include="tests/unit/*" | ||
coverage-badge -o coverage.svg | ||
- name: Upload coverage artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
parallel-finished: true | ||
name: coverage-report | ||
path: | | ||
coverage_report.txt | ||
coverage.xml | ||
htmlcov | ||
coverage.svg | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2012 - 2023 Contentstack. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,106 @@ | ||
# contentstack-management-python | ||
[](https://www.contentstack.com/) | ||
|
||
## Contentstack Management Python SDK | ||
|
||
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). | ||
|
||
This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication). | ||
|
||
Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties. | ||
|
||
### Prerequisite | ||
|
||
You will need python 3 installed on your machine. You can install it | ||
from [here](https://www.python.org/ftp/python/3.7.4/python-3.7.4-macosx10.9.pkg). | ||
|
||
### Installation | ||
#### Install contentstack pip | ||
|
||
```python | ||
pip install contentstack_management | ||
``` | ||
To import the SDK, use the following command: | ||
```python | ||
from contentstack_management import contentstack | ||
|
||
client = contentstack.ContentstackClient() | ||
``` | ||
|
||
### Authentication | ||
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token). | ||
### Authtoken | ||
|
||
An **Authtoken** is a read-write token used to make authorized CMA requests, and it is a **user-specific** token. | ||
```python | ||
client = contentstack.ContentstackClient(authtoken= 'authtoken') | ||
``` | ||
### Login | ||
To Login to Contentstack by using credentials, you can use the following lines of code: | ||
```python | ||
client.login(email="email", password="password") | ||
|
||
``` | ||
|
||
### Management Token | ||
**Management Tokens** are **stack-level** tokens, with no users attached to them. | ||
|
||
```python | ||
result = client.stack(api_key = 'api_key', management_token= 'management_token' ).content_type('content_type_uid') | ||
.fetch().json() | ||
print(result) | ||
``` | ||
### Contentstack Management Python SDK: 5-minute Quickstart | ||
#### Initializing Your SDK: | ||
To use the Python CMA SDK, you need to first initialize it. To do this, use the following code: | ||
|
||
```python | ||
from contentstack_management import contentstack | ||
|
||
client = contentstack.ContentstackClient(authtoken= 'authtoken') | ||
``` | ||
#### Fetch Stack Detail | ||
Use the following lines of code to fetch your stack detail using this SDK: | ||
```python | ||
result = client.stack(api_key= 'api_key').fetch().json() | ||
print(result) | ||
``` | ||
|
||
#### Create Entry | ||
To create an entry in a specific content type of a stack, use the following lines of code: | ||
|
||
```python | ||
entry = { | ||
title: 'Sample Entry', | ||
url: '/sampleEntry' | ||
} | ||
|
||
result = client.stack(api_key= 'api_key').content_types('content_type_uid').entry().create(entry) | ||
print(result.json()) | ||
``` | ||
|
||
#### Create Asset | ||
The following lines of code can be used to upload assets to your stack: | ||
|
||
```python | ||
asset = { | ||
upload: 'path/to/file', | ||
title: 'Asset Title' | ||
} | ||
asset = client().stack(api_key='api_key').assets() | ||
result = asset.upload(asset) | ||
``` | ||
|
||
### Helpful Links | ||
|
||
- [Contentstack Website](https://www.contentstack.com/) | ||
- [Official Documentation](https://contentstack.com/docs) | ||
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api) | ||
|
||
### The MIT License (MIT) | ||
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Error(Exception): | ||
class ArgumentException(Exception): | ||
|
||
pass | ||
def __init__(self, f, *args): | ||
super().__init__(args) | ||
self.f = f | ||
|
||
def __str__(self): | ||
return self.f | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""This class takes a base URL as an argument when it's initialized, | ||
which is the endpoint for the RESTFUL API that we'll be interacting with. | ||
The create(), read(), update(), and delete() methods each correspond to | ||
the CRUD operations that can be performed on the API """ | ||
|
||
import json | ||
from ..common import Parameter | ||
from urllib.parse import quote | ||
from .._errors import ArgumentException | ||
|
||
class Auditlog(Parameter): | ||
""" | ||
This class takes a base URL as an argument when it's initialized, | ||
which is the endpoint for the RESTFUL API that | ||
we'll be interacting with. The create(), read(), update(), and delete() | ||
methods each correspond to the CRUD | ||
operations that can be performed on the API """ | ||
|
||
def __init__(self, client, log_item_uid: str): | ||
self.client = client | ||
self.log_item_uid = log_item_uid | ||
super().__init__(self.client) | ||
|
||
self.path = "audit-logs" | ||
|
||
def find(self): | ||
""" | ||
The "Get audit log" request is used to retrieve the audit log of a stack. | ||
:return: Json, with auditlog details. | ||
------------------------------- | ||
[Example:] | ||
>>> from contentstack_management import contentstack | ||
>>> client = contentstack.client(authtoken='your_authtoken') | ||
>>> result = client.stack("api_key").auditlog().find().json() | ||
------------------------------- | ||
""" | ||
return self.client.get(self.path, headers = self.client.headers) | ||
|
||
|
||
|
||
def fetch(self): | ||
""" | ||
The "Get audit log item" request is used to retrieve a specific item from the audit log of a stack. | ||
:return: Json, with auditlog details. | ||
------------------------------- | ||
[Example:] | ||
>>> from contentstack_management import contentstack | ||
>>> client = contentstack.client(authtoken='your_authtoken') | ||
>>> result = client.stack('api_key').auditlog('log_item_uid').fetch().json() | ||
------------------------------- | ||
""" | ||
self.validate_uid() | ||
url = f"{self.path}/{self.log_item_uid}" | ||
return self.client.get(url, headers = self.client.headers) | ||
|
||
def validate_uid(self): | ||
if self.log_item_uid is None or '': | ||
raise ArgumentException('Log item Uid is required') | ||
|
||
|
Oops, something went wrong.