def load_sh(): config = SHConfig() for credentials in ['sh_client_id', 'sh_client_secret', 'instance_id']: if config.__getattribute__(credentials) == '': try: if credentials.startswith('sh_'): env = credentials else: env = 'sh_' + credentials setattr(config, credentials, os.environ.__getitem__(env.upper())) print( f'SentinelHub credential: {credentials} was set from env as {os.environ.__getitem__(env.upper())}' ) config.save() except KeyError: print( f'SentinelHub credential as environmental variable {env.upper()} was not found. ' f'Set credential {credentials} manualy') else: print( f'Actual SentinelHub credential: {credentials} is {config.__getattribute__(credentials)}' ) return SHConfig()
def set_sh_config(): config = SHConfig() expected_base_url = 'https://www.geopedia.world/rest/' if GeopediaConfig.is_production() else \ 'https://test.geopedia.world/rest/' if config.geopedia_rest_url != expected_base_url: config.geopedia_rest_url = expected_base_url config.save()
def test_save(self): config = SHConfig() old_value = config.download_timeout_seconds config.download_timeout_seconds = "abcd" self.assertRaises(ValueError, config.save) new_value = 150.5 config.download_timeout_seconds = new_value config.save() config = SHConfig() self.assertEqual(config.download_timeout_seconds, new_value, "Saved value has not changed") config.download_timeout_seconds = old_value config.save()
def set_sh_config(config: BaseConfig) -> SHConfig: """ Set AWS and SH credentials in SHConfig file to allow usage of download and io tasks """ sh_config = SHConfig() sh_config.aws_access_key_id = config.aws_access_key_id sh_config.aws_secret_access_key = config.aws_secret_access_key if all(key in config.__annotations__.keys() for key in ['sh_client_id', 'sh_client_secret']): sh_config.sh_client_id = config.sh_client_id sh_config.sh_client_secret = config.sh_client_secret sh_config.save() return sh_config
def _save_environment_variables(): config = SHConfig() for attr in ['INSTANCE_ID', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY']: if os.environ.get(attr): setattr(config, attr.lower(), os.environ.get(attr)) config.save()
def set_sh(name, value): config = SHConfig() setattr(config, name, value) print(f'{name} : {value} was set into SHConfig') config.save()