def update_namespace(namespace: AnyStr, tenant_id: AnyStr) -> int: """ Update the namespace associated with the tenant. :namespace (AnyStr) A string representing the namespace :tenant (AnyStr) A string representing the tenant. Return the number of row affected. """ qry = sa.text(""" INSERT INTO namespaces(namespace, tenant_id) VALUES (:namespace, :tenant_id) ON CONFLICT ON CONSTRAINT namespaces_pkey DO UPDATE SET tenant_id = EXCLUDED.tenant_id, namespace = EXCLUDED.namespace; DELETE FROM namespaces WHERE namespace = :namespace AND tenant_id = 'default' AND EXISTS ( SELECT namespace FROM namespaces WHERE namespace = :namespace AND tenant_id != 'default' ) """) params = {'namespace': namespace, 'tenant_id': tenant_id} return process_query_get_count(qry, params)
def delete_rated_frames(metric: AnyStr) -> int: """ Delete rated frames from the database. :metric (AnyStr) A string representing the metric name Return the number of row deleted """ qry = sa.text(""" DELETE FROM frames WHERE metric = :metric """) params = {'metric': metric} return utils.process_query_get_count(qry, params)
def clear_rated_metrics(metric: AnyStr) -> int: """ Delete a metrics from the frame_status table. :metric (AnyStr) A string representing the metric name Return the number of row updated """ qry = sa.text(""" DELETE FROM frame_status WHERE metric = :metric """) params = {'metric': metric} return utils.process_query_get_count(qry, params)
def delete_tenant(tenant: AnyStr) -> int: """ Remove a tenant from the table. :tenant (AnyStr) A name representing the tenant Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = text(""" DELETE FROM namespaces WHERE tenant_id = :tenant """) params = { 'tenant': tenant } return utils.process_query_get_count(qry, params)
def unlink_namespace(namespace: AnyStr) -> int: """ Remove assignation of a namespace to a tenant. :namespace (AnyStr) A name representing the namespace Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = text(""" UPDATE namespaces SET tenant_id = 'default' WHERE namespace = :namespace """) params = { 'namespace': namespace } return utils.process_query_get_count(qry, params)
def new_tenant(tenant: AnyStr, password: AnyStr) -> int: """ Insert a new tenant in database. :tenant (AnyStr) A string representing the name of the tenant :password (AnyStr) A string to use as password Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = text(""" INSERT INTO users (tenant_id, password) VALUES (:tenant, :password) """) params = { 'tenant': tenant, 'password': password } return utils.process_query_get_count(qry, params)
def insert_group_tenant(tenant: AnyStr, user_group: AnyStr) -> int: """ Insert the tenant group in database. :tenant (AnyStr) A string representing the name of the tenant :admin_user (AnyStr) A string that represents the group of a user (i.e. admin or user) Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = text(""" INSERT INTO group_tenant (tenant_id, user_group) VALUES (:tenant, :user_group) """) params = { 'tenant': tenant, 'user_group': user_group } return utils.process_query_get_count(qry, params)
def link_namespace(tenant: AnyStr, namespace: AnyStr) -> int: """ Assign a namespace to a tenant. :tenant (AnyStr) A name representing the tenant to whom the namespace will be assigned :namespace (AnyStr) A name representing the namespace to assign to the tenant Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = text(""" UPDATE namespaces SET tenant_id = :tenant WHERE namespace = :namespace """) params = { 'tenant': tenant, 'namespace': namespace } return utils.process_query_get_count(qry, params)
def update_tenant(tenant: AnyStr, password: AnyStr) -> int: """ Update a tenant in database. :tenant (AnyStr) A string representing the name of the tenant :password (AnyStr) A string to use as password Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = text(""" UPDATE users SET password = :password WHERE tenant_id = :tenant """) params = { 'tenant': tenant, 'password': password } return utils.process_query_get_count(qry, params)
def update_rated_metrics(metric: AnyStr, report_name: AnyStr, last_insert: AnyStr) -> int: """ Update the frame_status table with new informations. :metric (AnyStr) A string representing the metric to update :report_name (AnyStr) A string representing the report name :last_insert (AnyStr) A time representation of latest update Return the number of row updated, 0 in case of fail, 1 otherwise """ qry = sa.text(""" INSERT INTO frame_status(last_insert, report_name, metric) VALUES (:last_insert, :report_name , :metric) ON CONFLICT (report_name, metric) DO UPDATE SET last_insert = :last_insert """) params = { 'last_insert': last_insert, 'report_name': report_name, 'metric': metric } return utils.process_query_get_count(qry, params)