Skip to content

Commit

Permalink
Change naming of ISS route accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
CDellaGiusta authored and mcalmer committed Feb 22, 2025
1 parent 0992dc8 commit a9ec011
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
32 changes: 16 additions & 16 deletions java/code/src/com/suse/manager/hub/HubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

package com.suse.manager.hub;

import static com.suse.manager.hub.HubSparkHelper.allowingOnlyHub;
import static com.suse.manager.hub.HubSparkHelper.allowingOnlyRegistered;
import static com.suse.manager.hub.HubSparkHelper.allowingOnlyUnregistered;
import static com.suse.manager.hub.HubSparkHelper.onlyFromHub;
import static com.suse.manager.hub.HubSparkHelper.onlyFromRegistered;
import static com.suse.manager.hub.HubSparkHelper.onlyFromUnregistered;
import static com.suse.manager.hub.HubSparkHelper.usingTokenAuthentication;
import static com.suse.manager.webui.utils.SparkApplicationHelper.asJson;
import static com.suse.manager.webui.utils.SparkApplicationHelper.badRequest;
Expand Down Expand Up @@ -90,26 +90,26 @@ public HubController(HubManager hubManagerIn) {
*/
public void initRoutes() {
post("/hub/ping", asJson(usingTokenAuthentication(this::ping)));
post("/hub/sync/deregister", asJson(usingTokenAuthentication(allowingOnlyRegistered(this::deregister))));
post("/hub/sync/registerHub", asJson(usingTokenAuthentication(allowingOnlyUnregistered(this::registerHub))));
post("/hub/sync/replaceTokens", asJson(usingTokenAuthentication(allowingOnlyHub(this::replaceTokens))));
post("/hub/sync/storeCredentials", asJson(usingTokenAuthentication(allowingOnlyHub(this::storeCredentials))));
post("/hub/sync/setHubDetails", asJson(usingTokenAuthentication(allowingOnlyHub(this::setHubDetails))));
get("/hub/managerinfo", asJson(usingTokenAuthentication(allowingOnlyHub(this::getManagerInfo))));
post("/hub/sync/deregister", asJson(usingTokenAuthentication(onlyFromRegistered(this::deregister))));
post("/hub/sync/registerHub", asJson(usingTokenAuthentication(onlyFromUnregistered(this::registerHub))));
post("/hub/sync/replaceTokens", asJson(usingTokenAuthentication(onlyFromHub(this::replaceTokens))));
post("/hub/sync/storeCredentials", asJson(usingTokenAuthentication(onlyFromHub(this::storeCredentials))));
post("/hub/sync/setHubDetails", asJson(usingTokenAuthentication(onlyFromHub(this::setHubDetails))));
get("/hub/managerinfo", asJson(usingTokenAuthentication(onlyFromHub(this::getManagerInfo))));
post("/hub/storeReportDbCredentials",
asJson(usingTokenAuthentication(allowingOnlyHub(this::setReportDbCredentials))));
asJson(usingTokenAuthentication(onlyFromHub(this::setReportDbCredentials))));
post("/hub/removeReportDbCredentials",
asJson(usingTokenAuthentication(allowingOnlyHub(this::removeReportDbCredentials))));
asJson(usingTokenAuthentication(onlyFromHub(this::removeReportDbCredentials))));
get("/hub/listAllPeripheralOrgs",
asJson(usingTokenAuthentication(allowingOnlyHub(this::listAllPeripheralOrgs))));
asJson(usingTokenAuthentication(onlyFromHub(this::listAllPeripheralOrgs))));
get("/hub/listAllPeripheralChannels",
asJson(usingTokenAuthentication(allowingOnlyHub(this::listAllPeripheralChannels))));
asJson(usingTokenAuthentication(onlyFromHub(this::listAllPeripheralChannels))));
post("/hub/addVendorChannels",
asJson(usingTokenAuthentication(allowingOnlyHub(this::addVendorChannels))));
asJson(usingTokenAuthentication(onlyFromHub(this::addVendorChannels))));
post("/hub/addCustomChannels",
asJson(usingTokenAuthentication(allowingOnlyHub(this::addCustomChannels))));
asJson(usingTokenAuthentication(onlyFromHub(this::addCustomChannels))));
post("/hub/modifyCustomChannels",
asJson(usingTokenAuthentication(allowingOnlyHub(this::modifyCustomChannels))));
asJson(usingTokenAuthentication(onlyFromHub(this::modifyCustomChannels))));
}

private String setHubDetails(Request request, Response response, IssAccessToken accessToken) {
Expand Down
18 changes: 9 additions & 9 deletions java/code/src/com/suse/manager/hub/HubSparkHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,38 +114,38 @@ else if (!fqdn.equals(issuedToken.getServerFqdn())) {
* @param route the route
* @return the route
*/
public static RouteWithHubToken allowingOnlyHub(RouteWithHubToken route) {
return allowingOnly(List.of(IssRole.HUB), route);
public static RouteWithHubToken onlyFromHub(RouteWithHubToken route) {
return onlyFrom(List.of(IssRole.HUB), route);
}

/**
* Use in ISS routes only accessible from a peripheral
* @param route the route
* @return the route
*/
public static RouteWithHubToken allowingOnlyPeripheral(RouteWithHubToken route) {
return allowingOnly(List.of(IssRole.PERIPHERAL), route);
public static RouteWithHubToken onlyFromPeripheral(RouteWithHubToken route) {
return onlyFrom(List.of(IssRole.PERIPHERAL), route);
}

/**
* Use in ISS routes only accessible from a registered server
* @param route the route
* @return the route
*/
public static RouteWithHubToken allowingOnlyRegistered(RouteWithHubToken route) {
return allowingOnly(List.of(IssRole.HUB, IssRole.PERIPHERAL), route);
public static RouteWithHubToken onlyFromRegistered(RouteWithHubToken route) {
return onlyFrom(List.of(IssRole.HUB, IssRole.PERIPHERAL), route);
}

/**
* Use in ISS routes only accessible from an unregistered server
* @param route the route
* @return the route
*/
public static RouteWithHubToken allowingOnlyUnregistered(RouteWithHubToken route) {
return allowingOnly(List.of(), route);
public static RouteWithHubToken onlyFromUnregistered(RouteWithHubToken route) {
return onlyFrom(List.of(), route);
}

private static RouteWithHubToken allowingOnly(List<IssRole> allowedRoles, RouteWithHubToken route) {
private static RouteWithHubToken onlyFrom(List<IssRole> allowedRoles, RouteWithHubToken route) {
return (request, response, issAccessToken) -> {
String fqdn = issAccessToken.getServerFqdn();
Optional<IssHub> issHub = HUB_FACTORY.lookupIssHubByFqdn(fqdn);
Expand Down

0 comments on commit a9ec011

Please sign in to comment.