// awsValidateSubnets validates that the given VPC and Subnet inputs are
// coherent, either statically in the case of a new VPC, or dynamically against
// an existing VPC.
awsValidateSubnets validates that the given VPC and Subnet inputs are
coherent, either statically in the case of a new VPC, or dynamically against
an existing VPC.
// awsValidateSubnets validates that the given VPC and Subnet inputs are // coherent either statically in the case of a new VPC or dynamically against // an existing VPC .
func awsValidateSubnetsHandler(w http.ResponseWriter, req *http.Request, _ *Context) error {
	input := struct {
		VpcCIDR        string           `json:"vpcCIDR"`
		PodCIDR        string           `json:"podCIDR"`
		ServiceCIDR    string           `json:"serviceCIDR"`
		PublicSubnets  []paws.VPCSubnet `json:"publicSubnets"`
		PrivateSubnets []paws.VPCSubnet `json:"privateSubnets"`
		ExistingVPCID  string           `json:"awsVpcId"`
	}{}
	if err := json.NewDecoder(req.Body).Decode(&input); err != nil {
		return newBadRequestError("Could not unmarshal input: %s", err)
	}
	type response struct {
		Message string `json:"message"`
		Valid   bool   `json:"valid"`
	}
	if input.ExistingVPCID == "" {
		if err := paws.ValidateSubnets(input.VpcCIDR, input.PublicSubnets); err != nil {
			return writeJSONResponse(w, req, http.StatusOK, response{err.Error(), false})
		}
		if err := paws.ValidateSubnets(input.VpcCIDR, input.PrivateSubnets); err != nil {
			return writeJSONResponse(w, req, http.StatusOK, response{err.Error(), false})
		}
		if err := paws.ValidateKubernetesCIDRs(input.VpcCIDR, input.PodCIDR, input.ServiceCIDR); err != nil {
			return writeJSONResponse(w, req, http.StatusOK, response{err.Error(), false})
		}
		return writeJSONResponse(w, req, http.StatusOK, response{"", true})
	}
	awsSession, err := awsSessionFromRequest(req)
	if err != nil {
		return fromAWSErr(err)
	}
	err = paws.CheckSubnetsAgainstExistingVPC(awsSession, input.ExistingVPCID, input.PublicSubnets, input.PrivateSubnets)
	if err != nil {
		return writeJSONResponse(w, req, http.StatusOK, response{err.Error(), false})
	}
	err = paws.CheckKubernetesCIDRs(awsSession, input.ExistingVPCID, input.PodCIDR, input.ServiceCIDR)
	if err != nil {
		return writeJSONResponse(w, req, http.StatusOK, response{err.Error(), false})
	}
	return writeJSONResponse(w, req, http.StatusOK, response{"", true})
}
func awsValidateSubnetsHandler ( w http . ResponseWriter , req * http . Request , _ * Context ) error { input := struct { VpcCIDR string `json:"vpcCIDR"` PodCIDR string `json:"podCIDR"` ServiceCIDR string `json:"serviceCIDR"` PublicSubnets [ ] paws . VPCSubnet `json:"publicSubnets"` PrivateSubnets [ ] paws . VPCSubnet `json:"privateSubnets"` ExistingVPCID string `json:"awsVpcId"` } { } if err := json . NewDecoder ( req . Body ) . Decode ( & input ) ; err != nil { return newBadRequestError ( " " , err ) } type response struct { Message string `json:"message"` Valid bool `json:"valid"` } if input . ExistingVPCID == " " { if err := paws . ValidateSubnets ( input . VpcCIDR , input . PublicSubnets ) ; err != nil { return writeJSONResponse ( w , req , http . StatusOK , response { err . Error ( ) , false } ) } if err := paws . ValidateSubnets ( input . VpcCIDR , input . PrivateSubnets ) ; err != nil { return writeJSONResponse ( w , req , http . StatusOK , response { err . Error ( ) , false } ) } if err := paws . ValidateKubernetesCIDRs ( input . VpcCIDR , input . PodCIDR , input . ServiceCIDR ) ; err != nil { return writeJSONResponse ( w , req , http . StatusOK , response { err . Error ( ) , false } ) } return writeJSONResponse ( w , req , http . StatusOK , response { " " , true } ) } awsSession , err := awsSessionFromRequest ( req ) if err != nil { return fromAWSErr ( err ) } err = paws . CheckSubnetsAgainstExistingVPC ( awsSession , input . ExistingVPCID , input . PublicSubnets , input . PrivateSubnets ) if err != nil { return writeJSONResponse ( w , req , http . StatusOK , response { err . Error ( ) , false } ) } err = paws . CheckKubernetesCIDRs ( awsSession , input . ExistingVPCID , input . PodCIDR , input . ServiceCIDR ) if err != nil { return writeJSONResponse ( w , req , http . StatusOK , response { err . Error ( ) , false } ) } return writeJSONResponse ( w , req , http . StatusOK , response { " " , true } ) }
awsValidateSubnets validates that the given VPC and Subnet inputs are
coherent, either statically in the case of a new VPC, or dynamically against
an existing VPC.
awsValidateSubnets validates that the given VPC and Subnet inputs are coherent either statically in the case of a new VPC or dynamically against an existing VPC .
// Statically validating a new VPC. // # Validate private subnets. // # Validate public subnets. // # Validate Kubernetes CIDRs. // Dynamically check against an existing VPC. // # Check all subnets against the existing VPC. // # Check the Kubernetes CIDRs.