Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Revert "Use read-only ACL DAO in automation resource"
Browse files Browse the repository at this point in the history
This reverts commit 7b49329.
  • Loading branch information
csstaub committed Mar 13, 2017
1 parent ddf2c40 commit 7e726fd
Showing 1 changed file with 9 additions and 11 deletions.
Expand Up @@ -76,24 +76,22 @@ public class AutomationSecretResource {
private static final Logger logger = LoggerFactory.getLogger(AutomationSecretResource.class); private static final Logger logger = LoggerFactory.getLogger(AutomationSecretResource.class);
private final SecretController secretController; private final SecretController secretController;
private final SecretDAO secretDAO; private final SecretDAO secretDAO;
private final AclDAO aclDAOReadOnly; private final AclDAO aclDAO;
private final AuditLog auditLog; private final AuditLog auditLog;


@SuppressWarnings("unused")
@Inject public AutomationSecretResource(SecretController secretController, @Inject public AutomationSecretResource(SecretController secretController,
SecretDAOFactory secretDAOFactory, AclDAOFactory aclDAOFactory, AuditLog auditLog) { SecretDAOFactory secretDAOFactory, AclDAOFactory aclDAOFactory, AuditLog auditLog) {
this.secretController = secretController; this.secretController = secretController;
this.secretDAO = secretDAOFactory.readwrite(); this.secretDAO = secretDAOFactory.readwrite();
this.aclDAOReadOnly = aclDAOFactory.readonly(); this.aclDAO = aclDAOFactory.readwrite();
this.auditLog = auditLog; this.auditLog = auditLog;
} }


/** Constructor for testing */
@VisibleForTesting AutomationSecretResource(SecretController secretController, @VisibleForTesting AutomationSecretResource(SecretController secretController,
SecretDAO secretDAO, AclDAO aclDAOReadOnly, AuditLog auditLog) { SecretDAO secretDAO, AclDAO aclDAO, AuditLog auditLog) {
this.secretController = secretController; this.secretController = secretController;
this.secretDAO = secretDAO; this.secretDAO = secretDAO;
this.aclDAOReadOnly = aclDAOReadOnly; this.aclDAO = aclDAO;
this.auditLog = auditLog; this.auditLog = auditLog;
} }


Expand Down Expand Up @@ -130,7 +128,7 @@ public AutomationSecretResponse createSecret(
throw new ConflictException(format("Cannot create secret %s.", request.name)); throw new ConflictException(format("Cannot create secret %s.", request.name));
} }
ImmutableList<Group> groups = ImmutableList<Group> groups =
ImmutableList.copyOf(aclDAOReadOnly.getGroupsFor(secret)); ImmutableList.copyOf(aclDAO.getGroupsFor(secret));


Map<String, String> extraInfo = new HashMap<>(); Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true"); extraInfo.put("deprecated", "true");
Expand Down Expand Up @@ -173,7 +171,7 @@ public ImmutableList<AutomationSecretResponse> readSecrets(


Secret secret = optionalSecret.get(); Secret secret = optionalSecret.get();
ImmutableList<Group> groups = ImmutableList<Group> groups =
ImmutableList.copyOf(aclDAOReadOnly.getGroupsFor(secret)); ImmutableList.copyOf(aclDAO.getGroupsFor(secret));
responseBuilder.add(AutomationSecretResponse.fromSecret(secret, groups)); responseBuilder.add(AutomationSecretResponse.fromSecret(secret, groups));
} else { } else {
List<SanitizedSecret> secrets = secretController.getSanitizedSecrets(null, null); List<SanitizedSecret> secrets = secretController.getSanitizedSecrets(null, null);
Expand All @@ -183,7 +181,7 @@ public ImmutableList<AutomationSecretResponse> readSecrets(
new IllegalStateException(format("Cannot find record related to %s", sanitizedSecret))); new IllegalStateException(format("Cannot find record related to %s", sanitizedSecret)));


ImmutableList<Group> groups = ImmutableList<Group> groups =
ImmutableList.copyOf(aclDAOReadOnly.getGroupsFor(secret)); ImmutableList.copyOf(aclDAO.getGroupsFor(secret));
responseBuilder.add(AutomationSecretResponse.fromSecret(secret, groups)); responseBuilder.add(AutomationSecretResponse.fromSecret(secret, groups));
} }
} }
Expand Down Expand Up @@ -213,7 +211,7 @@ public AutomationSecretResponse readSecretById(
throw new NotFoundException("Secret not found."); throw new NotFoundException("Secret not found.");
} }


ImmutableList<Group> groups = ImmutableList.copyOf(aclDAOReadOnly.getGroupsFor(secret.get())); ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(secret.get()));


return AutomationSecretResponse.fromSecret(secret.get(), groups); return AutomationSecretResponse.fromSecret(secret.get(), groups);
} }
Expand All @@ -236,7 +234,7 @@ public Response deleteSecretSeries(
@PathParam("secretName") String secretName) { @PathParam("secretName") String secretName) {


Secret secret = secretController.getSecretByName(secretName).orElseThrow(() -> new NotFoundException("Secret series not found.")); Secret secret = secretController.getSecretByName(secretName).orElseThrow(() -> new NotFoundException("Secret series not found."));
Set<String> groups = aclDAOReadOnly.getGroupsFor(secret).stream().map(Group::getName).collect(toSet()); Set<String> groups = aclDAO.getGroupsFor(secret).stream().map(Group::getName).collect(toSet());
secretDAO.deleteSecretsByName(secretName); secretDAO.deleteSecretsByName(secretName);


// Record all groups to which this secret belongs, so they can be restored manually if necessary // Record all groups to which this secret belongs, so they can be restored manually if necessary
Expand Down

0 comments on commit 7e726fd

Please sign in to comment.