def url_base():
    """Allow test functions to get the url base
    of the application REST API
    """
    from rbac.common.config import get_config

    return get_config("REST_ENDPOINT")
Exemple #2
0
def main():
    """Start the initial sync and two delta threads."""
    tenant_id = get_config("TENANT_ID")
    if not tenant_id:
        LOGGER.warning("No Azure provider configured, exiting...")
        return

    initialize_aad_sync()
    # Create sync listener threads.
    inbound_sync_thread = DeltaSyncThread("Azure Inbound", inbound_sync_listener)
    outbound_sync_thread = DeltaSyncThread("Azure Outbound", outbound_sync_listener)
    # Start sync listener threads.
    inbound_sync_thread.start()
    outbound_sync_thread.start()
def main():
    """Start the initial sync and outbound delta thread."""
    ldap_server = get_config("LDAP_SERVER")
    if not ldap_server:
        LOGGER.warning("No LDAP provider configured, exiting...")
        return

    # wait 5 seconds before starting, to provide time for dependent services to start up
    time.sleep(5)
    initialize_ldap_sync()
    # Create sync listener threads.
    outbound_sync_thread = DeltaSyncThread("LDAP Outbound",
                                           ldap_outbound_listener)
    # Start sync listener threads.
    outbound_sync_thread.start()
def get_default_logger(name):
    """Returns a logger with custom logging format
    This method allows NEXT contributors to use a logger that is
    standardized across the project.
    """
    logger = logging.getLogger(name)

    logger_level = LOGGER_LEVEL_MAP[get_config("LOGGING_LEVEL")]

    logger.setLevel(logger_level)

    # Stream Handler
    stream_handler = logging.StreamHandler(sys.stdout)
    stream_handler.setLevel(logger_level)
    stream_handler.setFormatter(LOGGER_FORMAT)

    logger.addHandler(stream_handler)

    return logger
def load_config(app):
    """Load configuration (alphabetical)"""
    app.config.AES_KEY = get_config("AES_KEY")
    app.config.AIOHTTP_CONN_LIMIT = int(get_config("AIOHTTP_CONN_LIMIT"))
    app.config.AIOHTTP_DNS_TTL = int(get_config("AIOHTTP_DNS_TTL"))
    app.config.BATCHER_KEY_PAIR = Key()
    app.config.CHATBOT_HOST = get_config("CHATBOT_HOST")
    app.config.CHATBOT_PORT = get_config("CHATBOT_PORT")
    app.config.CLIENT_HOST = get_config("CLIENT_HOST")
    app.config.CLIENT_PORT = get_config("CLIENT_PORT")
    app.config.DB_HOST = get_config("DB_HOST")
    app.config.DB_NAME = get_config("DB_NAME")
    app.config.DB_PORT = get_config("DB_PORT")
    app.config.DEBUG = bool(get_config("DEBUG"))
    app.config.LOGGING_LEVEL = get_config("LOGGING_LEVEL")
    app.config.SECRET_KEY = get_config("SECRET_KEY")
    app.config.PORT = int(get_config("SERVER_PORT"))
    app.config.TIMEOUT = int(get_config("TIMEOUT"))
    app.config.VALIDATOR = get_config("VALIDATOR")
    app.config.WORKERS = int(get_config("WORKERS"))
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
"""Simple object for managing a connection to a rethink database
"""
import time
import rethinkdb as r

from rbac.common.config import get_config
from rbac.common.logs import getLogger

LOGGER = getLogger(__name__)
DB_HOST = get_config("DB_HOST")
DB_PORT = get_config("DB_PORT")
DB_NAME = get_config("DB_NAME")

# State Delta catches up based on the first valid ID it finds, which is
# likely genesis, defeating the purpose. Rewind just 15 blocks to handle forks.
KNOWN_COUNT = 15


class Database:
    """Simple object for managing a connection to a rethink database
    """

    def __init__(self, host=None, port=None, name=None):
        self._host = host or DB_HOST
        self._port = port or DB_PORT
Exemple #7
0
def load_config(app):
    """Load configuration (alphabetical)"""
    host = get_config("HOST") + ":" + get_config("SERVER_PORT")
    app.config.AES_KEY = get_config("AES_KEY")
    app.config.AIOHTTP_CONN_LIMIT = int(get_config("AIOHTTP_CONN_LIMIT"))
    app.config.AIOHTTP_DNS_TTL = int(get_config("AIOHTTP_DNS_TTL"))
    app.config.API_CONTACT_EMAIL = "*****@*****.**"
    app.config.API_DESCRIPTION = "Available API endpoints for Sawtooth Next Directory."
    app.config.API_HOST = host
    app.config.API_LICENSE_NAME = "Apache License 2.0"
    app.config.API_LICENSE_URL = (
        "https://github.com/tmobile/sawtooth-next-directory/blob/develop/LICENSE"
    )
    app.config.API_PRODUCES_CONTENT_TYPES = ["application/json"]
    app.config.API_SCHEMES = ["http", "https"]
    app.config.API_TITLE = "Sawtooth Next Directory API"
    app.config.API_SECURITY = [{"authToken": []}]
    app.config.API_SECURITY_DEFINITIONS = {
        "authToken": {
            "type": "apiKey",
            "in": "header",
            "name": "Authorization",
            "description": "Paste your auth token.",
        }
    }
    app.config.BATCHER_KEY_PAIR = Key()
    app.config.CHATBOT_HOST = get_config("CHATBOT_HOST")
    app.config.CHATBOT_PORT = get_config("CHATBOT_PORT")
    app.config.CLIENT_HOST = get_config("CLIENT_HOST")
    app.config.CLIENT_PORT = get_config("CLIENT_PORT")
    app.config.DB_HOST = get_config("DB_HOST")
    app.config.DB_NAME = get_config("DB_NAME")
    app.config.DB_PORT = get_config("DB_PORT")
    app.config.DEBUG = bool(get_config("DEBUG"))
    app.config.LOGGING_LEVEL = get_config("LOGGING_LEVEL")
    app.config.SECRET_KEY = get_config("SECRET_KEY")
    app.config.PORT = int(get_config("SERVER_PORT"))
    app.config.TIMEOUT = int(get_config("TIMEOUT"))
    app.config.VALIDATOR = get_config("VALIDATOR")
    app.config.WORKERS = int(get_config("WORKERS"))
 def url_base(self):
     """ The base url for the server REST API """
     return get_config("REST_ENDPOINT")
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
"""Sawtooth REST API client wrapper"""

import logging
from base64 import b64decode
from rbac.common.sawtooth.rest_client import RestClient
from rbac.common.sawtooth.rest_client import BaseMessage
from rbac.common.sawtooth import batcher
from rbac.common.config import get_config

LOGGER = logging.getLogger(__name__)

VALIDATOR_REST_ENDPOINT = get_config("VALIDATOR_REST_ENDPOINT")
_CLIENT = RestClient(base_url=VALIDATOR_REST_ENDPOINT)


class ClientSync:
    """Sawtooth REST API client wrapper"""

    def __init__(self):
        self._client = _CLIENT

    def send_batches_get_status(self, batch_list):
        """Send a batch list and get the result statuses
        of the execution of that batch list"""
        batch_ids = batcher.get_batch_ids(batch_list)
        self.send_batches(batch_list)
        return self.get_statuses(batch_ids, wait=10)
Exemple #10
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
""" Sawtooth Outbound State Sync
"""

from rbac.common.config import get_config
from rbac.common.logs import get_default_logger

from rbac.ledger_sync.database import Database
from rbac.ledger_sync.deltas.handlers import get_delta_handler
from rbac.ledger_sync.subscriber import Subscriber

LOGGER = get_default_logger(__name__)
VALIDATOR = get_config("VALIDATOR")


def listener():
    """ Listener for Sawtooth State changes
    """
    try:
        database = Database()
        subscriber = Subscriber(VALIDATOR)
        database.connect()
        subscriber.add_handler(get_delta_handler(database))
        known_blocks = database.get_last_known_blocks()
        subscriber.start(known_blocks)
        LOGGER.info("Listening for Sawtooth state changes")

    except Exception as err:  # pylint: disable=broad-except