Skip to content

Commit

Permalink
remove local config file code
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <[email protected]>
  • Loading branch information
ylwu-amzn committed Jul 12, 2023
1 parent f854e23 commit 60e1922
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.ml.common.AccessMode;
import org.opensearch.ml.common.TestHelper;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class MLCreateConnectorResponseTest {

Expand All @@ -35,4 +39,23 @@ public void readFromStream() throws IOException {
MLCreateConnectorResponse response2 = new MLCreateConnectorResponse(output.bytes().streamInput());
Assert.assertEquals("test_id", response2.getConnectorId());
}

@Test
public void t() throws IOException {
MLCreateConnectorInput input = MLCreateConnectorInput.builder()
.name("test_connector_name")
.description("this is a test connector")
.version("1")
.protocol("http")
.parameters(Map.of("input", "test input value"))
.credential(Map.of("key", "test_key_value"))
.access(AccessMode.PUBLIC)
.addAllBackendRoles(true)
.backendRoles(Arrays.asList("r1"))
.build();
BytesStreamOutput output = new BytesStreamOutput();
input.writeTo(output);
MLCreateConnectorInput input2 = new MLCreateConnectorInput(output.bytes().streamInput());
Assert.assertNotNull(input2);
}
}
1 change: 0 additions & 1 deletion ml-algorithms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ dependencies {
implementation 'com.amazonaws:aws-encryption-sdk-java:2.4.0'
implementation 'com.jayway.jsonpath:json-path:2.8.0'
implementation group: 'org.json', name: 'json', version: '20230227'
implementation group: 'org.yaml', name: 'snakeyaml', version: '2.0'
}

configurations.all {
Expand Down
27 changes: 0 additions & 27 deletions ml-algorithms/src/main/java/org/opensearch/ml/engine/MLEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,6 @@ public MLEngine(Path opensearchDataFolder, Path opensearchConfigFolder, Encrypto
this.mlUserConfigPath = opensearchConfigFolder.resolve("opensearch-ml");
this.mlConfigPath = mlCachePath.resolve("config");
this.encryptor = encryptor;
initMasterKey();
}

private synchronized void initMasterKey() {
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
Path userConfigFilePath = mlUserConfigPath.resolve("security_config.json");
Map<String, String> config = null;
if (Files.exists(userConfigFilePath)) {
try (FileInputStream fis = new FileInputStream(userConfigFilePath.toFile());) {
Yaml yaml = new Yaml();
config = yaml.load(fis);
}
}
if (config == null) {
config = new HashMap<>();
}

if (config.containsKey(MASTER_KEY)) {
encryptor.setMasterKey(config.get(MASTER_KEY));
}
return null;
});
} catch (Exception e) {
log.error("Failed to save master key", e);
throw new MLException(e);
}
}

public String getPrebuiltModelMetaListPath() {
Expand Down

0 comments on commit 60e1922

Please sign in to comment.