|
22 | 22 | import com.netflix.spinnaker.fiat.model.resources.Account;
|
23 | 23 | import com.netflix.spinnaker.fiat.model.resources.Application;
|
24 | 24 | import com.netflix.spinnaker.fiat.model.resources.ResourceType;
|
| 25 | +import com.netflix.spinnaker.fiat.model.resources.ServiceAccount; |
25 | 26 | import com.netflix.spinnaker.fiat.permissions.PermissionsRepository;
|
26 | 27 | import io.swagger.annotations.ApiOperation;
|
27 | 28 | import org.springframework.beans.factory.annotation.Autowired;
|
@@ -92,6 +93,53 @@ public Account.View getUserAccount(@PathVariable String userId, @PathVariable St
|
92 | 93 | .orElseThrow(NotFoundException::new);
|
93 | 94 | }
|
94 | 95 |
|
| 96 | + @RequestMapping(value = "/{userId:.+}/applications", method = RequestMethod.GET) |
| 97 | + public Set<Application.View> getUserApplications(@PathVariable String userId) { |
| 98 | + return permissionsRepository.get(ControllerSupport.convert(userId)) |
| 99 | + .orElseThrow(NotFoundException::new) |
| 100 | + .getApplications() |
| 101 | + .stream() |
| 102 | + .map(Application::getView) |
| 103 | + .collect(Collectors.toSet()); |
| 104 | + } |
| 105 | + |
| 106 | + @RequestMapping(value = "/{userId:.+}/applications/{applicationName:.+}", method = RequestMethod.GET) |
| 107 | + public Application.View getUserApplication(@PathVariable String userId, @PathVariable String applicationName) { |
| 108 | + return permissionsRepository.get(ControllerSupport.convert(userId)) |
| 109 | + .orElseThrow(NotFoundException::new) |
| 110 | + .getApplications() |
| 111 | + .stream() |
| 112 | + .filter(application -> applicationName.equalsIgnoreCase(application.getName())) |
| 113 | + .findFirst() |
| 114 | + .map(Application::getView) |
| 115 | + .orElseThrow(NotFoundException::new); |
| 116 | + } |
| 117 | + |
| 118 | + @RequestMapping(value = "/{userId:.+}/serviceAccounts", method = RequestMethod.GET) |
| 119 | + public Set<ServiceAccount.View> getServiceAccounts(@PathVariable String userId) { |
| 120 | + return permissionsRepository.get(ControllerSupport.convert(userId)) |
| 121 | + .orElseThrow(NotFoundException::new) |
| 122 | + .getServiceAccounts() |
| 123 | + .stream() |
| 124 | + .map(ServiceAccount::getView) |
| 125 | + .collect(Collectors.toSet()); |
| 126 | + } |
| 127 | + |
| 128 | + @RequestMapping(value = "/{userId:.+}/serviceAccounts/{serviceAccountName:.+}", method = RequestMethod.GET) |
| 129 | + public ServiceAccount.View getServiceAccount(@PathVariable String userId, |
| 130 | + @PathVariable String serviceAccountName) { |
| 131 | + return permissionsRepository.get(ControllerSupport.convert(userId)) |
| 132 | + .orElseThrow(NotFoundException::new) |
| 133 | + .getServiceAccounts() |
| 134 | + .stream() |
| 135 | + .filter(serviceAccount -> |
| 136 | + serviceAccount.getName() |
| 137 | + .equalsIgnoreCase(ControllerSupport.convert(serviceAccountName))) |
| 138 | + .findFirst() |
| 139 | + .orElseThrow(NotFoundException::new) |
| 140 | + .getView(); |
| 141 | + } |
| 142 | + |
95 | 143 | @RequestMapping(value = "/{userId:.+}/{resourceType:.+}/{resourceName:.+}/{authorization:.+}", method = RequestMethod.GET)
|
96 | 144 | public void getUserAuthorization(@PathVariable String userId,
|
97 | 145 | @PathVariable String resourceType,
|
@@ -126,26 +174,4 @@ public void getUserAuthorization(@PathVariable String userId,
|
126 | 174 |
|
127 | 175 | response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
128 | 176 | }
|
129 |
| - |
130 |
| - @RequestMapping(value = "/{userId:.+}/applications", method = RequestMethod.GET) |
131 |
| - public Set<Application.View> getUserApplications(@PathVariable String userId) { |
132 |
| - return permissionsRepository.get(ControllerSupport.convert(userId)) |
133 |
| - .orElseThrow(NotFoundException::new) |
134 |
| - .getApplications() |
135 |
| - .stream() |
136 |
| - .map(Application::getView) |
137 |
| - .collect(Collectors.toSet()); |
138 |
| - } |
139 |
| - |
140 |
| - @RequestMapping(value = "/{userId:.+}/applications/{applicationName:.+}", method = RequestMethod.GET) |
141 |
| - public Application.View getUserApplication(@PathVariable String userId, @PathVariable String applicationName) { |
142 |
| - return permissionsRepository.get(ControllerSupport.convert(userId)) |
143 |
| - .orElseThrow(NotFoundException::new) |
144 |
| - .getApplications() |
145 |
| - .stream() |
146 |
| - .filter(application -> applicationName.equalsIgnoreCase(application.getName())) |
147 |
| - .findFirst() |
148 |
| - .map(Application::getView) |
149 |
| - .orElseThrow(NotFoundException::new); |
150 |
| - } |
151 | 177 | }
|
0 commit comments