Skip to content

Commit be3cb1b

Browse files
Merge pull request #40 from contentstack/feat/CS-38762-ci/cd-azure-eu-live_preview_include_metadata
Feat/cs 38762 ci/cd azure eu live preview include metadata
2 parents b2b7eed + 22ff561 commit be3cb1b

File tree

12 files changed

+154
-186
lines changed

12 files changed

+154
-186
lines changed

.github/workflows/publish.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [ published ]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Set up Python
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: '3.x'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
- name: Build package
34+
run: python -m build
35+
- name: Publish package
36+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37+
with:
38+
user: __token__
39+
password: ${{ secrets.PYPI_PASSWORD }}

.talismanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ fileignoreconfig:
44

55
- filename: README.md
66
checksum: d9d20b2badbf1aa62649bb174db47a9e491d8687e33ac69fee62568efa23fc56
7+
fileignoreconfig:
8+
- filename: .github/workflows/publish.yml
9+
checksum: 4f2e1a9283c5aadaaec639f5efa0111dc35f385ead74e9a6a585f839d27aa0c8

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## _v1.8.0_
44

5-
### **Date: 23-MAY-2023**
5+
### **Date: 26-MAY-2023**
66

77
- AZURE_EU, Region support added
88
- Include Metadata support added to asset, entry and query

SECURITY.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Security
2+
3+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4+
5+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.**
10+
11+
Send email to [security@contentstack.com](mailto:security@contentstack.com).
12+
13+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14+
15+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16+
17+
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18+
- Full paths of source file(s) related to the manifestation of the issue
19+
- The location of the affected source code (tag/branch/commit or direct URL)
20+
- Any special configuration required to reproduce the issue
21+
- Step-by-step instructions to reproduce the issue
22+
- Proof-of-concept or exploit code (if possible)
23+
- Impact of the issue, including how an attacker might exploit the issue
24+
25+
This information will help us triage your report more quickly.
26+
27+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)

changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*v1.8.0*
66
============
77

8-
**Date: 23-MAY-2023**
8+
**Date: 26-MAY-2023**
99

1010
- AZURE_EU, Region support added
1111
- Include Metadata support added to asset, entry and query

contentstack/entry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
The Get a single entry request fetches a particular entry of a content type.
33
API Reference: https://www.contentstack.com/docs/developers/apis/content-delivery-api/#single-entry
44
"""
5-
5+
#min-similarity-lines=10
66
import logging
77
from urllib import parse
88

contentstack/https_connection.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,11 @@ def __get_os_platform():
2727
def user_agents():
2828
header = {'sdk': dict(name=contentstack.__package__,
2929
version=contentstack.__version__
30-
), 'os': __get_os_platform, 'Content-Type': 'application/json'}
30+
), 'os': __get_os_platform(), 'Content-Type': 'application/json'}
3131
package = f"{contentstack.__title__}/{contentstack.__version__}"
3232
return {'User-Agent': str(header), "X-User-Agent": package}
3333

3434

35-
def get_api_data(response):
36-
try:
37-
response.raise_for_status()
38-
except requests.exceptions.HTTPError as error:
39-
print(f"Error: {error}")
40-
return None
41-
else:
42-
return response.json()
43-
44-
4535
class HTTPSConnection: # R0903: Too few public methods
4636
def __init__(self, endpoint, headers, timeout, retry_strategy, live_preview):
4737
if None not in (endpoint, headers):
@@ -53,22 +43,6 @@ def __init__(self, endpoint, headers, timeout, retry_strategy, live_preview):
5343
self.retry_strategy = retry_strategy
5444
self.live_preview = live_preview
5545

56-
def impl_live_preview(self):
57-
if self.live_preview['enable']:
58-
host = self.live_preview['host']
59-
authorization = self.live_preview['authorization']
60-
ct = self.live_preview['content_type_uid']
61-
entry_uid = self.live_preview['entry_uid']
62-
url = f'https://{host}/v3/content_types/{ct}/entries'
63-
if entry_uid is not None:
64-
url = f'{url}/{entry_uid}'
65-
self.headers['authorization'] = authorization
66-
lp_resp = get_request(self.session, url, headers=self.headers, timeout=self.timeout)
67-
if lp_resp is not None and not 'error_code' in lp_resp:
68-
return lp_resp
69-
return None
70-
return None
71-
7246
def get(self, url):
7347
self.headers.update(user_agents())
7448
adapter = HTTPAdapter(max_retries=self.retry_strategy)

contentstack/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Contentstack provides certain queries that you can use to fetch filtered results
33
"""
4-
4+
#min-similarity-lines=10
55
import enum
66
import json
77
import logging

tests/test_live_preview.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import config
44
import contentstack
5+
from contentstack.deep_merge_lp import DeepMergeMixin
56

67
management_token = 'cs8743874323343u9'
78
entry_uid = 'blt8743874323343u9'
@@ -131,5 +132,84 @@ def test_10_live_preview_check_hash_value(self):
131132
self.assertEqual(ENVIRONMENT, self.stack.headers['environment'])
132133

133134

135+
lp_response = [
136+
{
137+
"uid": "76743678743",
138+
"comment": "this belongs to live preview object",
139+
"_version": 2,
140+
"locale": "en-us",
141+
"ACL": {},
142+
"author": [
143+
{
144+
"uid": "77f3f0ea3630e06",
145+
"_content_type_uid": "author"
146+
}
147+
]
148+
},
149+
{
150+
"uid": "7634767463",
151+
"_version": 2,
152+
"locale": "en-us",
153+
"comment": "this belongs to live preview object",
154+
"ACL": {},
155+
"author": [
156+
{
157+
"uid": "bltb77f3f0ea3630e06",
158+
"_content_type_uid": "author"
159+
}
160+
]
161+
}
162+
]
163+
164+
entry_response = [
165+
{
166+
"uid": "76743678743",
167+
"_version": 3,
168+
"locale": "en-uk",
169+
"title": "Updated Title",
170+
"comment": "this belongs to entry object",
171+
},
172+
{
173+
"uid": "47634767463",
174+
"_version": 3,
175+
"locale": "en-uk",
176+
"title": "Updated Title",
177+
"comment": "this belongs to entry object",
178+
},
179+
{
180+
"uid": "34767463",
181+
"_version": 3,
182+
"locale": "en-us",
183+
"comment": "this belongs to entry object",
184+
"title": "You have received a new merged entry response"
185+
}
186+
]
187+
188+
189+
class TestLivePreviewObject(unittest.TestCase):
190+
191+
def setUp(self):
192+
self.stack = contentstack.Stack(
193+
API_KEY, DELIVERY_TOKEN,
194+
ENVIRONMENT, host=HOST)
195+
196+
def test_setup_live_preview(self):
197+
self.stack = contentstack.Stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, live_preview={
198+
'enable': False,
199+
'host': 'api.contentstack.io',
200+
'management_token': 'string987654321'
201+
})
202+
self.stack.content_type('product').entry(entry_uid)
203+
self.assertEqual(3, len(self.stack.get_live_preview))
204+
self.assertFalse(self.stack.get_live_preview['enable'])
205+
self.assertTrue(self.stack.get_live_preview['management_token'])
206+
207+
def test_deep_merge_object(self):
208+
merged_response = DeepMergeMixin(entry_response, lp_response)
209+
self.assertTrue(isinstance(merged_response.entry_response, list))
210+
self.assertEqual(3, len(merged_response.entry_response))
211+
print(merged_response.entry_response)
212+
213+
134214
if __name__ == '__main__':
135215
unittest.main()

0 commit comments

Comments
 (0)