From 28e4b5963a49cf90c519dd70664f1cb98615c2da Mon Sep 17 00:00:00 2001 From: Gerry Nelson <45608078+gerrynelson63@users.noreply.github.com> Date: Fri, 18 Feb 2022 12:36:47 -0500 Subject: [PATCH] Bug/patch (#96) * add patch method * update comments --- callrestapi.py | 21 +++++++++++---------- exportcaslibs.py | 10 +++++----- exportfolder.py | 2 +- sharedfunctions.py | 5 ++++- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/callrestapi.py b/callrestapi.py index 47a9dd3..1bfbd62 100755 --- a/callrestapi.py +++ b/callrestapi.py @@ -10,16 +10,17 @@ # # 27JAN2017 Comments added # 29JAN2017 Added choices to validate method input -# 31JAN2017 Added contenttype parameters +# 31JAN2017 Added contenttype parameters # 02FEB2018 Added simple text print flag # 01JUN2018 Renamed from call_rest_api.py to callrestapi.py -# 08JUN2018 Print json instead of pprint of easier result parsing -# 01JUN2018 Renamed from call_rest_api.py to callrestapi.py # 08JUN2018 Print json instead of pprint of easier result parsing -# 08OCT2018 make printed json pretty -# 26OCT2018 call print function +# 01JUN2018 Renamed from call_rest_api.py to callrestapi.py +# 08JUN2018 Print json instead of pprint of easier result parsing +# 08OCT2018 make printed json pretty +# 26OCT2018 call print function # 20FEB2020 support simplejson # 16Jul2021 Support for updating the header. (Issue #83) +# 20Feb2022 Support patch # # Copyright © 2018, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. @@ -42,10 +43,10 @@ import argparse from sharedfunctions import callrestapi,getinputjson,printresult # get command line parameters - + parser = argparse.ArgumentParser(description="Call the Viya REST API") parser.add_argument("-e","--endpoint", help="Enter the REST endpoint e.g. /folders/folders ",required='True') -parser.add_argument("-m","--method", help="Enter the REST method.",default="get",required='True',choices=['get','put','post','delete']) +parser.add_argument("-m","--method", help="Enter the REST method.",default="get",required='True',choices=['get','put','post','delete','patch']) parser.add_argument("-i","--inputfile",help="Enter the full path to an input json file",default=None) parser.add_argument("-a","--accepttype",help="Enter REST Content Type you want returned e.g application/vnd.sas.identity.basic+json",default="application/json") parser.add_argument("-c","--contenttype",help="Enter REST Content Type for POST e.g application/vnd.sas.identity.basic+json",default="application/json") @@ -55,8 +56,8 @@ parser.add_argument("-hf","--headerfile",help="Enter the full path to a header j args = parser.parse_args() -reqval=args.endpoint -reqtype=args.method +reqval=args.endpoint +reqtype=args.method reqfile=args.inputfile reqcontent=args.contenttype reqaccept=args.accepttype @@ -81,6 +82,6 @@ elif headfile != None: result=callrestapi(reqval,reqtype,reqaccept,reqcontent,header=headerdata) else: result=callrestapi(reqval,reqtype,reqaccept,reqcontent) - + #print the result printresult(result,output_style) diff --git a/exportcaslibs.py b/exportcaslibs.py index c95cf33..4413d1c 100755 --- a/exportcaslibs.py +++ b/exportcaslibs.py @@ -1,16 +1,16 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# listcaslibs.py +# exportcaslibs.py # January 2019 # # Usage: -# listcaslibs.py [--noheader] [-d] +# exportcaslibs.py -s -i -d -nc -dc -q # # Examples: # -# 1. Return list of all CAS libraries on all servers -# ./listcaslibs.py +# 1. Export all caslibs and auth +# ./exportcaslibs.py -s cas-shared-default -i -d /tmp/mycaslbs -q # # Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # @@ -132,7 +132,7 @@ if areyousure.upper() =='Y': if 'limit' in casauth_result: casauth_result.pop('limit') if 'links' in casauth_result: casauth_result.pop('links') if 'version' in casauth_result: casauth_result.pop('version') - + json.dump(casauth_result, outauth) diff --git a/exportfolder.py b/exportfolder.py index e657df4..ca8593c 100755 --- a/exportfolder.py +++ b/exportfolder.py @@ -4,7 +4,7 @@ # exportfolder.py # Feb 2021 # -# Pass in a folder and this tool will export the folder to a apcakge +# Pass in a folder and this tool will export the folder to a package # # # Change History diff --git a/sharedfunctions.py b/sharedfunctions.py index e231142..8c5c79d 100755 --- a/sharedfunctions.py +++ b/sharedfunctions.py @@ -35,6 +35,7 @@ # 20SEP2019 Added getidsanduris # 09dec2020 Added get_valid_filename function to deal with invalid characters for Linux filesystem # 16Jul2021 Edited callrestapi to be able to update the header. (Issue #83) +# 20Feb2022 Support patch # # Copyright © 2018, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # @@ -79,7 +80,7 @@ def validaterestapi(baseurl, reqval, reqtype, data={}): print("Data for Request:") print(json_data) - if (reqtype !="get" or reqtype !="post" or reqtype!="delete" or reqtype!="put"): + if (reqtype !="get" or reqtype !="post" or reqtype!="delete" or reqtype!="put" or reqtype!="patch" ): print("NOTE: Invalid method") return; @@ -123,6 +124,8 @@ def callrestapi(reqval, reqtype, acceptType='application/json', contentType='app ret = requests.delete(baseurl+reqval,headers=head,data=json_data) elif reqtype=="put": ret = requests.put(baseurl+reqval,headers=head,data=json_data) + elif reqtype=="patch": + ret = requests.patch(baseurl+reqval,headers=head,data=json_data) else: result=None print("NOTE: Invalid method")