-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a928bcd
commit f849d6f
Showing
6 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.uid2.shared.vertx; | ||
|
||
import com.uid2.shared.ApplicationVersion; | ||
import com.uid2.shared.Utils; | ||
import com.uid2.shared.attest.AttestationResponseHandler; | ||
import com.uid2.shared.attest.NoAttestationProvider; | ||
import com.uid2.shared.attest.UidCoreClient; | ||
import com.uid2.shared.cloud.CloudStorageException; | ||
import com.uid2.shared.cloud.CloudUtils; | ||
import io.vertx.config.spi.ConfigStore; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.impl.VertxInternal; | ||
import io.vertx.core.impl.future.FailedFuture; | ||
import io.vertx.core.json.Json; | ||
import io.vertx.core.json.JsonObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class CoreConfigStore implements ConfigStore { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CoreConfigStore.class); | ||
private final VertxInternal vertx; | ||
private final UidCoreClient uidCoreClient; | ||
|
||
public CoreConfigStore(Vertx vertx, JsonObject configuration) { | ||
this.vertx = (VertxInternal) vertx; | ||
String token = configuration.getString("core_api_token"); | ||
String coreUrl = configuration.getString("core_attest_url"); | ||
|
||
ApplicationVersion appVersion = null; | ||
try { | ||
appVersion = ApplicationVersion.load("uid2-operator", "uid2-shared", "uid2-attestation-api"); | ||
AttestationResponseHandler handler = new AttestationResponseHandler(vertx, coreUrl, token, appVersion, new NoAttestationProvider(), null, CloudUtils.defaultProxy); | ||
this.uidCoreClient = new UidCoreClient(token, CloudUtils.defaultProxy, handler); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Future<Void> close() { | ||
return this.vertx.getOrCreateContext().succeededFuture(); | ||
} | ||
|
||
@Override | ||
public Future<Buffer> get() { | ||
try { | ||
Future<JsonObject> future; | ||
InputStream stream = this.uidCoreClient.download("/config"); | ||
String jsonString = Utils.readToEnd(stream); | ||
if (jsonString != null && !jsonString.isEmpty()) { | ||
return Future.succeededFuture(Buffer.buffer(jsonString)); | ||
} else { | ||
return Future.failedFuture("Unable to get config from Core"); | ||
} | ||
} catch (CloudStorageException e) { | ||
return Future.failedFuture(e); | ||
} catch (IOException e) { | ||
return Future.failedFuture(e); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/uid2/shared/vertx/CoreConfigStoreFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.uid2.shared.vertx; | ||
|
||
import io.vertx.config.spi.ConfigStore; | ||
import io.vertx.config.spi.ConfigStoreFactory; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class CoreConfigStoreFactory implements ConfigStoreFactory { | ||
@Override | ||
public String name() { | ||
return "core"; | ||
} | ||
|
||
@Override | ||
public ConfigStore create(Vertx vertx, JsonObject configuration) { | ||
return new CoreConfigStore(vertx, configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/io.vertx.config.spi.ConfigStoreFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.uid2.shared.vertx.CoreConfigStoreFactory |