Skip to content

Commit

Permalink
endpoint to post a revolution processing log
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed Jul 3, 2023
1 parent f6200b5 commit 9fd17cd
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cdci_data_analysis/analysis/drupal_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ContentType(Enum):
DATA_PRODUCT = auto()
OBSERVATION = auto()
ASTROPHYSICAL_ENTITY = auto()
REVOLUTION_PROCESSING_LOG = auto()


def analyze_drupal_output(drupal_output, operation_performed=None):
Expand Down Expand Up @@ -460,6 +461,13 @@ def post_content_to_gallery(decoded_token,
timezone=timezone,
sentry_dsn=sentry_dsn,
**par_dic)
elif content_type == content_type.REVOLUTION_PROCESSING_LOG:
user_id_product_creator = par_dic.pop('user_id_product_creator')
output_content_post = post_revolution_processing_log_to_gallery(product_gallery_url=product_gallery_url,

Check warning on line 466 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L464-L466

Added lines #L464 - L466 were not covered by tests
gallery_jwt_token=gallery_jwt_token,
user_id_product_creator=user_id_product_creator,
sentry_dsn=sentry_dsn,
**par_dic)
elif content_type == content_type.OBSERVATION:
# TODO build the body to send to the gallery in more automated fashion (like done for the data-product)
t1 = kwargs.pop('T1', None)
Expand Down Expand Up @@ -1049,6 +1057,50 @@ def get_observation_drupal_id(product_gallery_url, gallery_jwt_token, converttim
return observation_drupal_id, observation_information_message, output_post


def post_revolution_processing_log_to_gallery(product_gallery_url, gallery_jwt_token,
user_id_product_creator=None,
sentry_dsn=None,
**kwargs):
body_gallery_article_node = copy.deepcopy(body_article_product_gallery.body_node)

Check warning on line 1064 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1064

Added line #L1064 was not covered by tests

# set the type of content to post
body_gallery_article_node["_links"]["type"]["href"] = os.path.join(product_gallery_url,

Check warning on line 1067 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1067

Added line #L1067 was not covered by tests
body_gallery_article_node["_links"]["type"][
"href"], 'data_product')

# set the initial body content
body_gallery_article_node["body"][0]["value"] = ''

Check warning on line 1072 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1072

Added line #L1072 was not covered by tests

# set the user id of the author of the data product
if user_id_product_creator is not None:
body_gallery_article_node["uid"] = [{

Check warning on line 1076 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1075-L1076

Added lines #L1075 - L1076 were not covered by tests
"target_id": user_id_product_creator
}]

# body_gallery_article_node["title"]["value"] = "revnumber_status_log"

# let's go through the kwargs and if any overwrite some values for the product to post
for k, v in kwargs.items():

Check warning on line 1083 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1083

Added line #L1083 was not covered by tests
# assuming the name of the field in drupal starts always with field_
field_name = str.lower('field_' + k)
body_gallery_article_node[field_name] = [{

Check warning on line 1086 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1085-L1086

Added lines #L1085 - L1086 were not covered by tests
"value": v
}]

# finally, post the data product to the gallery
headers = get_drupal_request_headers(gallery_jwt_token)

Check warning on line 1091 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1091

Added line #L1091 was not covered by tests

logger.info("posting a new revolution-processing-log")
log_res = execute_drupal_request(os.path.join(product_gallery_url, 'node', ),

Check warning on line 1094 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1093-L1094

Added lines #L1093 - L1094 were not covered by tests
method='post',
data=json.dumps(body_gallery_article_node),
headers=headers,
sentry_dsn=sentry_dsn)
output_post = analyze_drupal_output(log_res, operation_performed="posting a new revolution processing log to the gallery")

Check warning on line 1099 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1099

Added line #L1099 was not covered by tests

return output_post

Check warning on line 1101 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1101

Added line #L1101 was not covered by tests


def post_data_product_to_gallery(product_gallery_url, gallery_jwt_token, converttime_revnum_service_url,
data_product_id=None,
product_title=None,
Expand Down
28 changes: 28 additions & 0 deletions cdci_data_analysis/flask_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,34 @@ def post_product_to_gallery():
return output_post


@app.route('/post_revolution_processing_log_to_gallery', methods=['POST'])
def post_revolution_processing_log_to_gallery():
logger.info("request.args: %s ", request.args)

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
logger.info("request.files: %s ", request.files)

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Check warning on line 932 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L931-L932

Added lines #L931 - L932 were not covered by tests

token = request.args.get('token', None)
app_config = app.config.get('conf')
secret_key = app_config.secret_key

Check warning on line 936 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L934-L936

Added lines #L934 - L936 were not covered by tests

output, output_code = tokenHelper.validate_token_from_request(token=token, secret_key=secret_key,

Check warning on line 938 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L938

Added line #L938 was not covered by tests
required_roles=['gallery contributor'],
action="post revolution processing log on the product gallery")

if output_code is not None:
return make_response(output, output_code)

Check warning

Code scanning / CodeQL

Reflected server-side cross-site scripting Medium

Cross-site scripting vulnerability due to a
user-provided value
.
decoded_token = output

Check warning on line 944 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L942-L944

Added lines #L942 - L944 were not covered by tests

par_dic = request.values.to_dict()
par_dic.pop('token')

Check warning on line 947 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L946-L947

Added lines #L946 - L947 were not covered by tests

output_post = drupal_helper.post_content_to_gallery(decoded_token=decoded_token,

Check warning on line 949 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L949

Added line #L949 was not covered by tests
disp_conf=app_config,
files=request.files,
**par_dic)

return output_post

Check warning on line 954 in cdci_data_analysis/flask_app/app.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/flask_app/app.py#L954

Added line #L954 was not covered by tests


@app.route('/report_incident', methods=['POST'])
def report_incident():
logger.info("request.args: %s ", request.args)
Expand Down

0 comments on commit 9fd17cd

Please sign in to comment.