public HashMap handleRequest()

in WorkingFromHome/ClientConnection/AdConnectorCustomResource/src/main/java/com/ilmlf/adconnector/customresource/OnEventHandler.java [36:92]


  public HashMap<String, Object> handleRequest(
      CloudFormationCustomResourceEvent event, Context context) {

    System.out.println("onEventHandler event: " + event.toString());
    Map<String, Object> properties = event.getResourceProperties();
    String secret = getSecretValue(properties.get("secretId").toString());

    String directoryId = event.getPhysicalResourceId();
    System.out.println("action:" + event.getRequestType() + " AD Connector");
    String requestType = event.getRequestType();
    switch (requestType) {
      /*
        For create requests, attempt to connect to the on-premise Active Directory
          using the AWS Directory Service.
      */
      case "Create":
        directoryId =
            directoryClient
                .connectDirectory(
                    ConnectDirectoryRequest.builder()
                        .connectSettings(
                            DirectoryConnectSettings.builder()
                                .customerUserName("Admin")
                                .customerDnsIps((Collection<String>) properties.get("dnsIps"))
                                .subnetIds((Collection<String>) properties.get("subnetIds"))
                                .vpcId((String) properties.get("vpcId"))
                                .build())
                        .name(properties.get("domainName").toString())
                        .password(secret)
                        .size("Small")
                        .build())
                .directoryId();
        break;
      case "Update":
        break;
      /*
        For delete requests, remove the connection to the on-premise Active Directory within the
          AWS Directory service
      */
      case "Delete":
        directoryClient.deleteDirectory(
            DeleteDirectoryRequest.builder().directoryId(directoryId).build());
        break;
      default:
        throw new InvalidParameterException("Invalid RequestType " + requestType);
    }

    HashMap<String, Object> response = new HashMap<>();
    response.put("PhysicalResourceId", directoryId);
    response.put("PhysicalResourceId", directoryId);
    response.put("RequestType", event.getRequestType());

    System.out.println("result: Successfully " + event.getRequestType() + " AD Connector.");
    System.out.println("response: " + response);

    return response;
  }