mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(ram): emulate organization sharing side effects (#3279)
* fix: emulate RAM organization sharing side effects * test(ram): add SDK organization sharing coverage
This commit is contained in:
1 parent
ed116ae815
commit
d322d48bd5
7 files changed
+139
-4
No files matched your search
@@ -87,7 +87,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
private static final String SERVICE_LINKED_ROLE_NAME_PREFIX = "AWSServiceRoleFor";
|
||||
private static final Map<String, String> SERVICE_LINKED_ROLE_NAMES = Map.of(
|
||||
"autoscaling.amazonaws.com", "AutoScaling",
|
||||
"cloud9.amazonaws.com", "AWSCloud9"
|
||||
"cloud9.amazonaws.com", "AWSCloud9",
|
||||
"ram.amazonaws.com", "ResourceAccessManager"
|
||||
);
|
||||
private static final String AMAZONAWS_DOMAIN = ".amazonaws.com";
|
||||
/** AWSServiceName as AWS constrains it: 1-128 characters of {@code [\w+=,.@-]}. */
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.github.hectorvent.floci.services.organizations.OrganizationsService;
|
||||
import io.github.hectorvent.floci.services.ram.model.PrincipalAssociation;
|
||||
import io.github.hectorvent.floci.services.ram.model.ResourceShare;
|
||||
import io.github.hectorvent.floci.services.ram.model.ResourceShareInvitation;
|
||||
@@ -48,20 +50,31 @@ public class RamController {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final ObjectReader requestReader;
|
||||
private final RegionResolver regionResolver;
|
||||
private final OrganizationsService organizationsService;
|
||||
private final IamService iamService;
|
||||
|
||||
@Inject
|
||||
public RamController(RamService service, ObjectMapper objectMapper, RegionResolver regionResolver) {
|
||||
public RamController(RamService service, ObjectMapper objectMapper, RegionResolver regionResolver,
|
||||
OrganizationsService organizationsService, IamService iamService) {
|
||||
this.service = service;
|
||||
this.objectMapper = objectMapper;
|
||||
this.requestReader = objectMapper.reader()
|
||||
.with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
|
||||
this.regionResolver = regionResolver;
|
||||
this.organizationsService = organizationsService;
|
||||
this.iamService = iamService;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/enablesharingwithawsorganization")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response enableSharingWithAwsOrganization() {
|
||||
String callerAccountId = regionResolver.getAccountId();
|
||||
organizationsService.enableAWSServiceAccess(callerAccountId, "ram.amazonaws.com");
|
||||
if (iamService.findRole(callerAccountId, "AWSServiceRoleForResourceAccessManager").isEmpty()) {
|
||||
iamService.createServiceLinkedRole("ram.amazonaws.com", null,
|
||||
"Allows AWS Resource Access Manager to access AWS Organizations on your behalf.");
|
||||
}
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("returnValue", service.enableSharingWithAwsOrganization());
|
||||
return Response.ok(response).build();
|
||||
|
||||
Reference in new issue
Block a user