Ejemplo n.º 1
0
def load_src(args):
    if args.src is None:
        src_path = default.DEFAULT_SERVICE
        msg = noexplicit("Service")
        printv(msg, args.verbose)
    else:
         src_path = args.src
    try:
        src = x.load_src(src_path)
        src.AUTH = x.load_auth(auth_path(args))
        return src, src_path
    except x.SrcLoadError:
        print("Error when trying to load Src file")
        print("Service path: ", src_path)
        raise
    except x.AuthLoadError:
        print("Error when trying to load Auth file")
        print("Auth path: ", auth_path(args))
        raise
Ejemplo n.º 2
0
def load_insp(args):
    if args.insp is None:
        insp_path = default.DEFAULT_INSPECTOR
        msg = noexplicit("Inspector")
        printv(msg, args.verbose)
    else:
        insp_path = args.insp

    try:
        insp = x.load_insp(insp_path)
        insp.AUTH = x.load_auth(auth_path(args))
        return insp, insp_path
    except x.InspLoadError:
        print("Error when trying to load Inspector file")
        print("Inspector path: ", insp_path)
        raise
    except x.AuthLoadError:
        print("Error when trying to load Auth file")
        print("Auth path: ", auth_path(args))
        raise
Ejemplo n.º 3
0
def load_usr(args):
    if args.usr is None:
        usr_path = default.DEFAULT_USER
        msg = noexplicit("User")
        printv(msg, args.verbose)
    else:
        usr_path = args.usr

    try:
        usr = x.load_usr(usr_path)
        usr.AUTH = x.load_auth(auth_path(args))
        return usr, usr_path
    except x.UsrLoadError:
        print("Error when trying to load User file")
        print("User path: ", usr_path)
        raise
    except x.AuthLoadError:
        print("Error when trying to load Auth file")
        print("Auth path: ", auth_path(args))
        raise
Ejemplo n.º 4
0
def run_form(args):
    usr, usr_path = load_usr(args)
    d = x.file_to_dict(args.req)
    req = x.Request.from_dict(d)
    try:
        blob = usr.create_blob(req, data=args.secdata)
    except:
        print("Problems with forming Blob. Request might be damaged or wrong")
        blob = None
    if blob is not None:
        x.to_file(args.output, blob)
        print("The blob was succesfully created. Stored in file: ",
              args.output)
        x.to_file(usr_path, usr)
        x.to_file(auth_path(args), usr.AUTH)
Ejemplo n.º 5
0
def run_form(args):
    src, src_path = load_src(args)
    due = datetime.datetime.strptime(args.due, '%Y-%m-%d').date()
    ttl = x.TTL(due)
    req = src.create_request(args.uid, args.scope, ttl)
    if args.verbose:
        print("The following request was formed:")
        print("Src ID: ", req.srcid)
        print("User ID: ", req.uid)
        print("Scope: ", req.scope)
        print("Due to: ", req.ttl.expired)
    x.to_file(args.output, req)
    if args.verbose:
        print("The following file for output was used: ", args.output)
    print("Request was succesfully created. Stored in file: ", args.output)
    x.to_file(src_path, src)
    x.to_file(auth_path(args), src.AUTH)
Ejemplo n.º 6
0
def run_adduser(args):
    insp, insp_path = load_insp(args)
    insp.add_user(args.uid, args.secdata)
    print("User personal data was succesfully added")
    x.to_file(insp_path, insp)
    x.to_file(auth_path(args), insp.AUTH)
Ejemplo n.º 7
0

def parse_CLI(arguments):
    parser = argparse.ArgumentParser(description='Registration script')
    parser.add_argument('--service', '-s', action="store_true", dest="src")
    parser.add_argument('--user', '-u', action="store_true", dest="usr")
    parser.add_argument('--inspector', '-i', action="store_true", dest="insp")
    parser.add_argument('--scope', '-S', action="store", dest="scope")
    parser.add_argument('--auth', '-a', action="store", dest="AUTH")
    parser.add_argument('--key' '-k', action="store", dest="key")
    parser.add_argument('--output', '-o', action="store", dest="output")
    parser.add_argument('--verbose', '-v', action="store_true")
    args = parser.parse_args(arguments)
    check = check_args(args)
    if check:
        return args
    else:
        return None

if __name__ == "__main__":
    args = parse_CLI(sys.argv[1:])
    if args is not None:
        AUTH = x.load_auth(auth_path(args))
        if args.src:
            create_service(args, AUTH)
        elif args.usr:
            create_user(args, AUTH)
        else:
            create_inspector(args, AUTH)
        x.to_file(auth_path(args),AUTH)