class FIDO2Registrations(object): def __init__(self, base_url, username, password): super(FIDO2Registrations, self).__init__() self.client = RESTClient(base_url, username, password) def list_registrations(self, username=None, credential_id=None): endpoint = FIDO2_REGISTRATIONS if username: endpoint = "{}/{}".format(FIDO2_USER_REGISTRATIONS, username) elif credential_id: endpoint = "{}/{}".format(FIDO2_REGISTRATIONS, credential_id) response = self.client.get_json(endpoint) response.success = response.stauts_code == 200 return response def delete_registration_by_user(self, username=None): endpoint = "{}/{}".format(FIDO2_USER_REGISTRATIONS, username) response = self.client.delete_json(endpoint) response.success = response.stauts_code == 200 return response def delete_registration_by_credential_id(self, credential_id=None): endpoint = "{}/{}".format(FIDO2_CRED_ID_REGISTRATIONS, credential_id) response = self.client.delete_json(endpoint) response.success = response.stauts_code == 200 return response
class RSA(object): def __init__(self, base_url, username, password): super(RSA, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, server_config_file=None): response = Response() endpoint = RSA_CONFIG + "/server_config" try: with open(server_config_file, "r") as server_config: files = {"server_config": server_config} response = self.client.post_file(endpoint, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def get(self): response = self.client.get_json(RSA_CONFIG) response.success = response.status_code == 200 return response def test(self, username=None, password=None): endpoint = RSA_CONFIG + "/test" data = DataObject() data.add_value_string("username", username) data.add_value_string("password", password) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 204 return response def delete(self): endpoint = RSA_CONFIG + "/server_config" response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def delete_node_secret(self): endpoint = RSA_CONFIG + "/nose_secret" response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response
class ClientCertMapping(object): def __init__(self, base_url, username, password): super(ClientCertMapping, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, content=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("content", content) response = self.client.post_json(CLIENT_CERT_CDAS, data.data) response.success = response.status_code == 200 return response def update(self, _id=None, content=None): data = DataObject() data.add_value("content", content) data.add_value_string("id", _id) endpoint = CLIENT_CERT_CDAS + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def delete(self, _id=None): endpoint = CLIENT_CERT_CDAS + "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def get(self, _id): endpoint = CLIENT_CERT_CDAS + "/{}".format(_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_template(self, tempalte_id=None): endpoit = "/isam/wga_templates/client_cert_cdas_template" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(CLIENT_CERT_CDAS) response.success = response.status_code == 200 return response
class URLMapping(object): def __init__(self, base_url, username, password): super(URLMapping, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, dynurl_config_data=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("dynurl_config_data", dynurl_config_data) response = self.client.post_json(URL_MAPPING, data.data) response.success = response.status_code == 200 return response def update(self, _id=None, dynurl_config_data=None): data = DataObject() data.add_value("dynurl_config_data", dynurl_config_data) endpoint = URL_MAPPING + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def delete(self, _id=None): endpoint = URL_MAPPING + "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def get(self, _id): endpoint = URL_MAPPING + "/{}".format(_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_template(self): endpoint = "/isam/wga_templates/dynurl_template" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(URL_MAPPING) response.success = response.status_code == 200 return response
class Policies(object): def __init__(self, base_url, username, password): super(Policies, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, groups=[], attributes=[]): data = DataObject() data.add_value_string("name", name) data.add_value_not_empty("group", grups) data.add_value_not_empty("attributes", attributes) response = self.client.post_json(POLICY, data.data) response.success = response.status_code == 200 return response def update(self, name, groups=[], attributes=[]): data = DataObject() data.add_value_not_empty("groups", groups) data.add_value_not_empty("attributes", attributes) endpoint = POLICY + "/{}".format(name) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def get(self, name=None): endpoint = POLICY + "/{}".format(name) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def delete(self, name=None): endpoint = POLICY + "/{}".format(name) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(POLICY) response.success = response.status_code == 200 return response
class ServerConnections9050(ServerConnections): def __init__(self, base_url, username, password): super(ServerConnections, self).__init__() self.client = RESTClient(base_url, username, password) def create_isam_runtime( self, name=None, description=None, locked=None, connection_bind_dn=None, connection_bind_pwd=None, connection_ssl_truststore=None, connection_ssl_auth_key=None, connection_ssl=None, connect_timeout=None, servers=None): connection_data = DataObject() connection_data.add_value_string("bindDN", connection_bind_dn) connection_data.add_value_string("bindPwd", connection_bind_pwd) connection_data.add_value_string( "sslTruststore", connection_ssl_truststore) connection_data.add_value_string("sslAuthKey", connection_ssl_auth_key) connection_data.add_value("ssl", connection_ssl) manager_data = DataObject() manager_data.add_value("connectTimeout", connect_timeout) data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("type", "isamruntime") data.add_value("locked", locked) data.add_value("servers", servers) data.add_value_not_empty("connection", connection_data.data) data.add_value_not_empty("connectionManager", manager_data.data) endpoint = SERVER_CONNECTION_ISAM_RUNTIME + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 return response def get_runtime(self): endpoint = SERVER_CONNECTION_ISAM_RUNTIME + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def delete_runtime(self, uuid): endpoint = "%s/%s/v1" % (SERVER_CONNECTION_ISAM_RUNTIME, uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response
class HTTP_Transform(object): def __init__(self, base_url, username, password): super(HTTP_Transform, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, template=None, contents=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("template", template) data.add_value_string("contents", contents) response = self.client.post_json(HTTP_TRANSFORM, data.data) response.success = response.status_code == 200 return response def update(self, _id, content=None): data = DataObject() data.add_vale_string("content", content) endpoint = HTTP_TRANSFORM + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.stauts_code == 200 return response def delete(self, _id=None): endpoint = HTTP_TRANSFORM + "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return repsonse def get(self, _id=None): endpoint = HTTP_TRANSFORM + "/{}".format(_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(HTTP_TRANSFORM) response.success = response.status_code == 200 return response
class Fixpacks(object): def __init__(self, base_url, username, password): super(Fixpacks, self).__init__() self.client = RESTClient(base_url, username, password) def install_fixpack(self, file_path): response = Response() try: with open(file_path, 'rb') as fixpack: data = DataObject() data.add_value_string("type", "application/octect-stream") files = {"file": fixpack} endpoint = FIXPACKS response = self.client.post_file(endpoint, data=data.data, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def list_fixpacks(self): endpoint = FIXPACKS response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_fips_mode(self): endpoint = FIXPACKS + "/fipsmode" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def rollback_fixpack(self): endpoint = FIXPACKS response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response
class Rate_Limit(object): def __init__(self, base_url, username, password): super(Rate_Limit, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, content=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("content", content) response = self.client.post_json(RATELIMIT, data.data) response.success = response.status_code == 200 return response def update(self, _id=None, content=None): data = DataObject() data.add_value("content", content) endpoint = RATELIMIT + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def delete(self, _id=None): endpoint = RATELIMIT + "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def get(self, _id): endpoint = RATELIMIT + "/{}".format(_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(RATELIMIT) response.success = response.status_code == 200 return response
class AdvancedTuning(object): def __init__(self, base_url, username, password): super(AdvancedTuning, self).__init__() self.client = RESTClient(base_url, username, password) def create_parameter(self, key=None, value=None, comment=None): data = DataObject() data.add_value_string("key", key) data.add_value_string("value", value) data.add_value_string("comment", comment) data.add_value("_isNew", True) response = self.client.post_json(ADVANCED_PARAMETERS, data.data) response.success = response.status_code == 201 return response def update_parameter(self, id=None, key=None, value=None, comment=None): data = DataObject() data.add_value_string("key", key) data.add_value_string("value", value) data.add_value_string("comment", comment) response = self.client.put_json(ADVANCED_PARAMETERS + "/" + id, data.data) response.success = response.status_code == 200 return response def list_parameters(self): response = self.client.get_json(ADVANCED_PARAMETERS) response.success = response.status_code == 200 if response.success: response.json = response.json.get("tuningParameters", []) return response def delete_parameter(self, uuid=None): endpoint = ADVANCED_PARAMETERS + "/{}".format(uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response
class RuntimeParameters(object): def __init__(self, base_url, username, password): super(RuntimeParameters, self).__init__() self.client = RESTClient(base_url, username, password) def update(self, parameter, value=None): data = DataObject() data.add_value("value", value) endpoint = "%s/%s/v1" % (RUNTIME_TUNING, parameter) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def get_runtime_tuning(self): endpoint = "%s/v1" % RUNTIME_TUNING response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def add_listening_interface(self, interface, port, secure=None): data = DataObject() data.add_value("interface", interface) data.add_value("port", port) data.add_value("secure", secure) endpoint = "%s/%s/v1" % (RUNTIME_TUNING, ENDPOINTS) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete_listening_interface(self, interface, port): endpoint = "%s/%s/%s:%d/v1" % (RUNTIME_TUNING, ENDPOINTS, interface, port) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response
class FSSO(object): def __init__(self, base_url, username, password): super(FSSO, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, fsso_config_data=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("fsso_config_data", fsso_config_data) response = self.client.post_json(FSSO_CONFIG, data.data) response.success = response.status_code == 200 return response def update(self, _id=None, fsso_config_data=None): data = DataObject() data.add_value("fsso_config_data", fsso_config_data) endpoint = FSSO_CONFIG + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def delete(self, _id=None): endpoint = FSSO_CONFIG + "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def get(self, _id): endpoint = FSSO_CONFIG + "/{}".format(_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(FSSO_CONFIG) response.success = response.status_code == 200 return response
class Utilities(object): def __init__(self, base_url, username, password): super(Utilities, self).__init__() self.client = RESTClient(base_url, username, password) def store_crednetial(self, admin_id=None, admin_pwd=None, admin_domain=None): data = DataObject() data.add_value_string("admin_id", admin_id) data.add_value_string("admin_pwd", admin_pwd) data.add_value_string("admin_domain", admin_domain) response = self.client.post_json(CREDENTIALS, data.data) response.success = response.status_code == 200 return response def delete_credential(self): response = self.client.delete_json(CREDENTIALS) response.success = response.status_code == 200 return response def get_credential(self): response = self.client.get_json(CREDENTIALS) response.success = response.status_code == 200 return response def list_groups(self): response = self.client.get_json(GROUPS) response.success = response.status_code == 200 return response
class APIProtection(object): def __init__(self, base_url, username, password): super(APIProtection, self).__init__() self.client = RESTClient(base_url, username, password) def create_client( self, name=None, redirect_uri=None, company_name=None, company_url=None, contact_person=None, contact_type=None, email=None, phone=None, other_info=None, definition=None, client_id=None, client_secret=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("redirectUri", redirect_uri) data.add_value_string("companyName", company_name) data.add_value_string("companyUrl", company_url) data.add_value_string("contactPerson", contact_person) data.add_value_string("contactType", contact_type) data.add_value_string("email", email) data.add_value_string("phone", phone) data.add_value_string("otherInfo", other_info) data.add_value_string("definition", definition) data.add_value_string("clientId", client_id) data.add_value_string("clientSecret", client_secret) response = self.client.post_json(CLIENTS, data.data) response.success = response.status_code == 201 return response def update_client( self, id=None, name=None, redirect_uri=None, company_name=None, company_url=None, contact_person=None, contact_type=None, email=None, phone=None, other_info=None, definition=None, client_id=None, client_secret=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("redirectUri", redirect_uri) data.add_value("companyName", company_name) data.add_value_string("companyUrl", company_url) data.add_value_string("contactPerson", contact_person) data.add_value_string("contactType", contact_type) data.add_value_string("email", email) data.add_value_string("phone", phone) data.add_value_string("otherInfo", other_info) data.add_value_string("definition", definition) data.add_value_string("clientId", client_id) data.add_value_string("clientSecret", client_secret) response = self.client.put_json(CLIENTS+"/"+str(id), data.data) response.success = response.status_code == 204 return response def delete_client(self, id): endpoint = "%s/%s" % (CLIENTS, id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_clients(self, sort_by=None, count=None, start=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sort_by) parameters.add_value_string("count", count) parameters.add_value_string("start", start) parameters.add_value_string("filter", filter) response = self.client.get_json(CLIENTS, parameters.data) response.success = response.status_code == 200 return response def create_definition( self, name=None, description=None, tcm_behavior=None, token_char_set=None, access_token_lifetime=None, access_token_length=None, authorization_code_lifetime=None, authorization_code_length=None, refresh_token_length=None, max_authorization_grant_lifetime=None, pin_length=None, enforce_single_use_authorization_grant=None, issue_refresh_token=None, enforce_single_access_token_per_grant=None, enable_multiple_refresh_tokens_for_fault_tolerance=None, pin_policy_enabled=None, grant_types=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("tcmBehavior", tcm_behavior) data.add_value_string("tokenCharSet", token_char_set) data.add_value("accessTokenLifetime", access_token_lifetime) data.add_value("accessTokenLength", access_token_length) data.add_value("authorizationCodeLifetime", authorization_code_lifetime) data.add_value("authorizationCodeLength", authorization_code_length) data.add_value("refreshTokenLength", refresh_token_length) data.add_value( "maxAuthorizationGrantLifetime", max_authorization_grant_lifetime) data.add_value("pinLength", pin_length) data.add_value( "enforceSingleUseAuthorizationGrant", enforce_single_use_authorization_grant) data.add_value("issueRefreshToken", issue_refresh_token) data.add_value( "enforceSingleAccessTokenPerGrant", enforce_single_access_token_per_grant) data.add_value( "enableMultipleRefreshTokensForFaultTolerance", enable_multiple_refresh_tokens_for_fault_tolerance) data.add_value("pinPolicyEnabled", pin_policy_enabled) data.add_value("grantTypes", grant_types) response = self.client.post_json(DEFINITIONS, data.data) response.success = response.status_code == 201 return response def update_definition( self, definition_id=None, name=None, description=None, tcm_behavior=None, token_char_set=None, access_token_lifetime=None, access_token_length=None, authorization_code_lifetime=None, authorization_code_length=None, refresh_token_length=None, max_authorization_grant_lifetime=None, pin_length=None, enforce_single_use_authorization_grant=None, issue_refresh_token=None, enforce_single_access_token_per_grant=None, enable_multiple_refresh_tokens_for_fault_tolerance=None, pin_policy_enabled=None, grant_types=None, oidc_enabled=False, iss=None, poc=None, lifetime=None, alg=None, db=None, cert=None, enc_enabled=False, enc_alg=None, enc_enc=None, access_policy_id=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("tcmBehavior", tcm_behavior) data.add_value_string("tokenCharSet", token_char_set) data.add_value("accessTokenLifetime", access_token_lifetime) data.add_value("accessTokenLength", access_token_length) data.add_value("authorizationCodeLifetime", authorization_code_lifetime) data.add_value("authorizationCodeLength", authorization_code_length) data.add_value("refreshTokenLength", refresh_token_length) data.add_value( "maxAuthorizationGrantLifetime", max_authorization_grant_lifetime) data.add_value("pinLength", pin_length) data.add_value( "enforceSingleUseAuthorizationGrant", enforce_single_use_authorization_grant) data.add_value("issueRefreshToken", issue_refresh_token) data.add_value( "enforceSingleAccessTokenPerGrant", enforce_single_access_token_per_grant) data.add_value( "enableMultipleRefreshTokensForFaultTolerance", enable_multiple_refresh_tokens_for_fault_tolerance) data.add_value("pinPolicyEnabled", pin_policy_enabled) data.add_value("grantTypes", grant_types) data.add_value("accessPolicyId", access_policy_id) if oidc_enabled: oidc = DataObject() oidc.add_value("enabled",True) oidc.add_value("iss",iss) oidc.add_value("poc",poc) oidc.add_value("lifetime",lifetime) oidc.add_value("alg",alg) oidc.add_value("db",db) oidc.add_value("cert",cert) if enc_enabled: enc_data = DataObject() enc_data.add_value("db",enc_db) enc_data.add_value("cert",enc_cert) oidc.add_value("enc",enc_data.data) data.add_value("oidc",oidc.data) response = self.client.put_json(DEFINITIONS+"/"+str(definition_id), data.data) response.success = response.status_code == 204 return response def delete_definition(self, id): endpoint = "%s/%s" % (DEFINITIONS, id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_definitions( self, sort_by=None, count=None, start=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sort_by) parameters.add_value_string("count", count) parameters.add_value_string("start", start) parameters.add_value_string("filter", filter) response = self.client.get_json(DEFINITIONS, parameters.data) response.success = response.status_code == 200 return response def create_mapping_rule( self, name=None, category=None, file_name=None, content=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("category", category) data.add_value_string("fileName", file_name) data.add_value_string("content", content) response = self.client.post_json(MAPPING_RULES, data.data) response.success = response.status_code == 201 return response def list_mapping_rules( self, sort_by=None, count=None, start=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sort_by) parameters.add_value_string("count", count) parameters.add_value_string("start", start) parameters.add_value_string("filter", filter) response = self.client.get_json(MAPPING_RULES, parameters.data) response.success = response.status_code == 200 return response def import_mapping_rule(self, id, file_path): response = Response() try: with open(file_path, 'rb') as mapping_rule: files = {"file": mapping_rule} endpoint = "%s/%s/file" % (MAPPING_RULES, id) accept_type = "%s,%s" % ("application/json", "text/html") response = self.client.post_file( endpoint, accept_type=accept_type, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def update_mapping_rule(self, id, content=None): data = DataObject() data.add_value_string("content", content) endpoint = "%s/%s" % (MAPPING_RULES, id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response
class ServerConnections(object): def __init__(self, base_url, username, password): super(ServerConnections, self).__init__() self.client = RESTClient(base_url, username, password) def create_ldap( self, name=None, description=None, locked=None, connection_host_name=None, connection_bind_dn=None, connection_bind_pwd=None, connection_ssl_truststore=None, connection_ssl_auth_key=None, connection_host_port=None, connection_ssl=None, connect_timeout=None, servers=None): connection_data = DataObject() connection_data.add_value_string("hostName", connection_host_name) connection_data.add_value_string("bindDN", connection_bind_dn) connection_data.add_value_string("bindPwd", connection_bind_pwd) connection_data.add_value_string( "sslTruststore", connection_ssl_truststore) connection_data.add_value_string("sslAuthKey", connection_ssl_auth_key) connection_data.add_value("hostPort", connection_host_port) connection_data.add_value("ssl", connection_ssl) manager_data = DataObject() manager_data.add_value("connectTimeout", connect_timeout) data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("type", "ldap") data.add_value("locked", locked) data.add_value("servers", servers) data.add_value_not_empty("connection", connection_data.data) data.add_value_not_empty("connectionManager", manager_data.data) endpoint = SERVER_CONNECTION_LDAP + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 return response def delete_ldap(self, uuid): endpoint = "%s/%s/v1" % (SERVER_CONNECTION_LDAP, uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_ldap(self): endpoint = SERVER_CONNECTION_LDAP + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_smtp( self, name=None, description=None,connect_timeout=None, connection_host_name=None, connection_host_port=None, connection_ssl=None, connection_user=None, connection_password=None): connection_data = DataObject() connection_data.add_value_string("hostName", connection_host_name) connection_data.add_value("hostPort", connection_host_port) connection_data.add_value("ssl", connection_ssl) connection_data.add_value("user", connection_user) connection_data.add_value("password", connection_password) manager_data = DataObject() manager_data.add_value("connectTimeout", connect_timeout) data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("type", "smtp") data.add_value_not_empty("connection", connection_data.data) data.add_value_not_empty("connectionManager", manager_data.data) endpoint = SERVER_CONNECTION_SMTP + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 return response def delete_smtp(self, uuid): endpoint = "%s/%s/v1" % (SERVER_CONNECTION_SMTP, uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_smtp(self): endpoint = SERVER_CONNECTION_SMTP + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_ci( self, name=None, description=None, locked=None, connection_host_name=None, connection_client_id=None, connection_client_secret=None, connection_ssl_truststore=None): connection_data = DataObject() connection_data.add_value_string("adminHost", connection_host_name) connection_data.add_value("clientId", connection_client_id) connection_data.add_value("clientSecret", connection_client_secret) connection_data.add_value("ssl", True) connection_data.add_value("sslTruststore", connection_ssl_truststore) connection_data.add_value("usersEndpoint", "/v2.0/Users") # yes, I know this is a token endpoint. The parameter name was poorly selected connection_data.add_value("authorizeEndpoint", "/v1.0/endpoint/default/token") connection_data.add_value("authenticatorsEndpoint", "/v1.0/authenticators") connection_data.add_value("authnmethodsEndpoint", "/v1.0/authnmethods") data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("type", "ci") data.add_value_string("locked", locked) data.add_value_not_empty("connection", connection_data.data) endpoint = SERVER_CONNECTION_CI + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 return response def delete_ci(self, uuid): endpoint = "%s/%s/v1" % (SERVER_CONNECTION_CI, uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_ci(self): endpoint = SERVER_CONNECTION_CI + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_web_service( self, name=None, description=None, locked=None, connection_url=None, connection_user=None, connection_password=None, connection_ssl_truststore=None, connection_ssl_auth_key=None, connection_ssl=None): connection_data = DataObject() connection_data.add_value_string("url", connection_url) connection_data.add_value_string("user", connection_user) connection_data.add_value_string("password", connection_password) connection_data.add_value_string( "sslTruststore", connection_ssl_truststore) connection_data.add_value_string("sslAuthKey", connection_ssl_auth_key) connection_data.add_value("ssl", connection_ssl) data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("type", "ws") data.add_value("locked", locked) data.add_value_not_empty("connection", connection_data.data) endpoint = SERVER_CONNECTION_WEB_SERVICE + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 return response def delete_web_service(self, uuid): endpoint = "%s/%s/v1" % (SERVER_CONNECTION_WEB_SERVICE, uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_web_service(self): endpoint = SERVER_CONNECTION_WEB_SERVICE + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_jdbc(self, name=None, description=None, locked=None, database_type=None, connection_jndi=None, connection_host_name=None, connection_port=None, connection_ssl=None, connection_user=None, connection_password=None, connection_type=None, connection_service_name=None, connection_dataabse_name=None, connection_aged_timeout=None, connection_connection_timeout=None, connection_per_thread=None, connection_max_idle=None, connection_max_pool_size=None, connection_min_pool_size=None, connection_per_local_thread=None, connection_purge_policy=None, connection_reap_time=None): data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("locked", locked) data.add_value_string("type", database_type) data.add_value_string("jndiId", connection_jndi) connection_data = DataObject() connection_data.add_value_string("serverName", connection_host_name) connection_data.add_value_string("portNumber", connection_port) connection_data.add_value_string("ssl", connection_ssl) connection_data.add_value_string("user", connection_user) connection_data.add_value_string("password", connection_password) connection_data.add_value_string("type", connection_type) connection_data.add_value_string("serviceName", connection_service_name) connection_data.add_value_string("databaseName", connection_database_name) data.add_value_string("connection", connection_data.data) manager = DataObject() manager.add_value_string("agedTimeout", connection_aged_timeout) manager.add_value_string("connectionTimeout", connection_connection_timeout) manager.add_value_string("maxConnectionsPerThread", connection_per_thread) manager.add_value_string("maxIdleTime", connection_max_idle) manager.add_value_string("maxPoolSize", connection_max_pool_size) manager.add_value_string("minPoolSize", connection_min_pool_size) manager.add_value_string("numConnectionsPerThreadLocal", connection_per_thread_local) manager.add_value_string("purgePolicy", connection_purge_policy) manager.add_value_string("reapTime", connection_reap_time) data.add_value_string("connectionManager", manager.data) endpoint = SERVER_CONNECTION_JDBC + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 return response def delete_jdbc(self, uuid): endpoint = "%s/%s/v1" % (SERVER_CONNECTION_JDBC, uuid) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_jdbc(self): endpoint = SERVER_CONNECTION_JDBC + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list_all(self): endpoint = SERVER_CONNECTION_ROOT + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response
class ReverseProxy(object): def __init__(self, base_url, username, password): super(ReverseProxy, self).__init__() self.client = RESTClient(base_url, username, password) def create_instance(self, inst_name=None, host=None, admin_id=None, admin_pwd=None, ssl_yn=None, key_file=None, cert_label=None, ssl_port=None, http_yn=None, http_port=None, https_yn=None, https_port=None, nw_interface_yn=None, ip_address=None, listening_port=None, domain=None): data = DataObject() data.add_value_string("inst_name", inst_name) data.add_value_string("host", host) data.add_value_string("listening_port", listening_port) data.add_value_string("domain", domain) data.add_value_string("admin_id", admin_id) data.add_value_string("admin_pwd", admin_pwd) data.add_value_string("ssl_yn", ssl_yn) if key_file != None and not key_file.endswith(".kdb"): key_file = key_file + ".kdb" data.add_value_string("key_file", key_file) data.add_value_string("cert_label", cert_label) data.add_value_string("ssl_port", ssl_port) data.add_value_string("http_yn", http_yn) data.add_value_string("http_port", http_port) data.add_value_string("https_yn", https_yn) data.add_value_string("https_port", https_port) data.add_value_string("nw_interface_yn", nw_interface_yn) data.add_value_string("ip_address", ip_address) response = self.client.post_json(REVERSEPROXY, data.data) response.success = response.status_code == 200 return response def delete_instance(self, id, admin_id, admin_pwd): data = DataObject() data.add_value_string("admin_id", admin_id) data.add_value_string("admin_pwd", admin_pwd) data.add_value_string("operation", "unconfigure") endpoint = "%s/%s" % (REVERSEPROXY, id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def list_instances(self): response = self.client.get_json(REVERSEPROXY) response.success = response.status_code == 200 return response def get_wga_defaults(self): response = self.client.get_json(WGA_DEFAULTS) response.success = response.status_code == 200 return response def restart_instance(self, id): data = DataObject() data.add_value_string("operation", "restart") endpoint = "%s/%s" % (REVERSEPROXY, id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def configure_mmfa(self, webseal_id, lmi_hostname=None, lmi_port=None, lmi_username=None, lmi_password=None, runtime_hostname=None, runtime_port=None, runtime_username=None, runtime_password=None, reuse_certs=None, reuse_acls=None, reuse_pops=None): lmi_data = DataObject() lmi_data.add_value_string("hostname", lmi_hostname) lmi_data.add_value_string("username", lmi_username) lmi_data.add_value_string("password", lmi_password) lmi_data.add_value("port", lmi_port) runtime_data = DataObject() runtime_data.add_value_string("hostname", runtime_hostname) runtime_data.add_value_string("username", runtime_username) runtime_data.add_value_string("password", runtime_password) runtime_data.add_value("port", runtime_port) data = DataObject() data.add_value("reuse_certs", reuse_certs) data.add_value("reuse_acls", reuse_acls) data.add_value("reuse_pops", reuse_pops) data.add_value_not_empty("lmi", lmi_data.data) data.add_value_not_empty("runtime", runtime_data.data) endpoint = "%s/%s/mmfa_config" % (REVERSEPROXY, webseal_id) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 204 return response def configure_fed(self, webseal_id, federation_id=None, reuse_certs=False, reuse_acls=False, runtime_hostname=None, runtime_port=None, runtime_username=None, runtime_password=None): data = DataObject() data.add_value_string("federation_id", federation_id) data.add_value("reuse_certs", reuse_certs) data.add_value("reuse_acls", reuse_acls) runtime_data = DataObject() runtime_data.add_value_string("hostname", runtime_hostname) runtime_data.add_value_string("port", runtime_port) runtime_data.add_value_string("username", runtime_username) runtime_data.add_value_string("password", runtime_password) data.add_value_not_empty("runtime", runtime_data.data) endpoint = "%s/%s/fed_config" % (REVERSEPROXY, webseal_id) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 204 return response def configure_aac(self, webseal_id, junction=None, reuse_certs=False, reuse_acls=False, runtime_hostname=None, runtime_port=None, runtime_username=None, runtime_password=None): data = DataObject() data.add_value("reuse_certs", reuse_certs) data.add_value("reuse_acls", reuse_acls) data.add_value("junction", junction) data.add_value_string("hostname", runtime_hostname) data.add_value_string("port", runtime_port) data.add_value_string("username", runtime_username) data.add_value_string("password", runtime_password) endpoint = "%s/%s/authsvc_config" % (REVERSEPROXY, webseal_id) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 204 return response def add_configuration_stanza(self, webseal_id, stanza_id): endpoint = ("%s/%s/configuration/stanza/%s" % (REVERSEPROXY, webseal_id, stanza_id)) response = self.client.post_json(endpoint, data=data) response.success = response.status_code == 200 def delete_configuration_stanza(self, webseal_id, stanza_id): endpoint = ("%s/%s/configuration/stanza/%s" % (REVERSEPROXY, webseal_id, stanza_id)) response = self.client.delete_json(endpoint, data=data) response.success = response.status_code == 200 def add_configuration_stanza_entry(self, webseal_id, stanza_id, entry_name, value): data = {"entries": [[str(entry_name), str(value)]]} endpoint = ("%s/%s/configuration/stanza/%s/entry_name" % (REVERSEPROXY, webseal_id, stanza_id)) response = self.client.post_json(endpoint, data=data) response.success = response.status_code == 200 return response def delete_configuration_stanza_entry(self, webseal_id, stanza_id, entry_name, value=None): endpoint = ("%s/%s/configuration/stanza/%s/entry_name/%s" % (REVERSEPROXY, webseal_id, stanza_id, entry_name)) if value: endpoint = "%s/value/%s" % (endpoint, value) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def get_configuration_stanza_entry(self, webseal_id, stanza_id, entry_name): endpoint = ("%s/%s/configuration/stanza/%s/entry_name/%s" % (REVERSEPROXY, webseal_id, stanza_id, entry_name)) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def update_configuration_stanza_entry(self, webseal_id, stanza_id, entry_name, value): data = DataObject() data.add_value_string("value", value) endpoint = ("%s/%s/configuration/stanza/%s/entry_name/%s" % (REVERSEPROXY, webseal_id, stanza_id, entry_name)) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def create_junction(self, webseal_id, server_hostname=None, junction_point=None, junction_type=None, description=None, basic_auth_mode=None, tfim_sso=None, stateful_junction=None, preserve_cookie=None, cookie_include_path=None, transparent_path_junction=None, mutual_auth=None, insert_ltpa_cookies=None, insert_session_cookies=None, request_encoding=None, enable_basic_auth=None, key_label=None, gso_resource_group=None, junction_cookie_javascript_block=None, client_ip_http=None, version_two_cookies=None, ltpa_keyfile=None, authz_rules=None, fsso_config_file=None, username=None, password=None, server_uuid=None, virtual_hostname=None, server_dn=None, local_ip=None, query_contents=None, case_sensitive_url=None, windows_style_url=None, ltpa_keyfile_password=None, proxy_hostname=None, sms_environment=None, vhost_label=None, force=None, delegation_support=None, scripting_support=None, junction_hard_limit=None, junction_soft_limit=None, server_port=None, https_port=None, http_port=None, proxy_port=None, remote_http_header=None): data = DataObject() data.add_value_string("server_hostname", server_hostname) data.add_value_string("junction_point", junction_point) data.add_value_string("junction_type", junction_type) data.add_value_string("description", description) data.add_value_string("basic_auth_mode", basic_auth_mode) data.add_value_string("tfim_sso", tfim_sso) data.add_value_string("stateful_junction", stateful_junction) data.add_value_string("preserve_cookie", preserve_cookie) data.add_value_string("cookie_include_path", cookie_include_path) data.add_value_string("transparent_path_junction", transparent_path_junction) data.add_value_string("mutual_auth", mutual_auth) data.add_value_string("insert_ltpa_cookies", insert_ltpa_cookies) data.add_value_string("insert_session_cookies", insert_session_cookies) data.add_value_string("request_encoding", request_encoding) data.add_value_string("enable_basic_auth", enable_basic_auth) data.add_value_string("key_label", key_label) data.add_value_string("gso_resource_group", gso_resource_group) data.add_value_string("junction_cookie_javascript_block", junction_cookie_javascript_block) data.add_value_string("client_ip_http", client_ip_http) data.add_value_string("version_two_cookies", version_two_cookies) data.add_value_string("ltpa_keyfile", ltpa_keyfile) data.add_value_string("authz_rules", authz_rules) data.add_value_string("fsso_config_file", fsso_config_file) data.add_value_string("username", username) data.add_value_string("password", password) data.add_value_string("server_uuid", server_uuid) data.add_value_string("virtual_hostname", virtual_hostname) data.add_value_string("server_dn", server_dn) data.add_value_string("local_ip", local_ip) data.add_value_string("query_contents", query_contents) data.add_value_string("case_sensitive_url", case_sensitive_url) data.add_value_string("windows_style_url", windows_style_url) data.add_value_string("ltpa_keyfile_password", ltpa_keyfile_password) data.add_value_string("proxy_hostname", proxy_hostname) data.add_value_string("sms_environment", sms_environment) data.add_value_string("vhost_label", vhost_label) data.add_value_string("force", force) data.add_value_string("delegation_support", delegation_support) data.add_value_string("scripting_support", scripting_support) data.add_value("junction_hard_limit", junction_hard_limit) data.add_value("junction_soft_limit", junction_soft_limit) data.add_value("server_port", server_port) data.add_value("https_port", https_port) data.add_value("http_port", http_port) data.add_value("proxy_port", proxy_port) data.add_value("remote_http_header", remote_http_header) endpoint = "%s/%s/junctions" % (REVERSEPROXY, str(webseal_id)) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete_junction(self, webseal_id, junction_point): query = urllib.parse.urlencode({JUNCTIONS_QUERY: junction_point}) endpoint = "%s/%s/junctions?%s" % (REVERSEPROXY, webseal_id, query) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def list_junctions(self, webseal_id): endpoint = "%s/%s/junctions" % (REVERSEPROXY, webseal_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def import_management_root_files(self, webseal_id, file_path): response = Response() endpoint = ("%s/%s/management_root" % (REVERSEPROXY, webseal_id)) try: with open(file_path, 'rb') as pages: files = {"file": pages} response = self.client.post_file(endpoint, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def update_management_root_file(self, webseal_id, page_id, contents): data = DataObject() data.add_value_string("type", "file") data.add_value_string("contents", contents) endpoint = ("%s/%s/management_root/%s" % (REVERSEPROXY, webseal_id, page_id)) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response # Upload a single file (eg HTML or ico), rather than a zip. def import_management_root_file(self, webseal_id, page_id, file_path): response = Response() endpoint = ("%s/%s/management_root/%s" % (REVERSEPROXY, webseal_id, page_id)) try: with open(file_path, 'rb') as contents: files = {"file": contents} response = self.client.post_file(endpoint, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def import_junction_mapping_file(self, file_path): response = Response() try: with open(file_path, 'rb') as contents: jmt_config_file = {"jmt_config_file": contents} response = self.client.post_file(JMT_CONFIG, files=jmt_config_file) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def update_junction_mapping_file(self, file_id, jmt_config_data): data = DataObject() data.add_value_string("id", file_id) data.add_value_string("jmt_config_data", jmt_config_data) endpoint = ("%s/%s" % (JMT_CONFIG, file_id)) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response
class ManagementAuthorization(object): def __init__(self, base_url, username, password): super(ManagementAuthorization, self).__init__() self.client = RESTClient(base_url, username, password) def enable(self, enforce=False): data = DataObject() data.add_value_boolean("enforcing", enforce) endpoint = MANAGEMENT_AUTHORIZATION + '/config/v1' response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def update(self, enforce_config=False, roles=[]): auth_config = DataObject() auth_config.add_value_boolean("enforcing", enforce_config) auth_roles = DataObject() auth_roles.add_value_not_empty("roles", roles) data = DataObject() data.add_value("config", auth_config.data) data.add_value_not_empty("roles", auth_roles.data) endpoint = MANAGEMENT_AUTHORIZATION + '/v1' response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def get(self): endpoint = MANAGEMENT_AUTHORIZATION + '/v1' response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_role(self, name=None, users=None, groups=None, features=None): data = DataObject() data.add_value_string("name", name) data.add_value_not_empty("users", users) data.add_value_not_empty("grpups", groups) data.add_value_not_empty("features", features) endpoint = MANAGEMENT_AUTHORIZATION_ROLES + '/v1' response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def update_role(self, name=None, users=None, groups=None, features=None): data = DataObject() data.add_value_string("name", name) data.add_value_not_empty("users", users) data.add_value_not_empty("grpups", groups) data.add_value_not_empty("features", features) endpoint = MANAGEMENT_AUTHORIZATION_ROLES + '/{}/v1'.format(name) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete_role(self, role=None): endpoint = MANAGEMENT_AUTHORIZATION_ROLES "/{}/v1".format(role) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def get_role(self, role=None): endpoint = MANAGEMENT_AUTHORIZATION_ROLES "/{}/v1".format(role) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_roles(self): endpoint = MANAGEMENT_AUTHORIZATION_ROLES + '/v1' response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_features(self): endpoint = MANAGEMENT_AUTHORIZATION_FEATURES + '/v1' response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_features_for_user(self, user=None): endpoint = MANAGEMENT_AUTHORIZATION_FEATURES + '/users/{}/v1'.format(user) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_groups_for_role(self, role=None): endpoint = MANAGEMENT_AUTHORIZATION_ROLES + '/{}/groups/v1'.format(role) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_users_for_role(self, role=None): endpoint = MANAGEMENT_AUTHORIZATION_ROLES + '/{}/users/v1' response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response
class CORS(object): def __init__(self, base_url, username, password): super(CORS, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, name=None, allowed_origins=[], allow_credentials=None, exposed_headers=[], handle_preflight=None, allowed_methods=[], allowed_headers=[], max_age=None): data = DataObject() data.add_value_string("name", name) data.add_value_not_empty("allowed_origins", allowed_origins) data.add_value_boolean("allow_credentials", allow_credentials) data.add_value_not_empty("exposed_headers", exposed_headers) data.add_value_boolean("handle_preflight", handle_preflight) data.add_value_not_empty("alowed_methods", allowed_methods) data.add_value_not_empty("alowed_headers", allowed_headers) data.add_value("max_age", max_age) response = self.client.put_json(CORS_POLICY, data.data) response.success = response.status_code == 200 return response def update(self, name, allowed_origins=[], allow_credentials=None, exposed_headers=[], handle_preflight=None, allowed_methods=[], allowed_headers=[], max_age=None): data = DataObject() data.add_value_not_empty("allowed_origins", allowed_origins) data.add_value_boolean("allow_credentials", allow_credentials) data.add_value_not_empty("exposed_headers", exposed_headers) data.add_value_boolean("handle_preflight", handle_preflight) data.add_value_not_empty("alowed_methods", allowed_methods) data.add_value_not_empty("alowed_headers", allowed_headers) data.add_value("max_age", max_age) endpoint = CORS_POLICY + "/{}".format(name) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete(self, name=None): endpoint = CORS_POLICY + "/{}".format(name) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def get(self, name=None): endpoint = CORS_POLICY + "/{}".format(name) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self): response = self.client.get_json(CORS_POLICY) response.success = response.status_code == 200 return response
class SysAccount(object): def __init__(self, base_url, username, password): super(SysAccount, self).__init__() self.client = RESTClient(base_url, username, password) def get_users(self): endpoint = SYSACCOUNT_USERS + '/v1' response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_user(self, user): endpoint = SYSACCOUNT_USERS + '/' + user + '/v1' rsponse = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def update_user(self, user, password=None): data = DataObject() data.add_value_string('password', password) endpoint = SYSACCOUNT_USERS + '/' + user + '/v1' response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def create_user(self, user=None, password=None, groups=[]): data = DataObject() data.add_value_string('id', user) data.add_value_string('password', password) if groups: groups_data = DataObject() for group in groups: groups_data.add_value('id', group) data.add_value_not_empty('groups', groups_data.data) endpoint = SYSACCOUNT_USERS + '/v1' response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete_user(self, user): endpoint = SYSACCOUNT_USERS + '/' + user + '/v1' response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def get_groups(self): endpoint = SYSACCOUNT_GROUPS + '/v1' response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_group(self, group=None): endpoint = SYSACCOUNT_GROUPS + '/groups/{}/v1'.format(group) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def add_user(self, group=None, user=None): data = DataObject() data.add_alue_string("id", group) endpoint = SYSACCOUNT_GROUPS + '/{}/groups/v1'.format(user) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def remove_user(self, group=None, user=None): endpoint = SYSACCOUNT_GROUPS + '/users/{}/groups/{}/v1'.format(user, group) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def create_group(self, group=None): data = DataObject() data.add_value_string("id", group) endpoint = SYSACCOUNT_GROUPS +'/v1' response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete_group(self, group=None): endpoint = SYSACCOUNT_GROUPS + '/{}/v1'.format(group) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def update_admin_password(self, old_password=None, password=None): endpoint = SYSACCOUNT_GROUPS + '/self/v1' data = DataObject() data.add_value_string('old_password', old_password) data.add_value_string('password', password) response.self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response
class Kerberos(object): def __init__(self, base_url, username, password): super(Kerberos, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, _id=None, subsection=None, name=None, value=None): data = DataObject() data.add_value_not_empty("name", name) data.add_value_not_empty("subsection", subsection) data.add_value_string("value", value) endpoint = KERBEROS_CONFIG + "/{}".format(_id) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def update(self, _id=None, value=None): data = DataObject() data.add_value_string("value", value) endpoint = KERBEROS_CONFIG + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.stauts_code == 200 return response def get(self, _id=None): endpoint = KERBEROS_CONFIG + "/{}".format(_id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def delete(self, _id=None): endpoint = KERBEROS_CONFIG = "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def test(self, username=None, password=None): data = DataObject() data.add_value_string("username", username) data.add_value_string("password", password) endpoint = "/wga/kerberos/test" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def import_keytab(self, keytab_file=None): response = Response() try: with open(file_path, 'rb') as contents: files = {"keytab_file": contents} response = self.client.post_file(KERBEROS_KEYTAB, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def delete_keytab(self, _id=None): endpoint = KERBEROS_KEYTAB + "/{}".format(_id) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def combine_keytab(self, new_name=None, keytab_files=[]): data = DataObject() data.add_value_string("new_name", new_name) data.add_value_not_empty("keytab_files", keytab_files) response = self.client.put_json(KERBEROS_KEYTAB, data.data) response.success = response.status_code == 200 return response def list_keytab(self): response = self.client.get_json(KERBEROS_KEYTAB) response.success = response.status_code == 200 return response def verify_keytab(self, _id=None, name=None): data = DataObject() data.add_value_string("name", name) endpoint = KERBEROS_KEYTAB + "/{}".format(_id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response
class FIDO2Config(object): def __init__(self, base_url, username, password): super(FIDO2Config, self).__init__() self.client = RESTClient(base_url, username, password) def list_relying_parties(self): response = self.client.get_json(FIDO2_RELYING_PARTIES) response.success = response.status_code == 200 return response def get_relying_parties(self, _id): endpoint = "{}/{}".format(FIDO2_RELYING_PARTIES, _id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_relying_party( self, name=None, rp_id=None, origins=None, metadata_set=None, metadata_soft_fail=True, mediator_mapping_rule_id=None, attestation_statement_types=None, attestation_statement_formats=None, attestation_public_key_algorithms=None, attestation_android_safetynet_max_age=None, attestation_android_safetynet_clock_skew=None, relying_party_impersonation_group="adminGroup"): data = DataObject() data.add_value("name", name) data.add_value("rpId", rp_id) fidoServerOptions = DataObject() fidoServerOptions.add_value_not_empty("origins", origins) fidoServerOptions.add_value("metadataSet", metadata_set) fidoServerOptions.add_value("metadataSoftFail", metadata_soft_fail) fidoServerOptions.add_value("mediatorMappingRuleId", mediator_mapping_rule_id) attestation = DataObject() attestation.add_value("statementTypes", attestation_statement_types) attestation.add_value("statementFormats", attestation_statement_formats) attestation.add_value("publicKeyAlgorithms", attestation_public_key_algorithms) fidoServerOptions.add_value("attestation", attestation.data) attestationAndroidSafetyNetOptions = DataObject() attestationAndroidSafetyNetOptions.add_value("attestationMaxAge", attestation_android_safetynet_max_age) attestationAndroidSafetyNetOptions.add_value("clockSkew", attestation_android_safetynet_clock_skew) fidoServerOptions.add_value("android-safetynet", attestationAndroidSafetyNetOptions.data) data.add_value("fidoServerOptions", fidoServerOptions.data) relyingPartyOptions = DataObject() relyingPartyOptions.add_value("impersonationGroup", relying_party_impersonation_group) data.add_value("relyingPartyOptions", relyingPartyOptions.data) response = self.client.post_json(FIDO2_RELYING_PARTIES, data.data) response.success = response.status_code == 201 return response def update_relying_party( self, id, name=None, rp_id=None, origins=None, metadata_set=None, metadata_soft_fail=True, mediator_mapping_rule_id=None, attestation_statement_types=None, attestation_statement_formats=None, attestation_public_key_algorithms=None, attestation_android_safety_net_max_age=None, attestation_android_safetynet_clock_skew=None, relying_party_impersonation_group="adminGroup"): data = DataObject() data.add_value("id", id) data.add_value("name", name) data.add_value("rpId", rp_id) fidoServerOptions = DataObject() fidoServerOptions.add_value_not_empty("origins", origins) fidoServerOptions.add_value("metadataSet", metadata_set) fidoServerOptions.add_value("metadataSoftFail", metadata_soft_fail) fidoServerOptions.add_value("mediatorMappingRuleId", mediator_mapping_rule_id) attestation = DataObject() attestation.add_value("statementTypes", attestation_statement_types) attestation.add_value("statementFormats", attestation_statement_formats) attestation.add_value("publicKeyAlgorithms", attestation_public_key_algorithms) attestation.add_value("publicKeyAlgorithms", attestation_public_key_algorithms) fidoServerOptions.add_value("attestation", attestation.data) attestationAndroidSafetyNetOptions = DataObject() attestationAndroidSafetyNetOptions.add_value("attestationMaxAge", attestation_android_safetynet_max_age) attestationAndroidSafetyNetOptions.add_value("clockSkew", attestation_android_safetynet_clock_skew) fidoServerOptions.add_value("android-safetynet", attestationAndroidSafetyNetOptions.data) data.add_value("fidoServerOptions", fidoServerOptions.data) relyingPartyOptions = DataObject() relyingPartyOptions.add_value("impersonationGroup", relying_party_impersonation_group) data.add_value("relyingPartyOptions", relyingPartyOptions.data) endpoint = "%s/%s" % (FIDO2_RELYING_PARTIES, id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def list_metadata(self): endpoint = FIDO2_METADATA response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_metadata(self, _id): endpoint = "{}/{}".format(FIDO2_METADATA, _id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def create_metadata(self, filename=None): response = Response() try: with open(filename, 'rb') as content: data = DataObject() data.add_value_string("filename", ntpath.basename(filename)) data.add_value_string("contents", content.read().decode('utf-8')) endpoint = FIDO2_METADATA response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 201 except IOError as e: logger.error(e) response.success = False return response def update_metadata(self, id, filename=None): response = Response() try: with open(filename, 'rb') as content: files = {"file": content} endpoint = ("%s/%s/file" % (FIDO2_METADATA, id)) response = self.client.post_file(endpoint, accept_type="application/json,text/html,application/*", files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def delete_metadata(self, id): endpoint = ("%s/%s/file" % (FIDO2_METADATA, id)) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 def create_mediator(self, name=None, filename=None): response = Response() try: with open(filename, 'rb') as content: data = DataObject() data.add_value_string("filename", ntpath.basename(filename)) data.add_value_string("content", content.read().decode('utf-8')) data.add_value_string("type", "FIDO2") data.add_value_string("name", name) response = self.client.post_json(FIDO2_MEDIATOR, data.data) response.success = response.status_code == 201 except IOError as e: logger.error(e) response.success = False return response def _update_mediator(self, id, filename=None): response = Response() try: with open(filename, 'rb') as content: data = DataObject() data.add_value_string("content", content.read().decode('utf-8')) endpoint = ("%s/%s" % (FIDO2_MEDIATOR, id)) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 except IOError as e: logger.error(e) response.success = False return response def get_mediator(self, id): endpoint = ("%s/%s" % (FIDO2_MEDIATOR, id)) response = self.get_json(endpoint) response.success = response.status_code == 200 return response def list_mediator(self): response = self.client.get_json(FIDO2_MEDIATOR) rsponse.success = response.status_code == 200 return response def delete_mediator(self, id): endpoint = ("%s/%s" % (FIDO2_MEDIATOR, id)) response = self.delete_json(endpoint) response.success = response.status_code == 204 return response
class DSCAdmin(object): def __init__(self, base_url, username, password): super(DSCAdmin, self).__init__() self.client = RESTClient(base_url, username, password) def list_replica_sets(self): """ List the replica sets in the DSC server. """ response = self.client.get_json(DSC_ADMIN_REPLICAS) response.success = response.status_code == 200 return response def list_servers(self, replica_set): """ List the servers (WebSEALs) for a replica set. """ replica_set = urllib.quote(replica_set, safe='') endpoint = "%s/%s/servers" % (DSC_ADMIN_REPLICAS, replica_set) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list_user_sessions(self, replica_set, user_name_pattern, max_results): """ List user sessions in a replica set. """ parameters = DataObject() parameters.add_value_string("user", user_name_pattern) parameters.add_value_string("max", max_results) replica_set = urllib.parse.quote(replica_set, safe='') endpoint = "%s/%s/sessions" % (DSC_ADMIN_REPLICAS, replica_set) response = self.client.get_json(endpoint, parameters.data) response.success = response.status_code == 200 return response def terminate_session(self, replica_set, session): """ Terminate a specific session. """ replica_set = urllib.parse.quote(replica_set, safe='') session = urllib.parse.quote(session, safe='') endpoint = "%s/%s/sessions/session/%s" % (DSC_ADMIN_REPLICAS, replica_set, session) response = self.client.delete_json(endpoint) response.success = (response.status_code == 200 or response.status_code == 204) return response def terminate_user_sessions(self, replica_set, user_name): """ Terminate all sessions for the specified user. """ replica_set = urllib.parse.quote(replica_set, safe='') user_name = urllib.parse.quote(user_name, safe='') endpoint = "%s/%s/sessions/user/%s" % (DSC_ADMIN_REPLICAS, replica_set, user_name) response = self.client.delete_json(endpoint) response.success = (response.status_code == 200 or response.status_code == 204) return response
class TemplateFiles(object): def __init__(self, base_url, username, password): super(TemplateFiles, self).__init__() self.client = RESTClient(base_url, username, password) def create_directory(self, path, dir_name=None): data = DataObject() data.add_value_string("dir_name", dir_name) data.add_value_string("type", "dir") endpoint = "%s/%s" % (TEMPLATE_FILES, path) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def get_directory(self, path, recursive=None): parameters = DataObject() parameters.add_value("recursive", recursive) endpoint = "%s/%s" % (TEMPLATE_FILES, path) response = self.client.get_json(endpoint, parameters.data) response.success == response.status_code == 200 if response.success and isinstance(response.json, dict): response.json = response.json.get("contents", []) return response def create_file(self, path, file_name=None, contents=None): data = DataObject() data.add_value_string("file_name", file_name) data.add_value_string("contents", contents) data.add_value_string("type", "file") endpoint = "%s/%s" % (TEMPLATE_FILES, path) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def delete_file(self, path, file_name): endpoint = ("%s/%s/%s" % (TEMPLATE_FILES, path, file_name)) response = self.client.delete_json(endpoint) response.success = response.status_code == 200 return response def get_file(self, path, file_name): endpoint = ("%s/%s/%s" % (TEMPLATE_FILES, path, file_name)) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def import_file(self, path, file_name, file_path): response = Response() try: with open(file_path, 'rb') as template: files = {"file": template} endpoint = ("%s/%s/%s" % (TEMPLATE_FILES, path, file_name)) response = self.client.post_file(endpoint, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def import_files(self, file_path, force=True): response = Response() try: with open(file_path, 'rb') as templates: files = {"file": templates} data = DataObject() data.add_value("force", force) response = self.client.post_file(TEMPLATE_FILES, data=data.data, files=files) response.success = response.status_code == 200 except IOError as e: logger.error(e) response.success = False return response def update_file(self, path, file_name, contents=None, force=False): data = DataObject() data.add_value_string("contents", contents) data.add_value_string("force", force) data.add_value_string("type", "file") endpoint = ("%s/%s/%s" % (TEMPLATE_FILES, path, file_name)) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response
class AccessControl(object): def __init__(self, base_url, username, password): super(AccessControl, self).__init__() self.client = RESTClient(base_url, username, password) def create_policy(self, name=None, description=None, dialect="urn:oasis:names:tc:xacml:2.0:policy:schema:os", policy=None, attributes_required=False): data = DataObject() data.add_value_string("name", name) data.add_value_string("description", description) data.add_value_string("dialect", dialect) data.add_value_string("policy", policy) data.add_value("attributesrequired", attributes_required) data.add_value("predefined", False) response = self.client.post_json(POLICIES, data.data) response.success = response.status_code == 201 return response def delete_policy(self, id=None): endpoint = "%s/%s" % (POLICIES, id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_policies(self, sort_by=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sort_by) parameters.add_value_string("filter", filter) response = self.client.get_json(POLICIES, parameters.data) response.success = response.status_code == 200 return response def authenticate_security_access_manager(self, username=None, password=None, domain=None): data = DataObject() data.add_value_string("username", username) data.add_value_string("password", password) data.add_value_string("domain", domain) data.add_value_string("command", "setCredential") response = self.client.post_json(POLICY_ATTACHMENTS_PDADMIN, data.data) response.success = response.status_code == 200 return response def configure_resource(self, server=None, resource_uri=None, policy_combining_algorithm=None, policies=None): data = DataObject() data.add_value_string("server", server) data.add_value_string("resourceUri", resource_uri) data.add_value_string("policyCombiningAlgorithm", policy_combining_algorithm) data.add_value("policies", policies) response = self.client.post_json(POLICY_ATTACHMENTS, data.data) response.success = response.status_code == 201 return response def remove_resource(self, id): endpoint = "%s/%s" % (POLICY_ATTACHMENTS, id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response def list_resources(self, sort_by=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sort_by) parameters.add_value_string("filter", filter) response = self.client.get_json(POLICY_ATTACHMENTS, parameters.data) response.success = response.status_code == 200 return response def publish_policy_attachment(self, id): endpoint = "%s/deployment/%s" % (POLICY_ATTACHMENTS, id) response = self.client.put_json(endpoint) response.success = response.status_code == 204 return response def publish_multiple_policy_attachments(self, *ids): id_string = "" for id in ids: if len(id_string) > 0: id_string += ", " id_string += str(id) data = DataObject() data.add_value_string("policyAttachmentIds", id_string) endpoint = "%s/deployment" % POLICY_ATTACHMENTS response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response def list_obligations(self, sort_by=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sort_by) parameters.add_value_string("filter", filter) response = self.client.get_json(OBLIGATIONS, parameters.data) response.success = response.status_code == 200 return response def create_obligation(self, name=None, predefined=False, description=None, obligationURI=None, type=None, parameters=None, typeId=None, properties=None): data = DataObject() data.add_value_string("name", name) data.add_value("predefined", predefined) data.add_value_string("description", description) data.add_value_string("obligationURI", obligationURI) data.add_value_string("type", type) data.add_value("parameters", parameters) data.add_value_string("typeId", typeId) data.add_value("properties", properties) response = self.client.post_json(OBLIGATIONS, data.data) response.success = response.status_code == 201 return response def delete_obligation(self, id): endpoint = "%s/%s" % (OBLIGATIONS, id) response = self.client.delete_json(endpoint) response.success = response.status_code == 204 return response
class Configuration(object): def __init__(self, base_url, username, password): super(Configuration, self).__init__() self.client = RESTClient(base_url, username, password) self._base_url = base_url self._username = username self._password = password def deploy_pending_changes(self): response = self.get_pending_changes() if response.success: if response.json.get("changes", []): response = self._deploy_pending_changes() else: logger.info("No pending changes to be deployed.") return response def revert_pending_changes(self): response = self.client.delete_json(PENDING_CHANGES) response.success = response.status_code == 200 return response def get_pending_changes(self): response = self.client.get_json(PENDING_CHANGES) response.success = response.status_code == 200 return response def _deploy_pending_changes(self): response = self.client.get_json(PENDING_CHANGES_DEPLOY) response.success = (response.status_code == 200 and response.json.get("result", -1) == 0) if response.success: status = response.json.get("status") if status == 0: logger.info("Successful operation. No further action needed.") else: if (status & 1) != 0: logger.error( "Deployment of changes resulted in good result but failure status: %i", status) response.success = False if (status & 2) != 0: logger.error("Appliance restart required - halting: %i", status) response.success = False if (status & 4) != 0 or (status & 8) != 0: logger.info("Restarting LMI as required for status: %i", status) self._restart_lmi() if (status & 16) != 0: logger.info( "Deployment of changes indicates a server needs restarting: %i", status) if (status & 32) != 0: logger.info("Runtime restart was performed for status: %i", status) self._restart_runtime() return response def _restart_lmi(self): restart_shutdown = RestartShutdown(self._base_url, self._username, self._password) restart_shutdown.restart_lmi() def _restart_runtime(self): restart_shutdown = RestartShutdown(self._base_url, self._username, self._password) restart_shutdown.restart_runtime()