Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial check-in #162

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
<micrometer.version>1.1.0</micrometer.version>
<junit-jupiter.version>5.7.0</junit-jupiter.version>
<uid2-shared.version>5.9.6-62621be878</uid2-shared.version>
<uid2-shared.version>5.11.0-d71d3c960e</uid2-shared.version>
<image.version>${project.version}</image.version>
</properties>
<repositories>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/admin/secret/IKeypairManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import com.uid2.shared.model.ClientSideKeypair;

public interface IKeypairManager {
ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled) throws Exception;
ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled, String name) throws Exception;
Iterable<ClientSideKeypair> getKeypairsBySite(int siteId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private static JsonObject toJson(ClientSideKeypair keypair, boolean includePriva
jo.put("contact", keypair.getContact());
jo.put("created", keypair.getCreated().getEpochSecond());
jo.put("disabled", keypair.isDisabled());
jo.put("name", keypair.getName());
return jo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void handleAddKeypair(RoutingContext rc) {
final Integer siteId = body.getInteger("site_id");
final String contact = body.getString("contact", "");
final boolean disabled = body.getBoolean("disabled", false);
final String name = body.getString("name");
if (siteId == null) {
ResponseUtil.error(rc, 400, "Required parameters: site_id");
return;
Expand All @@ -97,7 +98,7 @@ private void handleAddKeypair(RoutingContext rc) {

final ClientSideKeypair newKeypair;
try {
newKeypair = createAndSaveSiteKeypair(siteId, contact, disabled);
newKeypair = createAndSaveSiteKeypair(siteId, contact, disabled, name);
} catch (Exception e) {
ResponseUtil.errorInternal(rc, "failed to upload keypairs", e);
return;
Expand All @@ -120,6 +121,7 @@ private void handleUpdateKeypair(RoutingContext rc) {
final String subscriptionId = body.getString("subscription_id");
String contact = body.getString("contact");
Boolean disabled = body.getBoolean("disabled");
String name = body.getString("name");

if (subscriptionId == null) {
ResponseUtil.error(rc, 400, "Required parameters: subscription_id");
Expand All @@ -132,26 +134,32 @@ private void handleUpdateKeypair(RoutingContext rc) {
return;
}

if (contact == null && disabled == null) {
ResponseUtil.error(rc, 400, "Updatable parameters: contact, disabled");
if (contact == null && disabled == null && name == null) {
ResponseUtil.error(rc, 400, "Updatable parameters: contact, disabled, name");
return;
}

if (contact == null) {
contact = keypair.getContact();
}

if (disabled == null) {
disabled = keypair.isDisabled();
}

if (name == null) {
name = keypair.getName();
}

final ClientSideKeypair newKeypair = new ClientSideKeypair(
keypair.getSubscriptionId(),
keypair.encodePublicKeyToString(),
keypair.encodePrivateKeyToString(),
keypair.getSiteId(),
contact,
keypair.getCreated(),
disabled);
disabled,
name);


Set<ClientSideKeypair> allKeypairs = new HashSet<>(this.keypairStore.getAll());
Expand Down Expand Up @@ -198,7 +206,7 @@ private void handleListKeypair(RoutingContext rc) {
}

@Override
public ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled) throws Exception {
public ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled, String name) throws Exception {

final Instant now = clock.now();

Expand All @@ -219,7 +227,8 @@ public ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, bo
siteId,
contact,
now,
disabled);
disabled,
name);
keypairs.add(newKeypair);
storeWriter.upload(keypairs, null);

Expand Down
Loading