class AdvancedConfig(object): def __init__(self, base_url, username, password): super(AdvancedConfig, self).__init__() self.client = RESTClient(base_url, username, password) def list(self, sortBy=None, count=None, start=None, filter=None): parameters = DataObject() parameters.add_value_string("sortBy", sortBy) parameters.add_value_string("count", count) parameters.add_value_string("start", start) parameters.add_value_string("filter", filter) response = self.client.get_json(OVERRIDE_CONFIGS, parameters.data) response.success = response.status_code == 200 return response def update(self, id, value=None, sensitive=False): data = DataObject() data.add_value_string("value", value) data.add_value("sensitive", sensitive) endpoint = "%s/%s" % (OVERRIDE_CONFIGS, id) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response
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 FileDownloads(object): def __init__(self, base_url, username, password): super(FileDownloads, self).__init__() self.client = RESTClient(base_url, username, password) def get_file(self, path, file_name): endpoint = ("%s/%s/%s" % (FILE_DOWNLOADS, path, file_name)) response = self.client.get_json(endpoint) 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" % (FILE_DOWNLOADS, 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
class FirstSteps(object): def __init__(self, base_url, username, password): super(FirstSteps, self).__init__() self.client = RESTClient(base_url, username, password) def get_setup_status(self): response = self.client.get_json(SETUP_COMPLETE) response.success = response.status_code == 200 return response def set_setup_complete(self): response = self.client.put_json(SETUP_COMPLETE) response.success = response.status_code == 200 return response def get_sla_status(self): response = self.client.get_json(SERVICE_AGREEMENTS_ACCEPTED) response.success = response.status_code == 200 return response def set_sla_status(self, accept=True): data = DataObject() data.add_value("accepted", accept) response = self.client.put_json(SERVICE_AGREEMENTS_ACCEPTED, data.data) response.success = response.status_code == 200 return response
class DNS(object): def __init__(self, base_url, username, password): super(DNS, self).__init__() self.client = RESTClient(base_url, username, password) def get(self): response = self.client.get_json(NET_DNS) response.success = response.status_code == 200 return response def update(self, auto=True, auto_from_interface=None, primary_server=None, secondary_server=None, tertiary_server=None, search_domains=None): data = DataObject() data.add_value("auto", auto) data.add_value_string("autoFromInterface", auto_from_interface) data.add_value_string("primaryServer", primary_server) data.add_value_string("secondaryServer", secondary_server) data.add_value_string("tertiaryServer", tertiary_server) data.add_value_string("searchDomains", search_domains) response = self.client.put_json(NET_DNS, data.data) response.success = response.status_code == 200 return response
class Attributes(object): def __init__(self, base_url, username, password): super(Attributes, self).__init__() self.client = RESTClient(base_url, username, password) def create_attribute( self, category=None, matcher=None, issuer=None, description=None, name=None, datatype=None, uri=None, storage_session=None, storage_behavior=None, storage_device=None, type_risk=None, type_policy=None): storage_data = DataObject() storage_data.add_value("session", storage_session) storage_data.add_value("behavior", storage_behavior) storage_data.add_value("device", storage_device) type_data = DataObject() type_data.add_value("risk", type_risk) type_data.add_value("policy", type_policy) data = DataObject() data.add_value_string("category", category) data.add_value_string("matcher", matcher) data.add_value_string("issuer", issuer) data.add_value_string("description", description) data.add_value_string("name", name) data.add_value_string("datatype", datatype) data.add_value_string("uri", uri) data.add_value("predefined", False) data.add_value_not_empty("storageDomain", storage_data.data) data.add_value_not_empty("type", type_data.data) response = self.client.post_json(ATTRIBUTES, data.data) response.success = response.status_code == 201 return response def list_attributes( 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(ATTRIBUTES, parameters.data) response.success = response.status_code == 200 return response def list_attribute_matchers(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(ATTRIBUTE_MATCHERS, parameters.data) response.success = response.status_code == 200 return response
class DocumentRoot(object): def __init__(self, base_url, username, password): super(DocumentRoot, self).__init__() self.client = RESTClient(base_url, username, password) def create(self, instance, file_name=None, file_type=None, contents=None): data = DataObject() data.add_value_string("file_name", file_name) data.add_value_string("type", file_type) data.add_value_string("contents", contents) endpoint = APIAC + "/instance/{}/documentation".format(instance) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def rename(self, instance, name=None, new_name=None, file_type=None): data = DataObject() data.add_value_string("new_name", new_name) data.add_value_string("type", file_type) endpoint = APIAC + "/instance/{}/documentation/{}".format( instance, name) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def update(self, instance, name=None, file_type=None, contents=None): data = DataObject() data.add_value_string("contents", contents) data.add_value_string("type", file_type) endpoint = APIAC + "/instance/{}/documentation/{}".format( instance, name) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 200 return response def get(self, instance, name=None): endpoint = APIAC + "/instance/{}/documentation/{}".format( instance, name) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def list(self, instance): endpoint = APIAC + "/instance/{}/documentation".format(instance) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response
class RuntimeComponent(object): def __init__(self, base_url, username, password): super(RuntimeComponent, self).__init__() self.client = RESTClient(base_url, username, password) def configure( self, ps_mode=None, user_registry=None, admin_password=None, ldap_password=None, admin_cert_lifetime=None, ssl_compliance=None, ldap_host=None, ldap_port=None, isam_domain=None, ldap_dn=None, ldap_suffix=None, ldap_ssl_db=None, ldap_ssl_label=None, isam_host=None, isam_port=None): data = DataObject() data.add_value_string("ps_mode", ps_mode) data.add_value_string("user_registry", user_registry) data.add_value_string("admin_cert_lifetime", admin_cert_lifetime) data.add_value_string("ssl_compliance", ssl_compliance) data.add_value_string("admin_pwd", admin_password) data.add_value_string("ldap_pwd", ldap_password) data.add_value_string("ldap_host", ldap_host) data.add_value_string("domain", isam_domain) data.add_value_string("ldap_dn", ldap_dn) data.add_value_string("ldap_suffix", ldap_suffix) if ldap_ssl_db is not None: data.add_value_string("ldap_ssl_db", ldap_ssl_db if ldap_ssl_db.endswith(".kdb") else ldap_ssl_db+".kdb") data.add_value_string("usessl", "on") data.add_value_string("ldap_ssl_label", ldap_ssl_label) data.add_value_string("isam_host", isam_host) data.add_value("ldap_port", ldap_port) data.add_value("isam_port", isam_port) response = self.client.post_json(RUNTIME_COMPONENT, data.data) response.success = response.status_code == 200 return response def get_status(self): """ Query the ISAM API to get the runtime components list. :return: PyISAM Response """ response = self.client.get_json(RUNTIME_COMPONENT) response.success = response.status_code == 200 return response def update_embedded_ldap_password(self, password): data = DataObject() data.add_value_string("password", password) response = self.client.post_json(EMBEDDED_LDAP_PASSWORD, data.data) response.success = response.status_code == 200 return response
class AdminSettings(object): def __init__(self, base_url, username, password): super(AdminSettings, self).__init__() self.client = RESTClient(base_url, username, password) def get(self): response = self.client.get_json(ADMIN_CONFIG) response.success = response.status_code == 200 return response def update(self, old_password=None, new_password=None, confirm_password=None, min_heap_size=None, max_heap_size=None, session_timeout=None, http_port=None, https_port=None, min_threads=None, max_threads=None, max_pool_size=None, lmi_debugging_enabled=None, console_log_level=None, accept_client_certs=None, validate_client_cert_identity=None, exclude_csrf_checking=None, enable_ssl_v3=None): data = DataObject() data.add_value_string("oldPassword", old_password) data.add_value_string("newPassword", new_password) data.add_value_string("confirmPassword", confirm_password) data.add_value_string("consoleLogLevel", console_log_level) data.add_value_string("excludeCsrfChecking", exclude_csrf_checking) data.add_value("minHeapSize", min_heap_size) data.add_value("maxHeapSize", max_heap_size) data.add_value("sessionTimeout", session_timeout) data.add_value("httpPort", http_port) data.add_value("httpsPort", https_port) data.add_value("minThreads", min_threads) data.add_value("maxThreads", max_threads) data.add_value("maxPoolSize", max_pool_size) data.add_value_bool("lmiDebuggingEnabled", lmi_debugging_enabled) data.add_value_bool("acceptClientCerts", accept_client_certs) data.add_value_bool("validateClientCertIdentity", validate_client_cert_identity) data.add_value_bool("enableSSLv3", enable_ssl_v3) response = self.client.put_json(ADMIN_CONFIG, data.data) response.success = response.status_code == 200 return response
class Licensing(object): def __init__(self, base_url, username, password): super(Licensing, self).__init__() self.client = RESTClient(base_url, username, password) def activate_module(self, code): data = DataObject() data.add_value_string("code", code) endpoint = CAPABILITIES + "/v1" response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def get_activated_module(self, id): endpoint = "%s/%s/v1" % (CAPABILITIES, id) response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def get_activated_modules(self): endpoint = CAPABILITIES + "/v1" response = self.client.get_json(endpoint) response.success = response.status_code == 200 return response def import_activation_code(self, file_path): response = Response() try: with open(file_path, 'rb') as code: data = DataObject() data.add_value_string("name", "activation") files = {"filename": code} endpoint = CAPABILITIES + "/v1" 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
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 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 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 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 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 ConfigDb(object): def __init__(self, base_url, username, password): super(ConfigDb, self).__init__() self.client = RESTClient(base_url, username, password) """ setup the CONFIG database. """ def set_db(self, db_type=None, port=None, host=None, secure=True, user=None, passwd=None, db_name=None): data = DataObject() get_response = self.get_db() data.data = get_response.json data.add_value_string("cfgdb_address", host) data.add_value_string("cfgdb_port", port) data.add_value_string("cfgdb_secure", "true" if secure else "false") data.add_value_string("cfgdb_user", user) data.add_value_string("cfgdb_password", passwd) data.add_value_string("cfgdb_db_name", db_name) data.add_value_string("cfgdb_db_type", db_type) endpoint = CONFIG_DB response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 204 return response def get_db(self): endpoint = CONFIG_DB response = self.client.get_json(endpoint) response.success = response.status_code == 200 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 FileDownloads(object): def __init__(self, base_url, username, password): super(FileDownloads, self).__init__() self.client = RESTClient(base_url, username, password) def get(self, file_path, type=None): parameters = DataObject() parameters.add_value_string("type", type) endpoint = ("%s/%s" % (FILE_DOWNLOADS, file_path)) response = Response() if type == "file": response = self.client.get(endpoint, parameters=parameters.data) else: response = self.client.get_json(endpoint, parameters.data) response.success = response.status_code == 200 return response
class Docker(object): def __init__(self, base_url, username, password): super(Docker, self).__init__() self.client = RESTClient(base_url, username, password) def publish(self): endpoint = DOCKER + "/publish" response = self.client.put_json(endpoint) response.success = response.status_code == 201 return response def stop(self): endpoint = DOCKER + '/stop' response = self.client.put_json(endpoint) response.success = response.status_code == 204 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
def _discover_version_and_deployment(self): client = RESTClient(self._base_url, self._username, self._password) response = client.get_json("/core/sys/versions") if response.status_code == 200: self._version = "{0} {1}".format(response.json.get("product_description"), response.json.get("firmware_version")) self._deployment_model = response.json.get("deployment_model") elif response.status_code == 403: raise AuthenticationError("Authentication failed.") else: response = client.get_json("/firmware_settings") if response.status_code == 200: for entry in response.json: if entry.get("active", False): if entry.get("name", "").endswith("_nonproduction_dev"): self._version = DEVELOPMENT_VERSION else: self._version = entry.get("firmware_version") elif response.status_code == 403: raise AuthenticationError("Authentication failed.") if not self._version: raise Exception("Failed to retrieve the ISAM firmware version.")
class HostsFile(object): def __init__(self, base_url, username, password): super(HostsFile, self).__init__() self.client = RESTClient(base_url, username, password) def add_hostname(self, address, hostname=None): data = DataObject() data.add_value_string("name", hostname) endpoint = "%s/%s/hostnames" % (HOST_RECORDS, address) response = self.client.post_json(endpoint, data.data) response.success = response.status_code == 200 return response def create_record(self, address, hostname_list): hostnames = [] for entry in hostname_list: hostnames.append({"name": str(entry)}) data = DataObject() data.add_value_string("addr", address) data.add_value_not_empty("hostnames", hostnames) response = self.client.post_json(HOST_RECORDS, data.data) response.success = response.status_code == 200 return response def get_record(self, address): endpoint = "%s/%s/hostnames" % (HOST_RECORDS, address) response = self.client.get_json(endpoint) 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 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 PolicyAdmin(object): def __init__(self, base_url, username, password): super(PolicyAdmin, self).__init__() self.client = RESTClient(base_url, username, password) def execute(self, admin_id, admin_pwd, commands): data = DataObject() data.add_value_string("admin_id", admin_id) data.add_value_string("admin_pwd", admin_pwd) data.add_value("commands", commands) response = self.client.post_json(PDADMIN, data.data) response.success = response.status_code == 200 return response
class UserRegistry(object): def __init__(self, base_url, username, password): super(UserRegistry, self).__init__() self.client = RESTClient(base_url, username, password) def update_user_password(self, username, password=None): data = DataObject() data.add_value_string("password", password) endpoint = "%s/users/%s/v1" % (USER_REGISTRY, username) response = self.client.put_json(endpoint, data.data) response.success = response.status_code == 204 return response
class ApplicationLog(object): def __init__(self, base_url, username, password): super(ApplicationLog, self).__init__() self.client = RESTClient(base_url, username, password) def get_application_log(self, path): parameters = DataObject() parameters.add_value_string("type", "File") endpoint = "%s/%s" % (APPLICATION_LOGS, path) response = self.client.get_json(endpoint, parameters.data) response.success = response.status_code == 200 return response