Browse Source

Bug/patch (#96)

* add patch method

* update comments
master
Gerry Nelson 4 years ago
committed by GitHub
parent
commit
28e4b5963a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      callrestapi.py
  2. 10
      exportcaslibs.py
  3. 2
      exportfolder.py
  4. 5
      sharedfunctions.py

21
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)

10
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)

2
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

5
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")

Loading…
Cancel
Save