Example #1
0
def maintenance_mode_handler():

    # failed to route the request - this is a 404. Abort early.
    if not request.endpoint:
        return

    state = get_maintenance_state()
    if not state:
        return

    if is_bypass_maintenance_mode() and \
            is_user_action_allowed('maintenance_mode_set'):
        return

    if state['status'] == MAINTENANCE_MODE_ACTIVATING:
        if not get_running_executions():
            state = store_maintenance_state(status=MAINTENANCE_MODE_ACTIVATED,
                                            activated_at=datetime.utcnow())
        else:
            # Removing v*/ from the endpoint
            index = request.endpoint.find('/')
            request_endpoint = request.endpoint[index + 1:]
            return _handle_activating_mode(state=state,
                                           request_endpoint=request_endpoint)

    if utils.check_allowed_endpoint(ALLOWED_MAINTENANCE_ENDPOINTS):
        return

    if state['status'] == MAINTENANCE_MODE_ACTIVATED:
        return _maintenance_mode_error()
Example #2
0
 def get(self, pagination=None):
     """List brokers from the database."""
     brokers = get_storage_manager().list(models.RabbitMQBroker)
     if not is_user_action_allowed('broker_credentials'):
         for broker in brokers:
             broker.username = None
             broker.password = None
     return brokers
 def get(self, pagination=None):
     """List brokers from the database."""
     brokers = get_storage_manager().list(models.RabbitMQBroker)
     if not is_user_action_allowed('broker_credentials'):
         for broker in brokers:
             broker.username = None
             broker.password = None
     return brokers
Example #4
0
    def _validate_tenant_name(secret, tenant_map_dict, existing_tenants):
        tenant_name_exists = True
        tenant_name_authorized = True
        tenant_name = secret['tenant_name']
        if tenant_map_dict and (tenant_name in tenant_map_dict):
            tenant_name = tenant_map_dict[tenant_name]
        if tenant_name not in existing_tenants:
            tenant_name_exists = False
        if tenant_name_exists and not authorization.is_user_action_allowed(
                'secret_create', tenant_name):
            tenant_name_authorized = False

        return tenant_name_exists, tenant_name_authorized, tenant_name
Example #5
0
    def _validate_tenant_action(tenant_name, existing_tenants, secret_errors):
        """
        Ensure the tenant exists and that the current user is authorized to
        perform the `secret_create` action
        """

        if tenant_name not in existing_tenants:
            secret_errors['tenant_name'] = 'The tenant `{0}` was not' \
                                           ' found'.format(str(tenant_name))
        elif not is_user_action_allowed('secret_create', tenant_name):
            secret_errors['tenant_name'] =\
                'User `{0}` is not permitted to perform the action ' \
                '`secrets_create` in tenant: ' \
                '`{1}`'.format(current_user.username, str(tenant_name))