예제 #1
0
    )
if principaltype and name is None:
    raise Exception(
        'If you specify a principal type, you must also specify a principal name.'
    )

for permission in permissions:
    if permission not in valid_permissions:
        raise Exception(
            permission +
            ' is not the name of a permission. Valid permissions are: ' +
            ' '.join(map(str, valid_permissions)))

# Two ways this program can be used: for a folder, or for a URI.
if path_to_folder:
    getfolderid_result_json = getfolderid(path_to_folder)

    if (debug):
        print(getfolderid_result_json)

    if getfolderid_result_json[0] is not None:
        folder_uri = getfolderid_result_json[1]
        if (debug):
            print("Id  = " + getfolderid_result_json[0])
            print("URI = " + folder_uri)
            print("Path = " + getfolderid_result_json[2])

    explainuri = folder_uri
    resultpath = path_to_folder
    #Set convey to true, unless user overrode that setting and asked for false
    if (conveyparam is not None and conveyparam.lower() == 'false'):
예제 #2
0
parser.add_argument("-f",
                    "--folderpath",
                    help="Enter the path to the viya folder.",
                    required='True')
parser.add_argument("-q",
                    "--quiet",
                    help="Suppress the are you sure prompt.",
                    action='store_true')
args = parser.parse_args()

print(args.folderpath)
path_to_folder = args.folderpath
quietmode = args.quiet

# call getfolderid to get the folder id
targets = getfolderid(path_to_folder)

# if the folder is found
if targets[0] is not None:

    uri = targets[1]

    # if quiet do not prompt
    if quietmode:
        areyousure = "Y"
    else:

        if version > 2:
            areyousure = input(
                "Are you sure you want to delete the folder and its contents? (Y)"
            )
            newfolder = row[0]
            description = row[1]

            if newfolder[0] != '/': newfolder = "/" + newfolder

            folder = os.path.basename(os.path.normpath(newfolder))
            parent_folder = os.path.dirname(newfolder)

            data = {}
            data['name'] = folder
            data['description'] = description

            print("Creating folder " + newfolder)

            if parent_folder == "/": reqval = '/folders/folders'
            else:  # parent folder create a child

                parentinfo = getfolderid(parent_folder)

                if parentinfo != None:

                    parenturi = parentinfo[1]
                    reqval = '/folders/folders?parentFolderUri=' + parenturi

                else:
                    print("Parent folder not found")

            myresult = callrestapi(reqval, reqtype, data=data, stoponerror=0)
else:
    print("ERROR: cannot read " + file)
예제 #4
0
parser.add_argument("-t",
                    "--targetfolder",
                    help="Enter the path to the source folder.",
                    required='True')
parser.add_argument("-q",
                    "--quiet",
                    help="Suppress the are you sure prompt.",
                    action='store_true')
args = parser.parse_args()

source = args.sourcefolder
target = args.targetfolder

quietmode = args.quiet

sourceinfo = getfolderid(source)
targetinfo = getfolderid(target)

if sourceinfo[0] is not None:

    id = sourceinfo[0]

    if quietmode:
        areyousure = "Y"
    else:

        if version > 2:
            areyousure = input("Are you sure you want to move content from " +
                               source + " to " + target + "? (Y)")
        else:
            areyousure = raw_input(
예제 #5
0
            )
    else:
        areyousure = "Y"

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)
예제 #6
0
if modby!=None: filtercond.append("eq(modifiedBy,"+modby+")")

# set the request type
reqtype='get'
delimiter = ','

# process items not in folders
if puri!=None: 
   filtercond.append("contains(parentUri,'"+puri+"')")
   completefilter = 'and('+delimiter.join(filtercond)+')'
   reqval="/files/files?filter="+completefilter+"&sortBy="+sortby+":descending&limit=10000"
       
# process items in folders
elif pfolder!=None:

   folderid=getfolderid(pfolder)[0]     
   # add the start and end and comma delimit the filter
   completefilter = 'and('+delimiter.join(filtercond)+')'
   reqval="/folders/folders/"+folderid+"/members?filter="+completefilter+"&sortBy="+sortby+":descending&limit=10000"
   
   files_in_folder=callrestapi(reqval,reqtype)
      
   #now get the file objects using the ids returned
   iddict=getidsanduris(files_in_folder)
   
   # get the uris of the files   
   uris=iddict['uris']
   
   #get id, need to do this because only the uri of the folder is returned
   
   idlist=[]
# file can be read
if check:
    #    print("file: "+file)
    with open(file, 'rt') as f:
        filecontents = csv.reader(f)
        for row in filecontents:
            folderpath = row[0]
            principaltype = row[1]
            principalname = row[2]
            accesssetting = row[3]
            folderpermissions = row[4]
            conveyedpermissions = row[5]

            #            print("Creating auth rules for "+folderpath)

            folderid = getfolderid(folderpath)
            folderuri = folderid[0]
            reqval = '/folders/folders/' + folderuri

            # Construct JSON objects from auth rules defined in CSV. Two JSON objects are created for each row of CSV; one for perms on the folder object, one for conveyed perms on the object's contents.
            value_dict_object = {
                "description": "Created by applyfolderauthorizations.py",
                "objectUri": reqval,
                "permissions": folderpermissions.split(','),
                "principalType": principaltype,
                "principal": principalname,
                "type": accesssetting
            }
            value_dict_container = {
                "description": "Created by applyfolderauthorizations.py",
                "containerUri": reqval,