Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions contentstack_management/_constant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import platform
import sys
import sys
from ._messages import REQUEST_HEADERS_INVALID


def _default_user_agent():
Expand Down Expand Up @@ -55,4 +56,4 @@ def _request_headers():


if __name__ == '__main__':
print(_request_headers().__str__())
print(REQUEST_HEADERS_INVALID)
131 changes: 131 additions & 0 deletions contentstack_management/_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""
Centralized error and UI messages for Contentstack Management SDK.

This module contains all user-facing messages used throughout the SDK
to ensure consistency and easy maintenance.
"""

# General messages
REQUEST_HEADERS_INVALID = "Request headers are invalid. Provide valid headers and try again."

# Alias messages
ALIAS_UID_REQUIRED = "Alias UID is required. Provide a valid Alias UID and try again."

# Asset messages
ASSET_UID_REQUIRED = "Asset UID is required. Provide a valid Asset UID and try again."
ASSET_TYPE_REQUIRED = "Asset Type is required. Provide a valid Asset Type and try again."
ASSET_VERSION_NUMBER_REQUIRED = "Version Number is required. Provide a valid Version Number and try again."

# Audit log messages
LOG_ITEM_UID_REQUIRED = "Log Item UID is required. Provide a valid Log Item UID and try again."

# Branch messages
BRANCH_UID_REQUIRED = "Branch UID is required. Provide a valid Branch UID and try again."

# Bulk operation messages
JOB_UID_REQUIRED = "Job UID is required. Provide a valid Job UID and try again."

# Content type messages
CONTENT_TYPE_UID_REQUIRED = "Content Type UID is required. Provide a valid Content Type UID and try again."

# Delivery token messages
DELIVERY_TOKEN_UID_REQUIRED = "Delivery Token UID is required. Provide a valid Delivery Token UID and try again."

# Entry messages
ENTRY_UID_REQUIRED = "Entry UID is required. Provide a valid Entry UID and try again."
ENTRY_VERSION_NUMBER_REQUIRED = "Version Number is required. Provide a valid Version Number and try again."
ENTRY_BODY_REQUIRED = "Body is required. Provide a valid Body value and try again."
ENTRY_FILE_PATH_REQUIRED = "File Path is required. Provide a valid File Path and try again."

# Entry variant messages
ENTRY_VARIANT_CONTENT_TYPE_UID_REQUIRED = "Content Type UID is required. Provide a valid Content Type UID and try again."
ENTRY_VARIANT_ENTRY_UID_REQUIRED = "Entry UID is required. Provide a valid Entry UID and try again."
ENTRY_VARIANT_UID_REQUIRED = "Variant UID is required. Provide a valid Variant UID and try again."

# Environment messages
ENVIRONMENT_UID_REQUIRED = "Environment UID is required. Provide a valid Environment UID and try again."

# Extension messages
EXTENSION_UID_REQUIRED = "Extension UID is required. Provide a valid Extension UID and try again."

# Global field messages
GLOBAL_FIELD_UID_REQUIRED = "Global Field UID is required. Provide a valid Global Field UID and try again."

# Label messages
LABEL_UID_REQUIRED = "Label UID is required. Provide a valid Label UID and try again."

# Locale messages
LOCALE_CODE_REQUIRED = "Locale Code is required. Provide a valid Locale Code and try again."

# Management token messages
MANAGEMENT_TOKEN_UID_REQUIRED = "Management Token UID is required. Provide a valid Management Token UID and try again."

# Metadata messages
METADATA_UID_REQUIRED = "Metadata UID is required. Provide a valid Metadata UID and try again."

# OAuth messages
OAUTH_ACCESS_TOKEN_EXPIRED = "Access token expired. Refreshing the token."
OAUTH_ACCESS_TOKEN_NOT_AVAILABLE = "Access token is not available. Authenticate to continue."
OAUTH_TOKENS_NOT_AVAILABLE = "OAuth tokens are not available. Please authenticate first."
OAUTH_REFRESH_TOKEN_NOT_AVAILABLE = "Refresh token is not available. Please authenticate to get a new token."
OAUTH_NOT_CONFIGURED = "OAuth is not configured. Set up OAuth to continue."
OAUTH_AUTHORIZATION_CODE_NOT_FOUND = "Authorization code was not found in the redirect URL. Provide a valid code and try again."
OAUTH_TOKEN_EXCHANGE_FAILED = "Token exchange failed. Please try authenticating again."
OAUTH_TOKEN_REFRESH_FAILED = "Token refresh failed due to {error}. Review the error and try again."
OAUTH_BASE_URL_NOT_SET = "OAuth Base URL is not set. Provide a valid OAuth Base URL and try again."
OAUTH_AUTHORIZING = "Authorizing using app ID {app_id} and client ID {client_id}."
OAUTH_AUTHORIZATION_URL_GENERATED = "OAuth handler generated the final authorization URL at {final_url}."
OAUTH_AUTHORIZATION_URL_GENERATION_FAILED = "Authorization URL generation failed due to {error}. Review the error and try again."
OAUTH_AUTHORIZATION_CODE_EMPTY = "Authorization code is required. Provide a valid code and try again."
OAUTH_TOKEN_EXCHANGE_ERROR = "Token exchange failed due to {error}. Review the error and try again."
OAUTH_TOKEN_REFRESH_ERROR = "Token refresh failed due to {error}. Review the error and try again."
OAUTH_TOKEN_REFRESH_FAILED_AFTER_401 = "Token refresh failed after a 401 response due to {error}. Review the error and try again."
OAUTH_VISIT_URL_TO_AUTHORIZE = "Visit {auth_url} to authorize."

# Organization messages
ORGANIZATION_UID_REQUIRED = "Organization UID is required. Provide a valid Organization UID and try again."

# Publish queue messages
PUBLISH_QUEUE_UID_REQUIRED = "Publish Queue UID is required. Provide a valid Publish Queue UID and try again."

# Release messages
RELEASE_UID_REQUIRED = "Release UID is required. Provide a valid Release UID and try again."

# Role messages
ROLE_UID_REQUIRED = "Role UID is required. Provide a valid Release UID and try again."

# Stack messages
API_KEY_REQUIRED = "API Key is required. Provide a valid API Key and try again."
USER_ID_REQUIRED = "User ID is required. Provide a valid User ID and try again."
OWNERSHIP_TOKEN_REQUIRED = "Ownership Token is required. Provide a valid Ownership Token and try again."

# Taxonomy messages
TAXONOMY_UID_REQUIRED = "Taxonomy UID is required. Provide a valid Taxonomy UID and try again."

# Terms messages
TERMS_UID_REQUIRED = "Terms UID is required. Provide a valid Terms UID and try again."
TERM_STRING_REQUIRED = "Term String is required. Provide a valid Term String and try again."

# User session messages
EMAIL_ID_REQUIRED = "Email ID is required. Provide a valid Email ID and try again."
PASSWORD_REQUIRED = "Password is required. Provide a valid Password and try again."

# Variant group messages
VARIANT_GROUP_UID_REQUIRED = "Variant Group UID is required. Provide a valid Variant Group UID and try again."

# Variant messages
VARIANT_UIDS_NON_EMPTY_LIST_REQUIRED = "Variant UIDs must be a non-empty list. Provide at least one Variant UID and try again."
VARIANT_UID_REQUIRED = "Variant UID is required. Provide a valid Variant UID and try again."

# Webhook messages
WEBHOOK_UID_REQUIRED = "Webhook UID is required. Provide a valid Webhook UID and try again."
WEBHOOK_FILE_PATH_REQUIRED = "File Path is required. Provide a valid File Path and try again."
WEBHOOK_EXECUTION_UID_REQUIRED = "Execution UID is required. Provide a valid Execution UID and try again."

# Workflow messages
WORKFLOW_UID_REQUIRED = "Workflow UID is required. Provide a valid Workflow UID and try again."
WORKFLOW_CONTENT_TYPE_UID_REQUIRED = "Content Type UID is required. Provide a valid Content Type UID and try again."
WORKFLOW_ENTRY_UID_REQUIRED = "Entry UID is required. Provide a valid Entry UID and try again."
WORKFLOW_RULE_UID_REQUIRED = "Rule UID is required. Provide a valid Rule UID and try again."


3 changes: 2 additions & 1 deletion contentstack_management/aliases/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
from ..common import Parameter
from .._messages import ALIAS_UID_REQUIRED
_path = 'stacks/branch_aliases'


Expand Down Expand Up @@ -47,7 +48,7 @@ def fetch(self):
--------------------------------
"""
if self.alias_uid is None or '':
raise Exception('alias_uid is required')
raise Exception(ALIAS_UID_REQUIRED)
url = f"{_path}/{self.alias_uid}"
return self.client.get(url, headers=self.client.headers, params=self.params)

Expand Down
21 changes: 11 additions & 10 deletions contentstack_management/assets/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..common import Parameter
import mimetypes
import os
from .._messages import ASSET_UID_REQUIRED, ASSET_TYPE_REQUIRED, ASSET_VERSION_NUMBER_REQUIRED

class Assets(Parameter):
"""
Expand Down Expand Up @@ -62,7 +63,7 @@ def fetch(self):
"""

if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}"
return self.client.get(url, headers = self.client.headers, params = self.params)

Expand Down Expand Up @@ -284,7 +285,7 @@ def version(self):
"""

if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}/versions"
return self.client.get(url, headers = self.client.headers, params = self.params)

Expand All @@ -305,9 +306,9 @@ def version_delete(self, version_number):
"""

if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
if version_number is None:
raise Exception('Version Number is required')
raise Exception(ASSET_VERSION_NUMBER_REQUIRED)
url = f"assets/{self.asset_uid}/versions/{version_number}/name"
return self.client.delete(url, headers = self.client.headers, params = self.params)

Expand All @@ -326,7 +327,7 @@ def references(self):
"""

if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}/references"
return self.client.get(url, headers = self.client.headers, params = self.params)

Expand All @@ -346,7 +347,7 @@ def specific_asset_type(self, asset_type):
"""

if asset_type is None or '':
raise Exception('asset_type is required')
raise Exception(ASSET_TYPE_REQUIRED)
url = f"assets/{asset_type}"
return self.client.get(url, headers = self.client.headers, params = self.params)

Expand Down Expand Up @@ -376,7 +377,7 @@ def update_asset_revision(self, data):

data = json.dumps(data)
if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}"
return self.client.put(url, headers = self.client.headers, params = self.params, data = data)

Expand Down Expand Up @@ -404,7 +405,7 @@ def update(self, data):

data = json.dumps(data)
if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}"
Parameter.add_header(self, "Content-Type", "multipart/form-data")
return self.client.put(url, headers = self.client.headers, params = self.params, data = data)
Expand Down Expand Up @@ -439,7 +440,7 @@ def publish(self, data):

data = json.dumps(data)
if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}/publish"
return self.client.post(url, headers = self.client.headers, data = data)

Expand Down Expand Up @@ -474,7 +475,7 @@ def unpublish(self, data):

data = json.dumps(data)
if self.asset_uid is None or '':
raise Exception('asset_uid is required')
raise Exception(ASSET_UID_REQUIRED)
url = f"assets/{self.asset_uid}/unpublish"
return self.client.post(url, headers = self.client.headers, data = data)

Expand Down
3 changes: 2 additions & 1 deletion contentstack_management/auditlogs/auditlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ..common import Parameter
from .._errors import ArgumentException
from .._messages import LOG_ITEM_UID_REQUIRED

class Auditlog(Parameter):
"""
Expand Down Expand Up @@ -58,6 +59,6 @@ def fetch(self):

def validate_uid(self):
if self.log_item_uid is None or '':
raise ArgumentException('Log item Uid is required')
raise ArgumentException(LOG_ITEM_UID_REQUIRED)


5 changes: 3 additions & 2 deletions contentstack_management/branches/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json

from contentstack_management.common import Parameter
from contentstack_management._messages import BRANCH_UID_REQUIRED

_path = 'stacks/branches'

Expand Down Expand Up @@ -55,7 +56,7 @@ def fetch(self):
--------------------------------
"""
if self.branch_uid is None or '':
raise Exception('branch_uid is required field')
raise Exception(BRANCH_UID_REQUIRED)
url = f"{_path}/{self.branch_uid}"
return self.client.get(url, headers=self.client.headers, params=self.params)

Expand Down Expand Up @@ -101,6 +102,6 @@ def delete(self):
--------------------------------
"""
if self.branch_uid is None or '':
raise Exception('branch_uid is required field')
raise Exception(BRANCH_UID_REQUIRED)
url = f"{_path}/{self.branch_uid}"
return self.client.delete(url, headers=self.client.headers, params=self.params)
3 changes: 2 additions & 1 deletion contentstack_management/bulk_operations/bulk_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..common import Parameter
from urllib.parse import quote
from .._errors import ArgumentException
from .._messages import JOB_UID_REQUIRED

class BulkOperation(Parameter):
"""
Expand Down Expand Up @@ -313,7 +314,7 @@ def job_status(self, job_uid: str, headers: dict = None):
-------------------------------
"""
if job_uid is None:
raise ArgumentException("job_uid", "job_uid cannot be None")
raise ArgumentException(JOB_UID_REQUIRED)
if headers is not None:
self.client.headers.update(headers)
url = f"{self.path}/jobs/{quote(job_uid)}"
Expand Down
5 changes: 3 additions & 2 deletions contentstack_management/content_types/content_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from contentstack_management.common import Parameter
from ..entries import entry
from .._messages import CONTENT_TYPE_UID_REQUIRED

_path = 'content_types'

Expand Down Expand Up @@ -163,7 +164,7 @@ def update(self, data):
"""
data = json.dumps(data)
if self.content_type_uid is None or '':
raise Exception('content_type_uid is required')
raise Exception(CONTENT_TYPE_UID_REQUIRED)
url = f"{_path}/{self.content_type_uid}"
return self.client.put(url, headers=self.client.headers, params=self.params, data=data)

Expand Down Expand Up @@ -347,5 +348,5 @@ def imports(self, file_path):

def entry(self, entry_uid: str =None):
if self.content_type_uid is None:
raise Exception('Content type uid is required')
raise Exception(CONTENT_TYPE_UID_REQUIRED)
return entry.Entry(self.client, self.content_type_uid, entry_uid)
3 changes: 2 additions & 1 deletion contentstack_management/contentstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def oauth(self, app_id: str, client_id: str, redirect_uri: str,
... redirect_uri='http://localhost:3000/callback'
... )
>>> auth_url = oauth_handler.authorize()
>>> print(f"Visit this URL to authorize: {auth_url}")
>>> from contentstack_management._messages import OAUTH_VISIT_URL_TO_AUTHORIZE
>>> print(OAUTH_VISIT_URL_TO_AUTHORIZE.format(auth_url=auth_url))
"""
return OAuthHandler(
app_id=app_id,
Expand Down
3 changes: 2 additions & 1 deletion contentstack_management/delivery_token/delivery_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
from ..common import Parameter
from .._errors import ArgumentException
from .._messages import DELIVERY_TOKEN_UID_REQUIRED

class DeliveryToken(Parameter):
"""
Expand Down Expand Up @@ -191,4 +192,4 @@ def delete(self):

def validate_uid(self):
if self.delivery_token_uid is None or '':
raise ArgumentException("Delivery Token Uid is required")
raise ArgumentException(DELIVERY_TOKEN_UID_REQUIRED)
Loading