Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def teardown_method(self, method):
from amplify.ext.configurator.config import ConfiguratorConfig
ConfiguratorConfig.config = copy.deepcopy(self.original_config)
context.app_config.remove(ConfiguratorConfig())
super(BaseConfiguratorTestCase, self).teardown_method(method)
def test_freeze_api_url(self):
# check that if api_url is not set it will not prevent agent from setting api_url from cloud
context.app_config['cloud']['api_url'] = ''
context.setup(app='test', app_config=context.app_config.default)
assert_that(context.freeze_api_url, equal_to(False))
# check that an api_url from our receiver's domain will not prevent agent from setting api_url from cloud
context.app_config['cloud']['api_url'] = 'https://receiver.amplify.nginx.com:443/1.1'
context.setup(app='test', app_config=context.app_config.default)
assert_that(context.freeze_api_url, equal_to(False))
# check that a custom api_url will prevent agent from setting api_url from cloud
context.app_config['cloud']['api_url'] = 'http://some.other.domain/endpoint/'
context.setup(app='test', app_config=context.app_config.default)
assert_that(context.freeze_api_url, equal_to(True))
def teardown_method(self, method):
context.app_config['credentials']['imagename'] = None
context.app_config['credentials']['uuid'] = DEFAULT_UUID
context.setup(app='test', app_config=context.app_config.default)
context.objects = None
context._setup_object_tank()
super(ContainerSystemManagerTestCase, self).teardown_method(method)
def test_freeze_api_url(self):
# check that if api_url is not set it will not prevent agent from setting api_url from cloud
context.app_config['cloud']['api_url'] = ''
context.setup(app='test', app_config=context.app_config.default)
assert_that(context.freeze_api_url, equal_to(False))
# check that an api_url from our receiver's domain will not prevent agent from setting api_url from cloud
context.app_config['cloud']['api_url'] = 'https://receiver.amplify.nginx.com:443/1.1'
context.setup(app='test', app_config=context.app_config.default)
assert_that(context.freeze_api_url, equal_to(False))
# check that a custom api_url will prevent agent from setting api_url from cloud
context.app_config['cloud']['api_url'] = 'http://some.other.domain/endpoint/'
context.setup(app='test', app_config=context.app_config.default)
assert_that(context.freeze_api_url, equal_to(True))
def test_parse_simple_exclude_file(self):
"""Check that config.full_parse() obeys exclude_logs from app_config with file ignore"""
context.app_config['nginx']['exclude_logs'] = '*.log'
config = NginxConfig(simple_config)
config.full_parse()
del context.app_config['nginx']['exclude_logs']
assert_that(config.error_logs, empty())
assert_that(config.access_logs, empty())
# log formats
assert_that(config.log_formats, has_length(1))
assert_that(config.log_formats, has_item('super_log_format'))
assert_that(
config.log_formats['super_log_format'],
equal_to(
'$remote_addr - $remote_user [$time_local] "$request" $status ' +
'$body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" ' +
'rt="$request_time" ua="$upstream_addr" us="$upstream_status" ' +
'ut="$upstream_response_time" "$gzip_ratio"'
)
)
def wrapper(*args, **kwargs):
context.app_config['credentials']['imagename'] = 'DockerTest'
f(*args, **kwargs)
context.app_config['credentials']['imagename'] = None
def __init__(self, **kwargs):
super(PlusObject, self).__init__(**kwargs)
# Reset intervals to standardize intervals for all Plus objects
self.intervals = context.app_config['containers']['plus']['poll_intervals']
self.root_uuid = context.uuid
self.parent_local_id = self.data['parent_local_id']
self.local_name = self.data['local_name']
self.name = self.local_name
self.plus_status_internal_url_cache = None
self.api_internal_url_cache = None
self.collectors = []
print(" 3. sudo chown %s %s" % (current_user, log_filename))
return 1
# try to connect to the cloud
tries = 0
while tries <= 3:
tries += 1
try:
context.http_client.post('agent/', {})
except (requests.HTTPError, requests.ConnectionError) as e:
api_url = context.app_config['cloud']['api_url']
print("\033[31mCould not connect to API via url %s\033[0m\n" % api_url)
if e.response and e.response.status_code == 404:
api_key = context.app_config['credentials']['api_key']
print("\033[31mIt seems like your API key '%s' is wrong. \033[0m\n" % api_key)
return 1
else:
if (wait_for_cloud and tries == 1) or wait_for_cloud is False:
print("\033[31mIt seems like we have little problems connecting to API.\033[0m")
print("\033[31mApologies and bear with us. \033[0m\n")
if wait_for_cloud and tries < 3:
print("\033[31mWe will try to establish a connection once again in a minute.\033[0m\n")
if wait_for_cloud and tries == 3:
print("\033[31mGiving up after three attempts...\033[0m\n")
return 1
elif wait_for_cloud is False:
return 1
else:
def update_cloud_url(self):
config = context.app_config
self.url = '%s/%s' % (config['cloud']['api_url'], config['credentials']['api_key'])
self.session = requests.Session()
self.session.headers.update({
'Content-Type': 'application/json',
'User-Agent': 'nginx-%s-agent/%s' % (context.agent_name, context.version)
})
if self.gzip:
self.session.headers.update({'Content-Encoding': 'gzip'})
def hostname():
"""
Get the hostname from
- config
- unix internals
- ec2
"""
result = None
config = context.app_config
hostname_from_config = config['credentials']['hostname']
if hostname_from_config and is_valid_hostname(hostname_from_config):
result = hostname_from_config
# then move on to os-specific detection
if result is None:
def _get_hostname_unix():
try:
# fqdn
out, err = subp.call('/bin/hostname -f')
return out[0]
except Exception:
return None
if os_name() in ['mac', 'freebsd', 'linux', 'solaris']:
unix_hostname = _get_hostname_unix()