Example #1
0
    def _read(self, name, kind, action, jsonfile,
              connection=None, save_connection=True):
        jf = open(jsonfile).read()
        data = json.loads(jf)

        if name is not None:
            data['privilege-name'] = name
        if kind is not None:
            data['kind'] = kind
        if action is not None:
            data['action'] = action

        privilege = Privilege.unmarshal(data,
                                        connection=connection,
                                        save_connection=save_connection)
        return privilege
    def _read(self,
              name,
              kind,
              action,
              jsonfile,
              connection=None,
              save_connection=True):
        jf = open(jsonfile).read()
        data = json.loads(jf)

        if name is not None:
            data['privilege-name'] = name
        if kind is not None:
            data['kind'] = kind
        if action is not None:
            data['action'] = action

        privilege = Privilege.unmarshal(data,
                                        connection=connection,
                                        save_connection=save_connection)
        return privilege
# 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"
        priv = Privilege.unmarshal(config)
        print("{0} {1} privilege: {2}".format(verb, kind, name))
        priv.update(conn)

# Update users
for config in data['users']:
    name = config['user-name']
    user = User.lookup(conn, name)
    if user is None:
        verb = "Creating"
        user = User.unmarshal(config)