good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
653b7e95
Unverified
Commit
653b7e95
authored
4 years ago
by
Felix Lange
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
cmd/devp2p: add dns nuke-route53 command (#22695)
parent
42465651
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/devp2p/dns_route53.go
+44
-11
44 additions, 11 deletions
cmd/devp2p/dns_route53.go
cmd/devp2p/dnscmd.go
+30
-5
30 additions, 5 deletions
cmd/devp2p/dnscmd.go
with
74 additions
and
16 deletions
cmd/devp2p/dns_route53.go
+
44
−
11
View file @
653b7e95
...
...
@@ -107,22 +107,48 @@ func (c *route53Client) deploy(name string, t *dnsdisc.Tree) error {
return
err
}
log
.
Info
(
fmt
.
Sprintf
(
"Found %d TXT records"
,
len
(
existing
)))
records
:=
t
.
ToTXT
(
name
)
changes
:=
c
.
computeChanges
(
name
,
records
,
existing
)
// Submit to API.
comment
:=
fmt
.
Sprintf
(
"enrtree update of %s at seq %d"
,
name
,
t
.
Seq
())
return
c
.
submitChanges
(
changes
,
comment
)
}
// deleteDomain removes all TXT records of the given domain.
func
(
c
*
route53Client
)
deleteDomain
(
name
string
)
error
{
if
err
:=
c
.
checkZone
(
name
);
err
!=
nil
{
return
err
}
// Compute DNS changes.
existing
,
err
:=
c
.
collectRecords
(
name
)
if
err
!=
nil
{
return
err
}
log
.
Info
(
fmt
.
Sprintf
(
"Found %d TXT records"
,
len
(
existing
)))
changes
:=
makeDeletionChanges
(
existing
,
nil
)
// Submit to API.
comment
:=
"enrtree delete of "
+
name
return
c
.
submitChanges
(
changes
,
comment
)
}
// submitChanges submits the given DNS changes to Route53.
func
(
c
*
route53Client
)
submitChanges
(
changes
[]
types
.
Change
,
comment
string
)
error
{
if
len
(
changes
)
==
0
{
log
.
Info
(
"No DNS changes needed"
)
return
nil
}
// Submit all change batches.
var
err
error
batches
:=
splitChanges
(
changes
,
route53ChangeSizeLimit
,
route53ChangeCountLimit
)
changesToCheck
:=
make
([]
*
route53
.
ChangeResourceRecordSetsOutput
,
len
(
batches
))
for
i
,
changes
:=
range
batches
{
log
.
Info
(
fmt
.
Sprintf
(
"Submitting %d changes to Route53"
,
len
(
changes
)))
batch
:=
&
types
.
ChangeBatch
{
Changes
:
changes
,
Comment
:
aws
.
String
(
fmt
.
Sprintf
(
"
enrtree update %d/%d of %s at seq %d"
,
i
+
1
,
len
(
batches
)
,
name
,
t
.
Seq
()
)),
Comment
:
aws
.
String
(
fmt
.
Sprintf
(
"
%s (%d/%d)"
,
comment
,
i
+
1
,
len
(
batches
))),
}
req
:=
&
route53
.
ChangeResourceRecordSetsInput
{
HostedZoneId
:
&
c
.
zoneID
,
ChangeBatch
:
batch
}
changesToCheck
[
i
],
err
=
c
.
api
.
ChangeResourceRecordSets
(
context
.
TODO
(),
req
)
...
...
@@ -151,7 +177,6 @@ func (c *route53Client) deploy(name string, t *dnsdisc.Tree) error {
time
.
Sleep
(
30
*
time
.
Second
)
}
}
return
nil
}
...
...
@@ -186,7 +211,8 @@ func (c *route53Client) findZoneID(name string) (string, error) {
return
""
,
errors
.
New
(
"can't find zone ID for "
+
name
)
}
// computeChanges creates DNS changes for the given record.
// computeChanges creates DNS changes for the given set of DNS discovery records.
// The 'existing' arg is the set of records that already exist on Route53.
func
(
c
*
route53Client
)
computeChanges
(
name
string
,
records
map
[
string
]
string
,
existing
map
[
string
]
recordSet
)
[]
types
.
Change
{
// Convert all names to lowercase.
lrecords
:=
make
(
map
[
string
]
string
,
len
(
records
))
...
...
@@ -223,16 +249,23 @@ func (c *route53Client) computeChanges(name string, records map[string]string, e
}
// Iterate over the old records and delete anything stale.
for
path
,
set
:=
range
existing
{
if
_
,
ok
:=
records
[
path
];
ok
{
changes
=
append
(
changes
,
makeDeletionChanges
(
existing
,
records
)
...
)
// Ensure changes are in the correct order.
sortChanges
(
changes
)
return
changes
}
// makeDeletionChanges creates record changes which delete all records not contained in 'keep'.
func
makeDeletionChanges
(
records
map
[
string
]
recordSet
,
keep
map
[
string
]
string
)
[]
types
.
Change
{
var
changes
[]
types
.
Change
for
path
,
set
:=
range
records
{
if
_
,
ok
:=
keep
[
path
];
ok
{
continue
}
// Stale entry, nuke it.
log
.
Info
(
fmt
.
Sprintf
(
"Deleting %s = %q"
,
path
,
strings
.
Join
(
set
.
values
,
""
)))
log
.
Info
(
fmt
.
Sprintf
(
"Deleting %s = %s"
,
path
,
strings
.
Join
(
set
.
values
,
""
)))
changes
=
append
(
changes
,
newTXTChange
(
"DELETE"
,
path
,
set
.
ttl
,
set
.
values
...
))
}
sortChanges
(
changes
)
return
changes
}
...
...
This diff is collapsed.
Click to expand it.
cmd/devp2p/dnscmd.go
+
30
−
5
View file @
653b7e95
...
...
@@ -43,6 +43,7 @@ var (
dnsTXTCommand
,
dnsCloudflareCommand
,
dnsRoute53Command
,
dnsRoute53NukeCommand
,
},
}
dnsSyncCommand
=
cli
.
Command
{
...
...
@@ -84,6 +85,18 @@ var (
route53RegionFlag
,
},
}
dnsRoute53NukeCommand
=
cli
.
Command
{
Name
:
"nuke-route53"
,
Usage
:
"Deletes DNS TXT records of a subdomain on Amazon Route53"
,
ArgsUsage
:
"<domain>"
,
Action
:
dnsNukeRoute53
,
Flags
:
[]
cli
.
Flag
{
route53AccessKeyFlag
,
route53AccessSecretFlag
,
route53ZoneIDFlag
,
route53RegionFlag
,
},
}
)
var
(
...
...
@@ -174,6 +187,9 @@ func dnsSign(ctx *cli.Context) error {
return
nil
}
// directoryName returns the directory name of the given path.
// For example, when dir is "foo/bar", it returns "bar".
// When dir is ".", and the working directory is "example/foo", it returns "foo".
func
directoryName
(
dir
string
)
string
{
abs
,
err
:=
filepath
.
Abs
(
dir
)
if
err
!=
nil
{
...
...
@@ -182,7 +198,7 @@ func directoryName(dir string) string {
return
filepath
.
Base
(
abs
)
}
// dnsToTXT peforms dnsTXTCommand.
// dnsToTXT pe
r
forms dnsTXTCommand.
func
dnsToTXT
(
ctx
*
cli
.
Context
)
error
{
if
ctx
.
NArg
()
<
1
{
return
fmt
.
Errorf
(
"need tree definition directory as argument"
)
...
...
@@ -199,9 +215,9 @@ func dnsToTXT(ctx *cli.Context) error {
return
nil
}
// dnsToCloudflare peforms dnsCloudflareCommand.
// dnsToCloudflare pe
r
forms dnsCloudflareCommand.
func
dnsToCloudflare
(
ctx
*
cli
.
Context
)
error
{
if
ctx
.
NArg
()
<
1
{
if
ctx
.
NArg
()
!=
1
{
return
fmt
.
Errorf
(
"need tree definition directory as argument"
)
}
domain
,
t
,
err
:=
loadTreeDefinitionForExport
(
ctx
.
Args
()
.
Get
(
0
))
...
...
@@ -212,9 +228,9 @@ func dnsToCloudflare(ctx *cli.Context) error {
return
client
.
deploy
(
domain
,
t
)
}
// dnsToRoute53 peforms dnsRoute53Command.
// dnsToRoute53 pe
r
forms dnsRoute53Command.
func
dnsToRoute53
(
ctx
*
cli
.
Context
)
error
{
if
ctx
.
NArg
()
<
1
{
if
ctx
.
NArg
()
!=
1
{
return
fmt
.
Errorf
(
"need tree definition directory as argument"
)
}
domain
,
t
,
err
:=
loadTreeDefinitionForExport
(
ctx
.
Args
()
.
Get
(
0
))
...
...
@@ -225,6 +241,15 @@ func dnsToRoute53(ctx *cli.Context) error {
return
client
.
deploy
(
domain
,
t
)
}
// dnsNukeRoute53 performs dnsRoute53NukeCommand.
func
dnsNukeRoute53
(
ctx
*
cli
.
Context
)
error
{
if
ctx
.
NArg
()
!=
1
{
return
fmt
.
Errorf
(
"need domain name as argument"
)
}
client
:=
newRoute53Client
(
ctx
)
return
client
.
deleteDomain
(
ctx
.
Args
()
.
First
())
}
// loadSigningKey loads a private key in Ethereum keystore format.
func
loadSigningKey
(
keyfile
string
)
*
ecdsa
.
PrivateKey
{
keyjson
,
err
:=
ioutil
.
ReadFile
(
keyfile
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment