Skip to content

Commit

Permalink
allow non-admins to see slaves / racks
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetr committed Jun 19, 2015
1 parent 4087fcb commit 6792c16
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
Expand Up @@ -26,6 +26,7 @@ public AbstractMachineResource(AbstractMachineManager<T> manager, SingularityVal
} }


protected void remove(String objectId) { protected void remove(String objectId) {
validator.checkForAdminAuthorization(user);
checkNotFound(manager.deleteObject(objectId) == SingularityDeleteResult.DELETED, "Couldn't find dead %s with id %s", getObjectTypeString(), objectId); checkNotFound(manager.deleteObject(objectId) == SingularityDeleteResult.DELETED, "Couldn't find dead %s with id %s", getObjectTypeString(), objectId);
} }


Expand All @@ -46,12 +47,14 @@ private void changeState(String objectId, MachineState newState, Optional<String


} }


protected void decommission(String objectId, Optional<String> user) { protected void decommission(String objectId, Optional<String> queryUser) {
changeState(objectId, MachineState.STARTING_DECOMMISSION, user); validator.checkForAdminAuthorization(user);
changeState(objectId, MachineState.STARTING_DECOMMISSION, queryUser);
} }


protected void activate(String objectId, Optional<String> user) { protected void activate(String objectId, Optional<String> queryUser) {
changeState(objectId, MachineState.ACTIVE, user); validator.checkForAdminAuthorization(user);
changeState(objectId, MachineState.ACTIVE, queryUser);
} }


} }
Expand Up @@ -45,23 +45,20 @@ protected String getObjectTypeString() {
@Path("/") @Path("/")
@ApiOperation("Retrieve the list of all known racks, optionally filtering by a particular state") @ApiOperation("Retrieve the list of all known racks, optionally filtering by a particular state")
public List<SingularityRack> getRacks(@ApiParam("Optionally specify a particular state to filter racks by") @QueryParam("state") Optional<MachineState> filterState) { public List<SingularityRack> getRacks(@ApiParam("Optionally specify a particular state to filter racks by") @QueryParam("state") Optional<MachineState> filterState) {
validator.checkForAdminAuthorization(user);
return manager.getObjectsFiltered(filterState); return manager.getObjectsFiltered(filterState);
} }


@GET @GET
@Path("/rack/{rackId}") @Path("/rack/{rackId}")
@ApiOperation("Retrieve the history of a given rack") @ApiOperation("Retrieve the history of a given rack")
public List<SingularityMachineStateHistoryUpdate> getRackHistory(@ApiParam("Rack ID") @PathParam("rackId") String rackId) { public List<SingularityMachineStateHistoryUpdate> getRackHistory(@ApiParam("Rack ID") @PathParam("rackId") String rackId) {
validator.checkForAdminAuthorization(user);
return manager.getHistory(rackId); return manager.getHistory(rackId);
} }


@DELETE @DELETE
@Path("/rack/{rackId}") @Path("/rack/{rackId}")
@ApiOperation("Remove a known rack, erasing history. This operation will cancel decomissioning of racks") @ApiOperation("Remove a known rack, erasing history. This operation will cancel decomissioning of racks")
public void removeRack(@ApiParam("Rack ID") @PathParam("rackId") String rackId, @QueryParam("user") Optional<String> queryUser) { public void removeRack(@ApiParam("Rack ID") @PathParam("rackId") String rackId, @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.remove(rackId); super.remove(rackId);
} }


Expand All @@ -70,7 +67,6 @@ public void removeRack(@ApiParam("Rack ID") @PathParam("rackId") String rackId,
@Deprecated @Deprecated
public void decomissionRack(@ApiParam("Active rack ID") @PathParam("rackId") String rackId, public void decomissionRack(@ApiParam("Active rack ID") @PathParam("rackId") String rackId,
@ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) { @ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.decommission(rackId, queryUser); super.decommission(rackId, queryUser);
} }


Expand All @@ -79,7 +75,6 @@ public void decomissionRack(@ApiParam("Active rack ID") @PathParam("rackId") Str
@ApiOperation("Begin decommissioning a specific active rack") @ApiOperation("Begin decommissioning a specific active rack")
public void decommissionRack(@ApiParam("Active rack ID") @PathParam("rackId") String rackId, public void decommissionRack(@ApiParam("Active rack ID") @PathParam("rackId") String rackId,
@ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) { @ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.decommission(rackId, queryUser); super.decommission(rackId, queryUser);
} }


Expand All @@ -88,7 +83,6 @@ public void decommissionRack(@ApiParam("Active rack ID") @PathParam("rackId") St
@ApiOperation("Activate a decomissioning rack, canceling decomission without erasing history") @ApiOperation("Activate a decomissioning rack, canceling decomission without erasing history")
public void activateSlave(@ApiParam("Active rackId") @PathParam("rackId") String rackId, public void activateSlave(@ApiParam("Active rackId") @PathParam("rackId") String rackId,
@ApiParam("User requesting the activate") @QueryParam("user") Optional<String> queryUser) { @ApiParam("User requesting the activate") @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.activate(rackId, queryUser); super.activate(rackId, queryUser);
} }


Expand Down
Expand Up @@ -44,23 +44,20 @@ protected String getObjectTypeString() {
@Path("/") @Path("/")
@ApiOperation("Retrieve the list of all known slaves, optionally filtering by a particular state") @ApiOperation("Retrieve the list of all known slaves, optionally filtering by a particular state")
public List<SingularitySlave> getSlaves(@ApiParam("Optionally specify a particular state to filter slaves by") @QueryParam("state") Optional<MachineState> filterState) { public List<SingularitySlave> getSlaves(@ApiParam("Optionally specify a particular state to filter slaves by") @QueryParam("state") Optional<MachineState> filterState) {
validator.checkForAdminAuthorization(user);
return manager.getObjectsFiltered(filterState); return manager.getObjectsFiltered(filterState);
} }


@GET @GET
@Path("/slave/{slaveId}") @Path("/slave/{slaveId}")
@ApiOperation("Retrieve the history of a given slave") @ApiOperation("Retrieve the history of a given slave")
public List<SingularityMachineStateHistoryUpdate> getSlaveHistory(@ApiParam("Slave ID") @PathParam("slaveId") String slaveId) { public List<SingularityMachineStateHistoryUpdate> getSlaveHistory(@ApiParam("Slave ID") @PathParam("slaveId") String slaveId) {
validator.checkForAdminAuthorization(user);
return manager.getHistory(slaveId); return manager.getHistory(slaveId);
} }


@DELETE @DELETE
@Path("/slave/{slaveId}") @Path("/slave/{slaveId}")
@ApiOperation("Remove a known slave, erasing history. This operation will cancel decomissioning of the slave") @ApiOperation("Remove a known slave, erasing history. This operation will cancel decomissioning of the slave")
public void removeSlave(@ApiParam("Active SlaveId") @PathParam("slaveId") String slaveId, @QueryParam("user") Optional<String> queryUser) { public void removeSlave(@ApiParam("Active SlaveId") @PathParam("slaveId") String slaveId, @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.remove(slaveId); super.remove(slaveId);
} }


Expand All @@ -69,7 +66,6 @@ public void removeSlave(@ApiParam("Active SlaveId") @PathParam("slaveId") String
@Deprecated @Deprecated
public void decomissionSlave(@ApiParam("Active slaveId") @PathParam("slaveId") String slaveId, public void decomissionSlave(@ApiParam("Active slaveId") @PathParam("slaveId") String slaveId,
@ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) { @ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.decommission(slaveId, queryUser); super.decommission(slaveId, queryUser);
} }


Expand All @@ -78,7 +74,6 @@ public void decomissionSlave(@ApiParam("Active slaveId") @PathParam("slaveId") S
@ApiOperation("Begin decommissioning a specific active slave") @ApiOperation("Begin decommissioning a specific active slave")
public void decommissionSlave(@ApiParam("Active slaveId") @PathParam("slaveId") String slaveId, public void decommissionSlave(@ApiParam("Active slaveId") @PathParam("slaveId") String slaveId,
@ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) { @ApiParam("User requesting the decommisioning") @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.decommission(slaveId, queryUser); super.decommission(slaveId, queryUser);
} }


Expand All @@ -87,7 +82,6 @@ public void decommissionSlave(@ApiParam("Active slaveId") @PathParam("slaveId")
@ApiOperation("Activate a decomissioning slave, canceling decomission without erasing history") @ApiOperation("Activate a decomissioning slave, canceling decomission without erasing history")
public void activateSlave(@ApiParam("Active slaveId") @PathParam("slaveId") String slaveId, public void activateSlave(@ApiParam("Active slaveId") @PathParam("slaveId") String slaveId,
@ApiParam("User requesting the activate") @QueryParam("user") Optional<String> queryUser) { @ApiParam("User requesting the activate") @QueryParam("user") Optional<String> queryUser) {
validator.checkForAdminAuthorization(user);
super.activate(slaveId, queryUser); super.activate(slaveId, queryUser);
} }


Expand Down

0 comments on commit 6792c16

Please sign in to comment.