def _read(self, name, jsonfile, connection=None, save_connection=True):
        jf = open(jsonfile).read()
        data = json.loads(jf)

        if name is not None:
            data['role-name'] = name

        role = Role.unmarshal(data,
                              connection=connection,
                              save_connection=save_connection)
        return role
Exemple #2
0
 def _read(self, name, jsonfile):
     jf = open(jsonfile).read()
     data = json.loads(jf)
     data['role-name'] = name
     role = Role.unmarshal(data)
     return role
conn = Connection(args.host, HTTPDigestAuth(args.username, args.password))

# Create roles
for config in data['roles']:
    name = config['role-name']
    role = Role.lookup(conn, name)
    if role is None:
        print("Need to create role: {0}".format(name))
        role = Role(name)
        role.create(conn)

# Update privileges
for config in data['roles']:
    name = config['role-name']
    role = Role.unmarshal(config)
    print("Updating role: {0}".format(name))
    role.update(conn)

# Update privileges
for config in data['privileges']:
    name = config['privilege-name']
    kind = config['kind']
    priv = Privilege.lookup(conn, name, kind)
    if priv is None:
        verb = "Creating"
        priv = Privilege.unmarshal(config)
        print("{0} privilege: {1}".format(verb, name))
        priv.create(conn)
    else:
        verb = "Updating"
Exemple #4
0
 def _read(self, name, jsonfile):
     jf = open(jsonfile).read()
     data = json.loads(jf)
     data['role-name'] = name
     role = Role.unmarshal(data)
     return role