-
Notifications
You must be signed in to change notification settings - Fork 35
feat: new arg to publish command #1914
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
Changes from all commits
2c6570f
6a4ed97
f7e9263
4f352b6
5a929fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ def encode_multipart_formdata( | |
|
|
||
|
|
||
| def upload_package( | ||
| base_url: str, | ||
| app_id: int, | ||
| package_path: str, | ||
| splunk_versions: str, | ||
|
|
@@ -70,7 +71,7 @@ def upload_package( | |
| username: str, | ||
| password: str, | ||
| ) -> str: | ||
| upload_url = f"https://splunkbase.splunk.com/api/v1/app/{app_id}/new_release/" | ||
| upload_url = f"{base_url}/app/{app_id}/new_release/" | ||
|
|
||
| fields = { | ||
| "filename": os.path.basename(package_path), | ||
|
|
@@ -109,9 +110,9 @@ def upload_package( | |
|
|
||
|
|
||
| def check_package_validation( | ||
| package_upload_id: str, username: str, password: str | ||
| base_url: str, package_upload_id: str, username: str, password: str | ||
| ) -> None: | ||
| url = f"https://splunkbase.splunk.com/api/v1/package/{package_upload_id}/" | ||
| url = f"{base_url}/package/{package_upload_id}/" | ||
| auth_header = base64.b64encode(f"{username}:{password}".encode()).decode("utf-8") | ||
| context = ssl.create_default_context(cafile=certifi.where()) | ||
|
|
||
|
|
@@ -121,14 +122,20 @@ def check_package_validation( | |
| try: | ||
| with urllib.request.urlopen(request, context=context) as response: | ||
| response_data = json.loads(response.read().decode("utf-8")) | ||
| logger.info("Validation status: {}".format(response_data.get("message"))) | ||
| if response_data.get("result") == "pass": | ||
| logger.info( | ||
| "Validation status: {}".format(response_data.get("message")) | ||
| ) | ||
| else: | ||
| raise Exception(response_data.get("message")) | ||
| except urllib.error.HTTPError as e: | ||
|
Contributor
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. Raising a bare |
||
| error_msg = e.read().decode() | ||
| logger.error(f"Failed to retrieve package validation status. {error_msg}") | ||
| raise | ||
|
|
||
|
|
||
| def publish_package( | ||
| use_stage: bool, | ||
| app_id: int, | ||
| package_path: str, | ||
| splunk_versions: str, | ||
|
|
@@ -137,7 +144,12 @@ def publish_package( | |
| username: str, | ||
| password: str, | ||
| ) -> None: | ||
| if use_stage: | ||
|
Contributor
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. The staging URL |
||
| API_BASEURL = "https://classic.stage.splunkbase.splunk.com/api/v1" | ||
|
Contributor
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.
|
||
| else: | ||
| API_BASEURL = "https://splunkbase.splunk.com/api/v1" | ||
| package_upload_id = upload_package( | ||
| API_BASEURL, | ||
| app_id, | ||
| package_path, | ||
| splunk_versions, | ||
|
|
@@ -147,4 +159,4 @@ def publish_package( | |
| password, | ||
| ) | ||
| if package_upload_id: | ||
| check_package_validation(package_upload_id, username, password) | ||
| check_package_validation(API_BASEURL, package_upload_id, username, password) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,6 +260,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int: | |
| publish_parser = subparsers.add_parser( | ||
| "publish", description="Publish package to the Splunkbase" | ||
| ) | ||
| publish_parser.add_argument( | ||
| "--stage", | ||
| dest="stage", | ||
| help="Whether to release the app on staging or production splunkbase.", | ||
| action="store_true", | ||
| ) | ||
|
Contributor
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. Help text says "Whether to release the app on staging or production splunkbase" but this is a boolean flag (present = staging, absent = production). Clearer wording: |
||
| publish_parser.add_argument( | ||
| "--app-id", | ||
| type=int, | ||
|
|
@@ -334,6 +340,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int: | |
| ) | ||
| if args.command == "publish": | ||
| publish.publish_package( | ||
| use_stage=args.stage, | ||
| app_id=args.app_id, | ||
| package_path=args.package_path, | ||
| splunk_versions=args.splunk_versions, | ||
|
|
||
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.
Are we planning to expose this for all UCC users, or is this for a specific use case?