ctr = 0
try:
- jsonobj = json.loads(args['jsonblob'])
+ jsonobj = json.loads(args["jsonblob"])
except KeyError:
print("countnodes: json blob to parse not found")
raise
- if 'subnode' in args:
+ if "subnode" in args:
ctr = len(jsonobj)
- elif 'category' in args:
- category_ = args['category'].encode('ascii', 'ignore')
+ elif "category" in args:
+ category_ = args["category"].encode("ascii", "ignore")
ctr = len(jsonobj[category_])
else:
# working with a single record, short-cut and return count of 1
:returns number_nodes: the correct number of fields you counted
in the json
"""
- number_nodes = countnodes({'jsonblob': pobject, 'field': field})
+ number_nodes = countnodes({"jsonblob": pobject, "field": field})
return number_nodes
:returns number_nodes: the correct number of fields you counted
in the json
"""
- number_nodes = countnodes({'jsonblob': pobject, 'subnode': subnode})
+ number_nodes = countnodes({"jsonblob": pobject, "subnode": subnode})
return number_nodes
:returns number_nodes: the correct number of fields you counted
in the json
"""
- number_nodes = \
- countnodes({'jsonblob': pobject, 'category': category, 'node': node})
+ number_nodes = countnodes({"jsonblob": pobject, "category": category, "node": node})
return number_nodes
:returns nodelist: return the first id that has same corresponding name
"""
try:
- jsonobj = json.loads(str(args['jsonblob']))
+ jsonobj = json.loads(str(args["jsonblob"]))
except KeyError:
print("get_id_by_name: json blob not specified:")
raise
try:
- name = args['name']
+ name = args["name"]
except KeyError:
print("get_id_by_name: name [usr, domain, role] not specified in args")
raise
- if 'head' in args:
- blobkey = args['head']
+ if "head" in args:
+ blobkey = args["head"]
else:
# use an empty key when the arg is not specified. deals with simpler
# form
- blobkey = ''
+ blobkey = ""
try:
- datatype = args['typeval']
+ datatype = args["typeval"]
except KeyError:
print("get_id_by_name: need a type arg to process correct name for id")
raise
try:
- ncount = args['size']
+ ncount = args["size"]
except KeyError:
raise
if ncount > 0:
for i in range(ncount):
# build up some 'lookup' keys, call jsonpath with that key
- bkey1 = '$.' + blobkey + '[' + str(i) + '].name'
- typename = datatype + 'id'
- bkey2 = '$.' + blobkey + '[' + str(i) + '].' + typename
+ bkey1 = "$." + blobkey + "[" + str(i) + "].name"
+ typename = datatype + "id"
+ bkey2 = "$." + blobkey + "[" + str(i) + "]." + typename
# find records with same name
- name_record = jsonobj[blobkey][i]['name']
+ name_record = jsonobj[blobkey][i]["name"]
# find corresponding node info, for that name
node_record = jsonobj[blobkey][i][typename]
to the provided id
"""
try:
- jsonobj = json.loads(args['jsonblob'])
+ jsonobj = json.loads(args["jsonblob"])
except KeyError:
print("get_attribute_by_id: json blob not specified:")
raise
try:
- nodeid = args['id']
+ nodeid = args["id"]
except KeyError:
print("get_attribute_by_id: id to look for not specified in parameters")
raise
- if 'attr' in args:
- attr = args['attr']
+ if "attr" in args:
+ attr = args["attr"]
else:
# If caller does not specify a record attribute to return, then
# simply default to giving the description of the id you are
# searching on
- attr = 'description'
+ attr = "description"
- if 'head' in args:
+ if "head" in args:
# will be one of roles, users, domains, or empty to process more
# specific grouping of json data
- blobkey = args['head']
+ blobkey = args["head"]
else:
# use an empty key when the arg is not specified, allows us to
# process chunk of JSON without the outer layer defining roles,
# users, domains. (simpler format)
- blobkey = ''
+ blobkey = ""
try:
- datatype = args['typeval']
+ datatype = args["typeval"]
except KeyError:
print("get_attribute_by_id: need type arg to process name for id")
raise
try:
- size = args['size']
+ size = args["size"]
except KeyError:
print("get_attribute_by_id: specify number of records we need")
raise
- typename = datatype + 'id'
+ typename = datatype + "id"
# Loop through the records looking for the nodeid, when found, return
# the corresponding attribute value
for i in range(ncount):
try:
- name_record = jsonobj[blobkey][i]['name']
+ name_record = jsonobj[blobkey][i]["name"]
node_record = jsonobj[blobkey][i][typename]
except Exception:
- name_record = jsonobj['name']
+ name_record = jsonobj["name"]
node_record = jsonobj[typename]
if nodeid == node_record:
:returns roleid: a list of one or more roleid's that match
the rolename given
"""
- roleid = get_id_by_name({'jsonblob': pobject,
- 'name': rolename,
- 'head': 'roles',
- 'size': number_nodes,
- 'typeval': 'role'})
+ roleid = get_id_by_name(
+ {
+ "jsonblob": pobject,
+ "name": rolename,
+ "head": "roles",
+ "size": number_nodes,
+ "typeval": "role",
+ }
+ )
try:
roleid
except Exception:
:returns rolename: the role name that corresponds to the record
identified by the role-id
"""
- rolename = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'roles',
- 'id': roleid,
- 'attr': 'name',
- 'size': number_nodes,
- 'typeval': 'role'})
+ rolename = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "roles",
+ "id": roleid,
+ "attr": "name",
+ "size": number_nodes,
+ "typeval": "role",
+ }
+ )
try:
rolename
except Exception:
:returns roledesc: the role description that corresponds to the record
identified by the role-id
"""
- roledesc = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'roles',
- 'id': roleid,
- 'attr': 'description',
- 'size': number_nodes,
- 'typeval': 'role'})
+ roledesc = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "roles",
+ "id": roleid,
+ "attr": "description",
+ "size": number_nodes,
+ "typeval": "role",
+ }
+ )
try:
roledesc
except Exception:
:returns domainid: a list of one or more domain-id's that match
the domain-name given
"""
- domainid = get_id_by_name({'jsonblob': pobject,
- 'head': 'domains',
- 'name': domainname,
- 'size': number_nodes,
- 'typeval': 'domain'})
+ domainid = get_id_by_name(
+ {
+ "jsonblob": pobject,
+ "head": "domains",
+ "name": domainname,
+ "size": number_nodes,
+ "typeval": "domain",
+ }
+ )
try:
domainid
:returns domainname: the domain name that corresponds to the record
identified by the domainid
"""
- domainname = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'domains',
- 'id': domainid,
- 'attr': 'name',
- 'size': number_nodes,
- 'typeval': 'domain'})
+ domainname = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "domains",
+ "id": domainid,
+ "attr": "name",
+ "size": number_nodes,
+ "typeval": "domain",
+ }
+ )
try:
domainname
except Exception:
:returns domainname: the domain description field that corresponds
to the record identified by the domainid
"""
- domaindesc = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'domains',
- 'id': domainid,
- 'attr': 'description',
- 'size': number_nodes,
- 'typeval': 'domain'})
+ domaindesc = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "domains",
+ "id": domainid,
+ "attr": "description",
+ "size": number_nodes,
+ "typeval": "domain",
+ }
+ )
try:
domaindesc
except Exception:
:returns domainstate: the domain state (enabled) field that
corresponds to the record identified by the domainid
"""
- domainstate = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'domains',
- 'id': domainid,
- 'attr': 'enabled',
- 'size': number_nodes,
- 'typeval': 'domain'})
+ domainstate = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "domains",
+ "id": domainid,
+ "attr": "enabled",
+ "size": number_nodes,
+ "typeval": "domain",
+ }
+ )
try:
domainstate
except Exception:
:returns userid: a list of one or more user-id's that match
the username given
"""
- userid = get_id_by_name({'jsonblob': pobject,
- 'name': username,
- 'head': 'users',
- 'size': number_nodes,
- 'typeval': 'user'})
+ userid = get_id_by_name(
+ {
+ "jsonblob": pobject,
+ "name": username,
+ "head": "users",
+ "size": number_nodes,
+ "typeval": "user",
+ }
+ )
try:
userid
except Exception:
:returns userpassword: the raw password field that corresponds to
the record identified by the userid
"""
- userpassword = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'users',
- 'id': userid,
- 'attr': 'password',
- 'size': number_nodes,
- 'typeval': 'user'})
+ userpassword = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "users",
+ "id": userid,
+ "attr": "password",
+ "size": number_nodes,
+ "typeval": "user",
+ }
+ )
try:
userpassword
except Exception:
:returns username: the name field that corresponds to the record
identified by the userid
"""
- username = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'users',
- 'id': userid,
- 'attr': 'name',
- 'size': number_nodes,
- 'typeval': 'user'})
+ username = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "users",
+ "id": userid,
+ "attr": "name",
+ "size": number_nodes,
+ "typeval": "user",
+ }
+ )
try:
username
except Exception:
:returns userstate: the enabled field that corresponds to the record
identified by the userid
"""
- userstate = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'users',
- 'id': userid,
- 'attr': 'enabled',
- 'size': number_nodes,
- 'typeval': 'user'})
+ userstate = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "users",
+ "id": userid,
+ "attr": "enabled",
+ "size": number_nodes,
+ "typeval": "user",
+ }
+ )
try:
userstate
except Exception:
:returns useremail: the email field that corresponds to the record
identified by the userid
"""
- useremail = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'users',
- 'id': userid,
- 'attr': 'email',
- 'size': number_nodes,
- 'typeval': 'user'})
+ useremail = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "users",
+ "id": userid,
+ "attr": "email",
+ "size": number_nodes,
+ "typeval": "user",
+ }
+ )
try:
useremail
except Exception:
:returns userdesc: the description field that corresponds to the
record identified by the userid
"""
- userdesc = get_attribute_by_id({'jsonblob': pobject,
- 'head': 'users',
- 'id': userid,
- 'attr': 'description',
- 'size': number_nodes,
- 'typeval': 'user'})
+ userdesc = get_attribute_by_id(
+ {
+ "jsonblob": pobject,
+ "head": "users",
+ "id": userid,
+ "attr": "description",
+ "size": number_nodes,
+ "typeval": "user",
+ }
+ )
try:
userdesc
except Exception: