#reqval='/identities/groups' reqval = '/identities/groups/?filter=ne(providerId,"local")&limit=10000' groupslist_result_json = callrestapi(reqval, reqtype) groups = groupslist_result_json['items'] for group in groups: groupid = group['id'] reqval = '/identities/groups/' + groupid + '/identifier' posixinfo_result_json = callrestapi(reqval, reqtype) # get gid group["gid"] = posixinfo_result_json["gid"] cols = ['id', 'gid', 'name'] printresult(groupslist_result_json, output_style, cols) else: # set the request type reqtype = 'get' # set the endpoint to call reqval = '/identities/groups/' + group + "/identifier" if debug: print(reqval) #make the rest call using the callrestapi function. You can have one or many calls group_info_result_json = callrestapi(reqval, reqtype) # seems to be returning non standard results add id to make it standard # print result expects there to an id so use gid
ts_before=args.before # Create list for filter conditions filtercond=[] if appname!=None: filtercond.append("eq(application,'"+appname+"')") if username!=None: filtercond.append("eq(user,'"+username+"')") if entry_type!=None: filtercond.append("eq(type,'"+entry_type+"')") if entry_action!=None: filtercond.append("eq(action,'"+entry_action+"')") if entry_state!=None: filtercond.append("eq(state,'"+entry_state+"')") if ts_after!=None: filtercond.append("ge(timeStamp,'"+ts_after+"')") if ts_before!=None: filtercond.append("le(timeStamp,'"+ts_before+"')") # Construct filter delimiter = ',' completefilter = 'and('+delimiter.join(filtercond)+')' # Set request reqtype = 'get' reqval = "/audit/entries?filter="+completefilter+"&limit="+output_limit+"&sortBy="+sort_order # Construct & print endpoint URL baseurl=getbaseurl() endpoint=baseurl+reqval # print("REST endpoint: " +endpoint) # Make REST API call, and process & print results files_result_json=callrestapi(reqval,reqtype) cols=['id','timeStamp','type','action','state','user','remoteAddress','application','description','uri'] printresult(files_result_json,output_style,cols)
parser.add_argument("-m","--method", help="Enter the REST method.",default="get",required='True',choices=['get','put','post','delete']) 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") parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') parser.add_argument("-t","--text", help="Display Simple Text Results.", action='store_true') args = parser.parse_args() reqval=args.endpoint reqtype=args.method reqfile=args.inputfile reqcontent=args.contenttype reqaccept=args.accepttype simpletext=args.text output_style=args.output # keep for backward compatibility if simpletext: output_style='simple' # use the callrestapi function to make a call to the endpoint # call passing json or not if reqfile != None: inputdata=getinputjson(reqfile) result=callrestapi(reqval,reqtype,reqaccept,reqcontent,data=inputdata) else: result=callrestapi(reqval,reqtype,reqaccept,reqcontent) #print the result printresult(result,output_style)
else: areyousure = "Y" # prompt is Y if user selected Y, its a new directory, or user selected quiet mode if areyousure.upper() == 'Y': path = basedir # create directory if it doesn't exist if not os.path.exists(path): os.makedirs(path) folderinfo = getfolderid(folderpath) results = (folderinfo[3]) printresult(results, 'JSON') id = results["id"] package_name = str(uuid.uuid1()) json_name = folderpath.replace("/", "_") if filename != "XNOFILENAMEX": json_name = filename command = clicommand + ' transfer export -u /folders/folders/' + id + ' --name "' + package_name + '"' print(command) subprocess.call(command, shell=True) reqtype = 'get' reqval = '/transfer/packages?filter=eq(name,"' + package_name + '")' package_info = callrestapi(reqval, reqtype) package_id = package_info['items'][0]['id']
# setup command-line arguements parser = argparse.ArgumentParser() parser.add_argument("-f", "--folderpath", help="Enter the path to the viya folder.", required='True') parser.add_argument("-o", "--output", help="Output Style", choices=['csv', 'json', 'simple', 'simplejson'], default='csv') args = parser.parse_args() path_to_folder = args.folderpath output_style = args.output # call the get folderid function and pass it the entered path targets = getfolderid(path_to_folder) # default simple output style prints with original print method # but can also choose json or csv if output_style == 'simple': #print results if any are returned if targets[0] is not None: print("Id = " + targets[0]) print("URI = " + targets[1]) print("Path = " + targets[2]) else: printresult(targets[3], output_style)
if ident == 'none' and objuri == 'none': reqval = reqval + '?limit=' + str(limitval) else: reqval = reqval + '&limit=' + str(limitval) reqtype = 'get' #make the rest call rules_result_json = callrestapi(reqval, reqtype) #print(rules_result_json) #print('rules_result_json is a '+type(rules_result_json).__name__+' object') #rules_result_json is a dict object #print the result if output style is json or simple if output_style in ['json', 'simple']: printresult(rules_result_json, output_style) elif output_style == 'csv': # Print a header row print(','.join(map(str, desired_output_columns))) if 'items' in rules_result_json: #print "There are " + str(rules_result_json['count']) + " rules" for item in rules_result_json['items']: outstr = '' #print(item) for column in desired_output_columns: # Add a comma to the output string, even if we will not output anything else, unless this is the very first desired output column if column is not desired_output_columns[0]: outstr = outstr + ',' if column == 'setting': # The setting value is derived from two columns: type and condition. if 'condition' in item:
returned_items = len(itemlist) if total_items == 0: print("Note: No items returned.") else: # get the path for each report and add it to the result set # this is not very efficient. I will try to improve it for i in range(0, returned_items): id = itemlist[i]["id"] name = itemlist[i]["name"] path_to_report = getpath("/reports/reports/" + id) # add the path as an attribute of flag for delete if path_to_report.startswith(folderpath): itemlist[i]["fullreport"] = path_to_report + name else: itemlist[i]["fullreport"] = 'delete' # remove non matches before printing newlist = [i for i in itemlist if not (i['fullreport'] == 'delete')] resultdata['items'] = newlist resultdata['count'] = len(newlist) printresult(resultdata, output_style, colsforcsv=[ "id", "fullreport", "type", "description", "creationTimeStamp", "modifiedTimeStamp" ])
# setup command-line arguements parser = argparse.ArgumentParser(description="Display POSIX attributes for User") parser.add_argument("-u","--user", help="Enter the user id",required='True') parser.add_argument("-d","--debug", action='store_true', help="Debug") parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='json') args = parser.parse_args() user=args.user debug=args.debug output_style=args.output # set the request type reqtype='get' # set the endpoint to call reqval='/identities/users/'+user+"/identifier" if debug: print(reqval) #make the rest call using the callrestapi function. You can have one or many calls user_info_result_json=callrestapi(reqval,reqtype) # seems to be returning non standard results add id to make it standard # print result expects there to an id so use uid user_info_result_json['id']=user_info_result_json["uid"] user_info_result_json['username']=user printresult(user_info_result_json,output_style)
# Import Python modules from __future__ import print_function import argparse import pprint pp = pprint.PrettyPrinter(indent=4) from sharedfunctions import callrestapi, printresult parser = argparse.ArgumentParser( description="Return a set of configuration properties") parser.add_argument("-c", "--configuration", help="Enter the configuration definition.", required='True') parser.add_argument("-o", "--output", help="Output Style", choices=['csv', 'json', 'simple', 'simplejson'], default='json') args = parser.parse_args() configurationdef = args.configuration output_style = args.output reqval = "/configuration/configurations?definitionName=" + configurationdef configvalues = callrestapi(reqval, 'get') printresult(configvalues, output_style)
default="cas-shared-default") parser.add_argument("-o", "--output", help="Output Style", choices=['csv', 'json', 'simple', 'simplejson'], default='csv') args = parser.parse_args() casserver = args.server output_style = args.output # set the request type reqtype = 'get' # set the endpoint to call reqval = '/dataSources/providers/cas/sources/' + casserver + '/children?&limit=100000' #make the rest call using the callrestapi function. You can have one or many calls caslib_result_json = callrestapi(reqval, reqtype) # example of overriding the columns for csv output cols = ['name', 'type', 'path', 'scope', 'attributes', 'description'] # print result accepts # the json returned # the output style # optionally the columns for csv outtput, if you don't pass in columns you get defaults # You can just print results r post process the results as you need to printresult(caslib_result_json, output_style, cols)