Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ Go to browser -> AWS console -> login -> Route53 -> find the hosted zone -> find

- The CLI will use the default AWS login methods and query the Route53 API in a smart way to find the record.
- By default the nameservers will be verified against the real world via Dig implementation (turn off via `--skip-ns`).
- By using `-R` the query will continue recursivly and expand all the records until the "leaf".
- If the record value is an AWS resource it will output the URL to AWS console for quick access.
- Search recursivly and expand all the records until the "leaf".
- Direct Web URL to the resource from the terminal.

## With `route53-cli`:

**Input**

```bash
r53 -R -r 'app.foo.goo.website.com'
r53 -r 'app.foo.goo.website.com'
```

**Output**
Expand Down
2 changes: 1 addition & 1 deletion aws_utils/route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (r53m *Route53Manager) getRecordsRecursive(maxDepth int, recordName string,
result, err := r53m.getRecordsRecursive(maxDepth-1, a, skipNSVerification, checkedRecord)

if err != nil {
l.WithError(err).Warn("stopping recurse record set on alias no results")
l.Debugf("stopping recurse record set on alias no results %s", err.Error())
continue
}

Expand Down
6 changes: 4 additions & 2 deletions aws_utils/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"strings"

"github.com/aws/aws-sdk-go/aws"
route53 "github.com/aws/aws-sdk-go/service/route53"
)

Expand Down Expand Up @@ -41,6 +42,7 @@ func CheckRoutableAWSTarget(r *route53.ResourceRecordSet) (string, bool) {
if r.AliasTarget == nil || r.AliasTarget.DNSName == nil {
return "", false
}

dns := *r.AliasTarget.DNSName

for _, st := range SupportedTarget {
Expand All @@ -65,10 +67,10 @@ func GenerateWebURL(r *route53.ResourceRecordSet) (string, error) {

// https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LoadBalancers:search=some-alb-name;sort=loadBalancerName
func GetLBWebURL(dnsIdentifier string, r *route53.ResourceRecordSet) string {
record := *r.AliasTarget.DNSName
record := aws.StringValue(r.AliasTarget.DNSName)
record = strings.TrimRight(record, ".")

region := *r.Region
region := aws.StringValue(r.Region)
searchQuery := record
// parse region
splitted := strings.Split(record, ".")
Expand Down
52 changes: 52 additions & 0 deletions aws_utils/urls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package aws_utils_test

import (
awsu "r53/aws_utils"
"testing"

route53 "github.com/aws/aws-sdk-go/service/route53"
"github.com/stretchr/testify/assert"
)

func newRecSet(dns, region string) *route53.ResourceRecordSet {
return &route53.ResourceRecordSet{
Region: &region,
AliasTarget: &route53.AliasTarget{
DNSName: &dns,
},
}
}

func TestGenerateWebURL(t *testing.T) {
//r.AliasTarget.DNSName
cases := []struct {
Record *route53.ResourceRecordSet
ShouldError bool
ExpectedOutput string
}{
{
Record: newRecSet("", ""),
ShouldError: true,
ExpectedOutput: "",
},
{
Record: newRecSet("dualstack.my-production-alb.eu-east-1.elb.amazonaws.com.", "eu-east-1"),
ShouldError: false,
ExpectedOutput: "https://console.aws.amazon.com/ec2/v2/home?region=eu-east-1#LoadBalancers:search=my-production-alb.eu-east-1.elb.amazonaws.com;sort=loadBalancerName",
},
{
Record: newRecSet("some-rec-ok-eu-east-1.similarweb.com.", "eu-east-1"),
ShouldError: true,
ExpectedOutput: "",
},
}

for _, c := range cases {
url, err := awsu.GenerateWebURL(c.Record)

isError := err != nil

assert.Equal(t, c.ShouldError, isError, "error comparison dont match")
assert.Equal(t, url, c.ExpectedOutput, "url output not as expected")
}
}
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
AppVersion = "0.3.0"
AppVersion = "0.3.1"
)

var cfgFile string
Expand Down Expand Up @@ -87,7 +87,8 @@ func ExecuteR53() {

depth := *recusiveSearchMaxDepth
if !*recursiveSearch {
depth = 1
// default recurse 3 depth max
depth = 3
}

results, err := api.GetRecordSetAliasesRecursive(depth, recordInput, skipNSVerification, nil)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ require (
github.com/smartystreets/assertions v1.0.0 // indirect
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)