Пример #1
0
def test_get_configuration():
    CloudharnessConfig.apps = ConfigObject({
        'a': conf_1,
        'b': conf_2
    })
    uut = get_configuration('app1')
    assert uut.name == 'app1'
    assert not uut.is_auto_service()
    assert uut.is_auto_deployment()
    assert uut.is_sentry_enabled()
    assert uut.image_name == 'image1-name'
    uut = get_configuration('app2')
    assert uut.name == 'app2'
    assert not uut.is_auto_service()
    assert not uut.is_auto_deployment()
    assert uut.is_sentry_enabled()


    # uut = get_configuration('app2sub') # FIXME this should work
    uut = uut.subapp

    assert uut.name == 'app2sub'
    assert uut.is_auto_service()
    assert not uut.is_auto_deployment()
    assert not uut.is_sentry_enabled()
Пример #2
0
def get_server_url():
    accounts_app = get_configuration('accounts')

    if not os.environ.get('KUBERNETES_SERVICE_HOST', None):
        # running outside kubernetes
        return accounts_app.get_public_address() + '/auth/'
    return accounts_app.get_service_address() + '/auth/'
Пример #3
0
def getdsn(appname):  # noqa: E501
    """
    Gets the Sentry DSN for a given application or returns the global dsn when set
    global dsn can be set using the kubectl command
        kubectl create secret generic -n mnp mnp-sentry --from-literal=dsn=<dsn>
    :param appname:
    :type appname: str
    :rtype: str
    """
    ch_app = applications.get_configuration(appname)
    if ch_app.is_sentry_enabled():
        if global_dsn:
            # if a global dsn env var is set and not empty then use this
            dsn = global_dsn
        else:
            try:
                dsn = get_dsn(appname)
            except SentryProjectNotFound as e:
                # if project not found, create one
                sentry_api_token = get_token()
                headers = {'Authorization': 'Bearer ' + sentry_api_token}
                url = get_sentry_service_cluster_address(
                ) + f'/api/0/teams/sentry/sentry/projects/'
                data = {'name': appname}
                response = requests.post(url,
                                         data,
                                         headers=headers,
                                         verify=False)
                dsn = get_dsn(appname)
    else:
        dsn = ''
    return {'dsn': dsn}
Пример #4
0
 def get_image_tag(cls, base_name):
     if base_name in cls.get_applications():
         from cloudharness.applications import get_configuration
         return get_configuration(base_name).image_name
     else:
         if not base_name in cls.get_configuration()['task-images']:
             # External image
             return base_name
         return cls.get_configuration()['task-images'][base_name]
Пример #5
0
def get_config():  # noqa: E501
    """
    Gets the config for logging in into accounts

    :rtype: json
        {
            'url': '',
            'realm': '',
            'clientId': ''
        }
    """
    accounts_app = applications.get_configuration('accounts')
    return {
        'url': urljoin(accounts_app.get_public_address(), 'auth'),
        'realm': CloudharnessConfig.get_namespace(),
        'clientId': accounts_app['webclient']['id']
    }
Пример #6
0
def send(operation, context):
    notification_app = apps.get_configuration('notifications')
    notification = notification_app["notification"]["operations"][operation]

    for c in notification["channels"]:
        channel = notification_app["notification"]["channels"][c]
        for b in channel["backends"]:
            if b == "email":
                channel_backend = NotificationEmailBackend
            elif b == "console":
                channel_backend = NotificationConsoleBackend

            try:
                if channel["adapter"].lower() == "email":
                    NotificationEmailAdapter(
                        notification=notification,
                        channel=channel,
                        backend=channel_backend).send(context=context)
                else:
                    raise NotImplementedError
            except Exception as e:
                logger.error('Sending notification error.', exc_info=True)
Пример #7
0
 def _get_client_id(cls):
     return apps.get_configuration('accounts').webclient.get('id')
Пример #8
0
def get_configuration():
    if not conf.is_test():
        host = applications.get_configuration('argo').get_service_address()
    else:
        host = applications.get_configuration('argo').get_public_address()
    return Configuration(host=host)
Пример #9
0
 def get_workspace_volume_size(self, ws: Workspace):
     # Place to change whenever we implement user or workspace based sizing
     return get_configuration('workspaces').conf['workspace_size']