-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d38491f
commit bfe821f
Showing
6 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
/.idea | ||
/keypair.json | ||
dist/ | ||
/bootstrap | ||
/dyndns-server-lambda.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build aws | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/rs/zerolog/log" | ||
conf2 "github.com/soerenschneider/dyndns/conf" | ||
"github.com/soerenschneider/dyndns/internal/common" | ||
server2 "github.com/soerenschneider/dyndns/server" | ||
"github.com/soerenschneider/dyndns/server/dns" | ||
) | ||
|
||
const defaultRegion = "us-east-1" | ||
|
||
var propagator dns.Propagator | ||
var server *server2.Server | ||
|
||
func init() { | ||
region := os.Getenv("AWS_REGION") | ||
if region == "" { | ||
region = defaultRegion | ||
} | ||
|
||
conf := conf2.GetDefaultServerConfig() | ||
if err := conf2.ParseEnvVariables(conf); err != nil { | ||
log.Fatal().Err(err).Msg("could not parse config") | ||
} | ||
|
||
var err error | ||
propagator, err = dns.NewRoute53Propagator(conf.HostedZoneId, nil) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("could not build propagator") | ||
} | ||
|
||
c := make(chan common.UpdateRecordRequest) | ||
server, err = server2.NewServer(*conf, propagator, c, nil) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("could not build server") | ||
} | ||
} | ||
|
||
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | ||
payload := common.UpdateRecordRequest{} | ||
if err := json.Unmarshal([]byte(request.Body), &payload); err != nil { | ||
return events.APIGatewayProxyResponse{ | ||
Body: "could not parse json", | ||
StatusCode: 400, | ||
}, err | ||
} | ||
|
||
if err := server.HandlePropagateRequest(payload); err != nil { | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: 500, | ||
}, err | ||
} | ||
|
||
return events.APIGatewayProxyResponse{ | ||
StatusCode: 200, | ||
}, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters