'tags': ['setting'], 'description': "Return a setting that match the given ID", 'parameters': [ { 'name': 'id', 'description': 'the id of a setting', 'in': 'path', 'schema': { 'type': 'integer', } } ], 'responses': { '200': { 'description': "The setting that match the ID", 'content': { 'application/json': { 'examples': {} } } } } }) @jwt_required def get(self, id): return SettingsModel.to_json(SettingsModel.by_id(id)) api.add_resource(Settings, '/v1/settings') api.add_resource(Setting, '/v1/setting/<int:id>')
'responses': { '200': { 'description': "The event that match the ID", 'content': { 'application/json': { 'examples': { 'application/json': { "id": 1, "created_at": "2019-11-13T16:08:45.370956", "updated_at": "2019-11-13T16:08:45.370956", "deleted_at": None, "author_id": 0, "domain": "system", "action": "migrated", "entity": "", "args": None } } } } } } }) @jwt_required def get(self, id): return EventsModel.to_json(EventsModel.by_id(id)) api.add_resource(Events, '/v1/events') api.add_resource(Event, '/v1/event/<int:id>')
}, 'userkeys': { 'count': len(userkeys) }, 'hosts': { 'count': len(hosts), 'keys': len(list(set([x.ssh_key_id for x in hosts]))) }, 'hostgroups': { 'count': len(hostgroups) }, 'acls': { 'count': len(acls), 'allow': len([x for x in acls if x.action == 'allow']), }, 'sessions': { 'count': len(sessions), 'active': len([s for s in sessions if s.status != 'closed']), 'errors': len([s for s in sessions if s.err_msg != '']) }, 'events': { 'count': len(events), 'last_5': list(reversed([EventsModel.to_json(x) for x in events[-5:]])) } } api.add_resource(Statistics, '/v1/statistics')
"-----BEGIN RSA PRIVATE KEY-----\n.....\n-----END RSA PRIVATE KEY-----\n", # noqa "pub_key": "ssh-rsa AAAAB3.....NSF", "comment": "deployed by saltstack" } } } } } } } }) @jwt_required def get(self, name): host = HostsModel.by_name(name) hosts_part = HostsModel.to_json(host) host_host_groups = HostHostGroupsModel.by_host_id(host.id) host_group = HostGroupsModel.by_id(host_host_groups.host_group_id) hosts_part['host_groups'] = HostGroupsModel.to_json( host_group) if host_group else None ssh_key = SshKeysModel.by_id(host.ssh_key_id) hosts_part['ssh_key'] = SshKeysModel.to_json(ssh_key) return hosts_part api.add_resource(Hosts, '/v1/hosts') api.add_resource(HostId, '/v1/host/<int:id>') api.add_resource(HostName, '/v1/host/<string:name>')
useruserroles = UserUserRolesModel.by_user_id(current_user.id) for uur in useruserroles: role = UserRolesModel.by_id(uur.user_role_id) user_part['roles'].append(UserRolesModel.to_json(role)) userkeys = UserKeysModel.by_user_id(current_user.id) for uk in userkeys: user_part['keys'].append(UserKeysModel.to_json(uk)) usergroups = UserUserGroupsModel.by_user_id(current_user.id) for ug in usergroups: group = UserGroupsModel.by_id(ug.user_group_id) if group: user_part['groups'].append(UserGroupsModel.to_json(group)) return user_part # # Adding resources: api.add_resource(Registration, '/v1/private/registration') api.add_resource(DevToken, '/v1/private/devtoken') api.add_resource(Login, '/v1/login') api.add_resource(AllUsers, '/v1/users') api.add_resource(User, '/v1/user') api.add_resource(TokenRefresh, '/v1/token') api.add_resource(LogoutAccess, '/v1/logout/access') api.add_resource(LogoutRefresh, '/v1/logout/refresh')
"deleted_at": None, "is_admin": None, "email": "admin@localhost", "comment": "created by sshportal", "invite_token": "1234567899" } } } } } } } }) @jwt_required def get(self, id): session = SessionsModel.by_id(id) sessions_part = SessionsModel.to_json(session) host = HostsModel.by_id(session.host_id) sessions_part['host'] = HostsModel.to_json(host) if host else None user = UserModel.by_id(session.user_id) sessions_part['user'] = UserModel.to_json(user) if user else None return sessions_part api.add_resource(Sessions, '/v1/sessions') api.add_resource(Session, '/v1/session/<int:id>')
"deleted_at": None, "is_admin": None, "email": "admin@localhost", "comment": "created by sshportal", "invite_token": "711pl82xwUJ4CCFw" }] } } } } } }) @jwt_required def get(self, name): userrole = UserRolesModel.by_name(name) userroles_part = UserRolesModel.to_json(userrole) useruserroles = UserUserRolesModel.by_user_role_id(userrole.id) userroles_part['users'] = [] for uur in useruserroles: user = UserModel.by_id(uur.user_id) userroles_part['users'].append(UserModel.to_json(user)) return userroles_part api.add_resource(UserRoles, '/v1/userroles') api.add_resource(UserRoleId, '/v1/userrole/<int:id>') api.add_resource(UserRoleName, '/v1/userrole/<string:name>')
} } } } } }) @jwt_required def get(self, name): host_group = HostGroupsModel.by_name(name) host_groups_part = HostGroupsModel.to_json(host_group) host_group_acls = HostGroupAclsModel.by_host_group_id(host_group.id) host_groups_part['acls'] = [] for hgacls in host_group_acls: acl = AclsModel.by_id(hgacls.acl_id) host_groups_part['acls'].append(AclsModel.to_json(acl)) host_host_groups = HostHostGroupsModel.by_host_group_id(host_group.id) host_groups_part['hosts'] = [] for hhg in host_host_groups: host = HostsModel.by_id(hhg.host_id) host_groups_part['hosts'].append( HostsModel.to_json(host) if host else None) return host_groups_part api.add_resource(HostGroups, '/v1/host_groups') api.add_resource(HostGroupId, '/v1/host_group/<int:id>') api.add_resource(HostGroupName, '/v1/host_group/<string:name>')
"name": "admin", "password": None, "created_at": "2019-11-13T16:08:45.490830", "updated_at": "2019-11-13T16:39:21.114928", "deleted_at": None, "is_admin": None, "email": "admin@localhost", "comment": "created by sshportal", "invite_token": "1234567890" } } } } } } }) @jwt_required def get(self, id): userkey = UserKeysModel.by_id(id) userkeys_part = UserKeysModel.to_json(userkey) user = UserModel.by_id(userkey.user_id) userkeys_part['user'] = UserModel.to_json(user) return userkeys_part api.add_resource(UserKeys, '/v1/userkeys') api.add_resource(UserKey, '/v1/userkey/<int:id>')
} } } } } }) @jwt_required def get(self, name): usergroup = UserGroupsModel.by_name(name) usergroups_part = UserGroupsModel.to_json(usergroup) userusergroups = UserUserGroupsModel.by_user_group_id(usergroup.id) usergroups_part['users'] = [] for uug in userusergroups: user = UserModel.by_id(uug.user_id) usergroups_part['users'].append(UserModel.to_json(user)) usergroupacls = UserGroupAclModel.by_user_group_id(usergroup.id) usergroups_part['acls'] = [] for uga in usergroupacls: acl = AclsModel.by_id(uga.acl_id) usergroups_part['acls'].append(AclsModel.to_json(acl)) return usergroups_part api.add_resource(UserGroups, '/v1/usergroups') api.add_resource(UserGroupId, '/v1/usergroup/<int:id>') api.add_resource(UserGroupName, '/v1/usergroup/<string:name>')
from flask_restful import Resource from sshportal_api import api class Ping(Resource): def get(self): return {"message": "Pong!"} api.add_resource(Ping, '/v1/ping')
"comment": "created by sshportal" } } } } } } } }) @jwt_required def get(self, id): # parser = reqparse.RequestParser() # parser.add_argument('id', help='This field cannot be blank', required=True) # data = parser.parse_args() # acl = AclsModel.by_id(data['id']) acl = AclsModel.by_id(id) acl_part = AclsModel.to_json(acl) host_group_acls = HostGroupAclsModel.by_acl_id(acl.id) host_group = HostGroupsModel.by_id(host_group_acls.host_group_id) acl_part['host_groups'] = HostGroupsModel.to_json(host_group) user_group_acls = UserGroupAclModel.by_acl_id(acl.id) user_group = UserGroupsModel.by_id(user_group_acls.user_group_id) acl_part['user_groups'] = UserGroupsModel.to_json(user_group) return acl_part api.add_resource(Acls, '/v1/acls') api.add_resource(Acl, '/v1/acl/<int:id>')