Skip to content
Snippets Groups Projects
Commit dd3b0529 authored by Recolic K's avatar Recolic K
Browse files

add jobtype upload feature

parent 7a3c078f
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,13 @@ function curl_wrapped () {
# Getting http status is a trick...
exec 3>&1
HTTP_STATUS=$(curl -w "%{http_code}" -o >(cat >&3) "${curl_options[@]}" "$@") || ! echo2 "Error $? while executing 'curl ${curl_options[@]} $@', refer to https://man7.org/linux/man-pages/man1/curl.1.html (EXIT CODES) for more info" || return $?
for retry_count in {0..5}; do
HTTP_STATUS=$(curl -w "%{http_code}" -o >(cat >&3) "${curl_options[@]}" "$@") && break
! echo2 "Error $? while executing 'curl ${curl_options[@]} $@', refer to https://man7.org/linux/man-pages/man1/curl.1.html (EXIT CODES) for more info. Retry $retry_count in 5..."
done || exit $?
# There is some expected 40x error in some API. Caller may set HTTP_IGNORED_ERROR_STATUS_LIST=405,413 to ignore some of them.
[[ "$HTTP_IGNORED_ERROR_STATUS_LIST" == *"$HTTP_STATUS"* ]] && return 0
[[ "$HTTP_STATUS" == 40* ]] || [[ "$HTTP_STATUS" == 50* ]] && echo2 "HTTP Error $HTTP_STATUS while sending HTTP request 'curl ${curl_options[@]} $@'. Double-confirm that this API is working with your cookie or token! " && return 2
return 0
}
......@@ -258,6 +264,7 @@ function cis_wait_for_upload () {
function subcmd_push () {
# No output. TODO: DO NOT release in push. Delete it and modify documents.
local_wf_dir="$1"
workflow_name="$2"
[[ "$workflow_name" = "" ]] && workflow_name="$cis_default_workflow_name"
......@@ -271,6 +278,7 @@ function subcmd_push () {
return $?
}
function subcmd_setdef () {
# No output.
workflow_name="$1"
[[ "$workflow_name" = "" ]] && workflow_name="$cis_default_workflow_name"
release_ver="$2"
......@@ -281,6 +289,7 @@ function subcmd_setdef () {
return $?
}
function subcmd_release () {
# No output.
workflow_name="$1"
[[ "$workflow_name" = "" ]] && workflow_name="$cis_default_workflow_name"
release_ver="$2"
......@@ -291,6 +300,7 @@ function subcmd_release () {
return $?
}
function subcmd_cloudrun () {
# Output stdout: job_id on success
workflow_name="$1"
[[ "$workflow_name" = "" ]] && workflow_name="$cis_default_workflow_name"
release_ver="$2"
......@@ -301,6 +311,7 @@ function subcmd_cloudrun () {
return $?
}
function subcmd_jobstatus () {
# Output stdout: job status summary in plain text or markdown.
jobid="$1"
[[ "$jobid" = "" ]] && echo2 "Error: subcommand 'jobstatus' requires argument 'jobid'" && exit 1
......@@ -308,6 +319,7 @@ function subcmd_jobstatus () {
return $?
}
function subcmd_listver () {
# Output stdout: a list of version and state, seperated by |
workflow_name="$1"
[[ "$workflow_name" = "" ]] && workflow_name="$cis_default_workflow_name"
......@@ -316,9 +328,21 @@ function subcmd_listver () {
echo "$resp" | json2table Version,State -p
return $?
}
function subcmd_xmlupload () {
# Output stdout: Text message returned from CIS API.
jobtype_filename="$1"
# 406 means "Identical Job type definition found. Upload completed with no-op."
HTTP_IGNORED_ERROR_STATUS_LIST=406 curl_wrapped "https://beta-cps.trafficmanager.net/cis.client.svc/Public/JobTypeDefinition/upload" -F "note=" -F "uploadfiles[]=@$jobtype_filename"
return $?
}
function subcmd_xmldownload () {
echo2 "This feature subcmd_xmldownload is not implemented yet. Because the author doesn't need it. "
return 1
}
# Initialization
antidote_version="1.1.07"
antidote_version="1.1.08"
subcmd="$1"
shift
......@@ -348,11 +372,11 @@ case "$subcmd" in
listver )
subcmd_listver "${filteredArgs[@]}" ; exit $?
;;
all)
subcmd_push "${filteredArgs[@]}" &&
subcmd_setdef "${filteredArgs[@]:1}" &&
subcmd_cloudrun "${filteredArgs[@]:1}"
exit $?
jobtype-upload )
subcmd_xmlupload "${filteredArgs[@]}" ; exit $?
;;
jobtype-download )
subcmd_xmldownload "${filteredArgs[@]}" ; exit $?
;;
*)
echo2 "
......@@ -363,11 +387,14 @@ Antidote-CIS version $antidote_version, maintained by Recolic Keghart <root@reco
Usage:
$0 push path/to/your/workflow/dir [BootstrapCAWorkflow] [v4.1.1]
$0 push //existing-samba-share/your/workflow/dir [BootstrapCAWorkflow] [v4.1.1]
$0 push cis:// [BootstrapCAWorkflow] [v4.1.1]
$0 release [BootstrapCAWorkflow] [v4.1.1]
$0 setdef [BootstrapCAWorkflow] [v4.1.1]
$0 cloudrun [BootstrapCAWorkflow] [v4.1.1] [ParameterName=ParameterValue ...]
$0 listver [BootstrapCAWorkflow]
$0 jobstatus <JOB_ID>
$0 jobtype-upload path/to/your/jobtype.xml
$0 jobtype-download
The 'push' subcommand uploads your workflow to CIS, and release it.
The 'release' subcommand releases your package.
......@@ -375,6 +402,8 @@ The 'setdef' subcommand set a released package as the default version.
The 'cloudrun' subcommand would run the workflow on CIS. It doesn't wait for job completion.
The 'listver' subcommand shows all versions of your workflow.
The 'jobstatus' subcommand would show the status of specified job. It's usually 'InProgress', 'Blocked' or 'Finished'.
The 'jobtype-upload' subcommand uploads a jobtype definition XML to CIS. Some app might need extra permission to access this feature.
The 'jobtype-download' subcommand downloads the jobtype definition XML of current cis_namespace to STDOUT.
You can push from local directory, CORPNET samba share, or CIS itself. Refer to README.md for more info.
If you omit the version number, 'push' would generate a random verion number, while other subcommands would use the version number in your last push.
......@@ -394,9 +423,11 @@ antidote-cis setdef BootstrapCAWorkflow
antidote-cis cloudrun BootstrapCAWorkflow
antidote-cis cloudrun BuildDomainControllerWorkflow jihyan.9.24.2 IsFirstDC=true UserNameKey=unkey PasswordKey=pwkey @SubscriptionId=420f71ab-35f2-4550-9de6-7c8fab764b4d @Region=westus2
antidote-cis jobstatus 2517645620722579999_df3a452e-d580-47c2-b96e-61f1671358c9
antidote-cis jobtype-upload ../jobtype/modified.xml
antidote-cis jobtype-download > ../jobtype/downloaded.xml
Available env:
ANTIDOTE_JOBSTAT_MARKDOWN: If this variable is not empty, 'jobstatus' would output as markdown instead of plain text.
ANTIDOTE_JOBSTAT_MARKDOWN: If this variable is set to non-empty, 'jobstatus' would output as markdown instead of plain text.
"
exit 1
esac
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment