Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rbac #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
7 changes: 6 additions & 1 deletion appd/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ class JsonObject(object):

FIELDS = {}

# Added the check to below function to avoid Key_errors, where key we are checking for is not returned by the server
# 'if json_dict.has_key(k):'
# For instance, 'user' object has description field, but when we get the list of users; the description field is not
# sent by server. Description field is present, only when getting the info of an individual user.
@classmethod
def _set_fields_from_json_dict(cls, obj, json_dict):
for k, v in list(obj.FIELDS.items()):
obj.__setattr__(k, json_dict[v or k])
if json_dict.has_key(k):
obj.__setattr__(k, json_dict[v or k])

@classmethod
def from_json(cls, json_dict):
Expand Down
59 changes: 59 additions & 0 deletions appd/model/group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Model classes for AppDynamics REST API

moduleauthor:: Srikar Achanta <[email protected]>

"""

from . import JsonObject, JsonList


class Group(JsonObject):

FIELDS = {'id': '', 'name': '', 'description': '', 'security_provider_type': '', 'roles': None}

def __init__(self, id='0', name=None, description=None, security_provider_type=None, roles=None):
self.id, self.name, self.description, self.security_provider_type, self.roles = id, name, description, \
security_provider_type, roles


class Groups(JsonList):
"""
Represents a collection of :class:Group objects. Extends :class:UserList, so it supports the
standard array index and :keyword:`for` semantics.
"""

def __init__(self, initial_list=None):
super(Groups, self).__init__(Group, initial_list)

def __getitem__(self, i):
"""
:rtype: Group
"""
return self.data[i]

def by_name(self, name):
"""
Finds a group by name.

:returns: First group with the correct name
:rtype: Group
"""
found = [x for x in self.data if x.name == name]
try:
return found[0]
except IndexError:
raise KeyError(name)

def by_id(self, id):
"""
Finds a group by id.

:returns: First group with the correct id
:rtype: Group
"""
found = [x for x in self.data if x.id == id]
try:
return found[0]
except IndexError:
raise KeyError(id)
59 changes: 59 additions & 0 deletions appd/model/role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Model classes for AppDynamics REST API

moduleauthor:: Srikar Achanta <[email protected]>

"""

from . import JsonObject, JsonList


class Role(JsonObject):

FIELDS = {'id': '', 'name': '', 'description': ''}
# FIELDS = {'id': '', 'name': ''}

def __init__(self, id='0', name=None, description=None):
self.id, self.name, self.description = id, name, description


class Roles(JsonList):
"""
kylefurlong marked this conversation as resolved.
Show resolved Hide resolved
Represents a collection of :class:Role objects. Extends :class:UserList, so it supports the
standard array index and :keyword:`for` semantics.
"""

def __init__(self, initial_list=None):
super(Roles, self).__init__(Role, initial_list)

def __getitem__(self, i):
"""
:rtype: Role
"""
return self.data[i]

def by_name(self, name):
"""
Finds a role by name.

:returns: First role with the correct name
:rtype: Role
"""
found = [x for x in self.data if x.name == name]
try:
return found[0]
except IndexError:
raise KeyError(name)

def by_id(self, id):
"""
Finds a role by id.

:returns: First role with the correct id
:rtype: Role
"""
found = [x for x in self.data if x.id == id]
try:
return found[0]
except IndexError:
raise KeyError(id)
61 changes: 61 additions & 0 deletions appd/model/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Model classes for AppDynamics REST API

moduleauthor:: Srikar Achanta <[email protected]>

"""

from . import JsonObject, JsonList


class User(JsonObject):

FIELDS = {'id': '', 'name': '', 'displayName': '', 'email': '', 'security_provider_type': '', 'roles': None,
'groups': None}

def __init__(self, id='0', name=None, displayName=None, email=None, security_provider_type=None, roles=None,
groups=None):
self.id, self.name, self.displayName, self.email, self.security_provider_type, self.roles, self.groups = \
id, name, displayName, email, security_provider_type, roles, groups


class Users(JsonList):
"""
Represents a collection of :class:User objects. Extends :class:UserList, so it supports the
standard array index and :keyword:`for` semantics.
"""

def __init__(self, initial_list=None):
super(Users, self).__init__(User, initial_list)

def __getitem__(self, i):
"""
:rtype: User
"""
return self.data[i]

def by_name(self, name):
"""
Finds a user by name.

:returns: First user with the correct name
:rtype: User
"""
found = [x for x in self.data if x.name == name]
try:
return found[0]
except IndexError:
raise KeyError(name)

def by_id(self, id):
"""
Finds a user by id.

:returns: First user with the correct id
:rtype: User
"""
found = [x for x in self.data if x.id == id]
try:
return found[0]
except IndexError:
raise KeyError(id)
Loading