// awsGetDomainInfoHandler returns the SOA record for a given zone.
awsGetDomainInfoHandler returns the SOA record for a given zone.
// awsGetDomainInfoHandler returns the SOA record for a given zone .
func awsGetDomainInfoHandler(w http.ResponseWriter, req *http.Request, _ *Context) error {
	req.Header.Set("Tectonic-Region", "us-east-1")
	awsSession, err := awsSessionFromRequest(req)
	if err != nil {
		return fromAWSErr(err)
	}
	input := struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	}{}
	if err := json.NewDecoder(req.Body).Decode(&input); err != nil {
		return newBadRequestError("Could not unmarshal input: %s", err)
	}
	response := struct {
		SoaTTL     int64    `json:"soaTTL"`
		SoaValue   string   `json:"soaValue"`
		Registered string   `json:"registered"`
		AWSNS      []string `json:"awsNS"`
		PublicNS   []string `json:"publicNS"`
	}{}
	var wg sync.WaitGroup
	done := make(chan struct{})
	errch := make(chan error)
	wg.Add(4)
	go func() {
		wg.Wait()
		close(done)
	}()
	go func() {
		defer wg.Done()
		records, err := paws.GetHostedZoneRecords(awsSession, input.ID, input.Name, "SOA", 1)
		if err != nil {
			errch <- err
			return
		}
		if len(records) == 1 {
			response.SoaTTL = aws.Int64Value(records[0].TTL)
			response.SoaValue = aws.StringValue(records[0].ResourceRecords[0].Value)
		}
	}()
	go func() {
		defer wg.Done()
		records, err := paws.GetHostedZoneRecords(awsSession, input.ID, input.Name, "NS", 10)
		if err != nil {
			errch <- err
			return
		}
		if len(records) > 0 {
			domains := make([]string, len(records[0].ResourceRecords))
			for i, record := range records[0].ResourceRecords {
				domains[i] = aws.StringValue(record.Value)
			}
			sort.Strings(domains)
			response.AWSNS = domains
		}
	}()
	go func() {
		defer wg.Done()
		split := strings.Split(input.Name, ".")
		if len(split) < 2 {
			response.Registered = route53domains.DomainAvailabilityDontKnow
			return
		}
		domainName := strings.Join(split[len(split)-2:], ".")
		availability, err := route53domains.New(awsSession).CheckDomainAvailability(
			&route53domains.CheckDomainAvailabilityInput{
				DomainName: aws.String(domainName),
			},
		)
		if err != nil {
			errch <- err
			return
		}
		response.Registered = aws.StringValue(availability.Availability)
	}()
	go func() {
		defer wg.Done()
		nsRecords, err := net.LookupNS(input.Name)
		if err != nil {
			errch <- err
			return
		}
		domains := make([]string, len(nsRecords))
		for i, ns := range nsRecords {
			domains[i] = ns.Host
		}
		sort.Strings(domains)
		response.PublicNS = domains
	}()
	select {
	case <-done:
		return writeJSONResponse(w, req, http.StatusOK, response)
	case <-errch:
		return fromAWSErr(err)
	case <-time.After(10 * time.Second):
		return newError(http.StatusRequestTimeout, "Time-out while querying domain informations")
	}
}
func awsGetDomainInfoHandler ( w http . ResponseWriter , req * http . Request , _ * Context ) error { req . Header . Set ( " " , " " ) awsSession , err := awsSessionFromRequest ( req ) if err != nil { return fromAWSErr ( err ) } input := struct { ID string `json:"id"` Name string `json:"name"` } { } if err := json . NewDecoder ( req . Body ) . Decode ( & input ) ; err != nil { return newBadRequestError ( " " , err ) } response := struct { SoaTTL int64 `json:"soaTTL"` SoaValue string `json:"soaValue"` Registered string `json:"registered"` AWSNS [ ] string `json:"awsNS"` PublicNS [ ] string `json:"publicNS"` } { } var wg sync . WaitGroup done := make ( chan struct { } ) errch := make ( chan error ) wg . Add ( 4 ) go func ( ) { wg . Wait ( ) close ( done ) } ( ) go func ( ) { defer wg . Done ( ) records , err := paws . GetHostedZoneRecords ( awsSession , input . ID , input . Name , " " , 1 ) if err != nil { errch <- err return } if len ( records ) == 1 { response . SoaTTL = aws . Int64Value ( records [ 0 ] . TTL ) response . SoaValue = aws . StringValue ( records [ 0 ] . ResourceRecords [ 0 ] . Value ) } } ( ) go func ( ) { defer wg . Done ( ) records , err := paws . GetHostedZoneRecords ( awsSession , input . ID , input . Name , " " , 10 ) if err != nil { errch <- err return } if len ( records ) > 0 { domains := make ( [ ] string , len ( records [ 0 ] . ResourceRecords ) ) for i , record := range records [ 0 ] . ResourceRecords { domains [ i ] = aws . StringValue ( record . Value ) } sort . Strings ( domains ) response . AWSNS = domains } } ( ) go func ( ) { defer wg . Done ( ) split := strings . Split ( input . Name , " " ) if len ( split ) < 2 { response . Registered = route53domains . DomainAvailabilityDontKnow return } domainName := strings . Join ( split [ len ( split ) - 2 : ] , " " ) availability , err := route53domains . New ( awsSession ) . CheckDomainAvailability ( & route53domains . CheckDomainAvailabilityInput { DomainName : aws . String ( domainName ) , } , ) if err != nil { errch <- err return } response . Registered = aws . StringValue ( availability . Availability ) } ( ) go func ( ) { defer wg . Done ( ) nsRecords , err := net . LookupNS ( input . Name ) if err != nil { errch <- err return } domains := make ( [ ] string , len ( nsRecords ) ) for i , ns := range nsRecords { domains [ i ] = ns . Host } sort . Strings ( domains ) response . PublicNS = domains } ( ) select { case <- done : return writeJSONResponse ( w , req , http . StatusOK , response ) case <- errch : return fromAWSErr ( err ) case <- time . After ( 10 * time . Second ) : return newError ( http . StatusRequestTimeout , " " ) } }
awsGetDomainInfoHandler returns the SOA record for a given zone.
awsGetDomainInfoHandler returns the SOA record for a given zone .
// Read the SOA Value/TTL. // Read the defined nameservers. // Verify that the domain is registered. // Get the nameservers we see being set for the domain.