Search in sources :

Example 1 with MockSecureSettings

use of org.opensearch.common.settings.MockSecureSettings in project OpenSearch by opensearch-project.

the class AzureBlobContainerRetriesTests method createBlobContainer.

private BlobContainer createBlobContainer(final int maxRetries) {
    final Settings.Builder clientSettings = Settings.builder();
    final String clientName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT);
    final InetSocketAddress address = httpServer.getAddress();
    final String endpoint = "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort() + "/";
    clientSettings.put(ENDPOINT_SUFFIX_SETTING.getConcreteSettingForNamespace(clientName).getKey(), endpoint);
    clientSettings.put(MAX_RETRIES_SETTING.getConcreteSettingForNamespace(clientName).getKey(), maxRetries);
    clientSettings.put(TIMEOUT_SETTING.getConcreteSettingForNamespace(clientName).getKey(), TimeValue.timeValueMillis(2000));
    final MockSecureSettings secureSettings = new MockSecureSettings();
    secureSettings.setString(ACCOUNT_SETTING.getConcreteSettingForNamespace(clientName).getKey(), "account");
    final String key = Base64.getEncoder().encodeToString(randomAlphaOfLength(10).getBytes(UTF_8));
    secureSettings.setString(KEY_SETTING.getConcreteSettingForNamespace(clientName).getKey(), key);
    clientSettings.setSecureSettings(secureSettings);
    service = new AzureStorageService(clientSettings.build()) {

        @Override
        RequestRetryOptions createRetryPolicy(final AzureStorageSettings azureStorageSettings, String secondaryHost) {
            return new RequestRetryOptions(RetryPolicyType.EXPONENTIAL, azureStorageSettings.getMaxRetries(), 1, 10L, 100L, secondaryHost);
        }

        @Override
        ParallelTransferOptions getBlobRequestOptionsForWriteBlob() {
            return new ParallelTransferOptions().setMaxSingleUploadSizeLong(ByteSizeUnit.MB.toBytes(1));
        }
    };
    final RepositoryMetadata repositoryMetadata = new RepositoryMetadata("repository", AzureRepository.TYPE, Settings.builder().put(CONTAINER_SETTING.getKey(), "container").put(ACCOUNT_SETTING.getKey(), clientName).build());
    return new AzureBlobContainer(BlobPath.cleanPath(), new AzureBlobStore(repositoryMetadata, service, threadPool), threadPool);
}
Also used : RequestRetryOptions(com.azure.storage.common.policy.RequestRetryOptions) InetSocketAddress(java.net.InetSocketAddress) Matchers.containsString(org.hamcrest.Matchers.containsString) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) ParallelTransferOptions(com.azure.storage.blob.models.ParallelTransferOptions) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 2 with MockSecureSettings

use of org.opensearch.common.settings.MockSecureSettings in project OpenSearch by opensearch-project.

the class AzureStorageServiceTests method testProxySocks.

public void testProxySocks() throws UnknownHostException {
    final MockSecureSettings secureSettings = buildSecureSettings();
    secureSettings.setString("azure.client.azure1.proxy.username", "user");
    secureSettings.setString("azure.client.azure1.proxy.password", "pwd");
    final Settings settings = Settings.builder().put("azure.client.azure1.proxy.host", "127.0.0.1").put("azure.client.azure1.proxy.port", 8080).put("azure.client.azure1.proxy.type", "socks5").setSecureSettings(secureSettings).build();
    final AzureStorageService mock = storageServiceWithSettingsValidation(settings);
    final ProxySettings azure1Proxy = mock.storageSettings.get("azure1").getProxySettings();
    assertThat(azure1Proxy, notNullValue());
    assertThat(azure1Proxy.getType(), is(ProxySettings.ProxyType.SOCKS5));
    assertThat(azure1Proxy.getAddress(), is(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 8080)));
    assertEquals("user", azure1Proxy.getUsername());
    assertEquals("pwd", azure1Proxy.getPassword());
    assertEquals(ProxySettings.NO_PROXY_SETTINGS, mock.storageSettings.get("azure2").getProxySettings());
    assertEquals(ProxySettings.NO_PROXY_SETTINGS, mock.storageSettings.get("azure3").getProxySettings());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 3 with MockSecureSettings

use of org.opensearch.common.settings.MockSecureSettings in project OpenSearch by opensearch-project.

the class GoogleCloudStorageServiceTests method testClientsAreNotSharedAcrossRepositories.

public void testClientsAreNotSharedAcrossRepositories() throws Exception {
    final MockSecureSettings secureSettings1 = new MockSecureSettings();
    secureSettings1.setFile("gcs.client.gcs1.credentials_file", serviceAccountFileContent("test_project"));
    final Settings settings = Settings.builder().setSecureSettings(secureSettings1).build();
    try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings)) {
        final GoogleCloudStorageService storageService = plugin.storageService;
        final Storage repo1Client = storageService.client("gcs1", "repo1", new GoogleCloudStorageOperationsStats("bucket"));
        final Storage repo2Client = storageService.client("gcs1", "repo2", new GoogleCloudStorageOperationsStats("bucket"));
        final Storage repo1ClientSecondInstance = storageService.client("gcs1", "repo1", new GoogleCloudStorageOperationsStats("bucket"));
        assertNotSame(repo1Client, repo2Client);
        assertSame(repo1Client, repo1ClientSecondInstance);
    }
}
Also used : Storage(com.google.cloud.storage.Storage) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 4 with MockSecureSettings

use of org.opensearch.common.settings.MockSecureSettings in project OpenSearch by opensearch-project.

the class GoogleCloudStorageServiceTests method testReinitClientSettings.

public void testReinitClientSettings() throws Exception {
    final MockSecureSettings secureSettings1 = new MockSecureSettings();
    secureSettings1.setFile("gcs.client.gcs1.credentials_file", serviceAccountFileContent("project_gcs11"));
    secureSettings1.setFile("gcs.client.gcs2.credentials_file", serviceAccountFileContent("project_gcs12"));
    final Settings settings1 = Settings.builder().setSecureSettings(secureSettings1).build();
    final MockSecureSettings secureSettings2 = new MockSecureSettings();
    secureSettings2.setFile("gcs.client.gcs1.credentials_file", serviceAccountFileContent("project_gcs21"));
    secureSettings2.setFile("gcs.client.gcs3.credentials_file", serviceAccountFileContent("project_gcs23"));
    final Settings settings2 = Settings.builder().setSecureSettings(secureSettings2).build();
    try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings1)) {
        final GoogleCloudStorageService storageService = plugin.storageService;
        GoogleCloudStorageOperationsStats statsCollector = new GoogleCloudStorageOperationsStats("bucket");
        final Storage client11 = storageService.client("gcs1", "repo1", statsCollector);
        assertThat(client11.getOptions().getProjectId(), equalTo("project_gcs11"));
        final Storage client12 = storageService.client("gcs2", "repo2", statsCollector);
        assertThat(client12.getOptions().getProjectId(), equalTo("project_gcs12"));
        // client 3 is missing
        final IllegalArgumentException e1 = expectThrows(IllegalArgumentException.class, () -> storageService.client("gcs3", "repo3", statsCollector));
        assertThat(e1.getMessage(), containsString("Unknown client name [gcs3]."));
        // update client settings
        plugin.reload(settings2);
        // old client 1 not changed
        assertThat(client11.getOptions().getProjectId(), equalTo("project_gcs11"));
        // new client 1 is changed
        final Storage client21 = storageService.client("gcs1", "repo1", statsCollector);
        assertThat(client21.getOptions().getProjectId(), equalTo("project_gcs21"));
        // old client 2 not changed
        assertThat(client12.getOptions().getProjectId(), equalTo("project_gcs12"));
        // new client2 is gone
        final IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> storageService.client("gcs2", "repo2", statsCollector));
        assertThat(e2.getMessage(), containsString("Unknown client name [gcs2]."));
        // client 3 emerged
        final Storage client23 = storageService.client("gcs3", "repo3", statsCollector);
        assertThat(client23.getOptions().getProjectId(), equalTo("project_gcs23"));
    }
}
Also used : Storage(com.google.cloud.storage.Storage) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 5 with MockSecureSettings

use of org.opensearch.common.settings.MockSecureSettings in project OpenSearch by opensearch-project.

the class GoogleCloudStorageThirdPartyTests method credentials.

@Override
protected SecureSettings credentials() {
    assertThat(System.getProperty("test.google.account"), not(blankOrNullString()));
    assertThat(System.getProperty("test.google.bucket"), not(blankOrNullString()));
    MockSecureSettings secureSettings = new MockSecureSettings();
    secureSettings.setFile("gcs.client.default.credentials_file", Base64.getDecoder().decode(System.getProperty("test.google.account")));
    return secureSettings;
}
Also used : MockSecureSettings(org.opensearch.common.settings.MockSecureSettings)

Aggregations

MockSecureSettings (org.opensearch.common.settings.MockSecureSettings)44 Settings (org.opensearch.common.settings.Settings)25 Matchers.containsString (org.hamcrest.Matchers.containsString)7 SettingsException (org.opensearch.common.settings.SettingsException)6 AWSCredentials (com.amazonaws.auth.AWSCredentials)5 InetSocketAddress (java.net.InetSocketAddress)5 Matchers.emptyString (org.hamcrest.Matchers.emptyString)4 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)3 RecoverySettings (org.opensearch.indices.recovery.RecoverySettings)3 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)2 Storage (com.google.cloud.storage.Storage)2 IOException (java.io.IOException)2 RepositoryMetadata (org.opensearch.cluster.metadata.RepositoryMetadata)2 GoogleCloudStorageClientSettings.getClientSettings (org.opensearch.repositories.gcs.GoogleCloudStorageClientSettings.getClientSettings)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1