Skip to content

Commit

Permalink
Merge pull request #18 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 0.4.0 - new flag on DNS command
  • Loading branch information
briskt authored Nov 16, 2023
2 parents 212912d + 742ee6c commit 943f1b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
51 changes: 32 additions & 19 deletions cmd/cli/multiregion/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
)

type DnsCommand struct {
cfClient *cloudflare.API
cfZone *cloudflare.ResourceContainer
domainName string
env string
failback bool
region string
region2 string
testMode bool
cfClient *cloudflare.API
cfZone *cloudflare.ResourceContainer
domainName string
env string
failback bool
includeCommon bool
region string
region2 string
testMode bool
}

type DnsValues struct {
Expand All @@ -36,36 +37,39 @@ type DnsValues struct {
}

func InitDnsCmd(parentCmd *cobra.Command) {
var failback bool
var failback, includeCommon bool

cmd := &cobra.Command{
Use: "dns",
Short: "DNS Failover and Failback",
Long: `Configure DNS CNAME values for primary or secondary region hostnames. Default is failover, use --failback to switch back to the primary region.`,
Run: func(cmd *cobra.Command, args []string) {
runDnsCommand(failback)
runDnsCommand(failback, includeCommon)
},
}
parentCmd.AddCommand(cmd)

cmd.PersistentFlags().BoolVar(&failback, "failback", false,
`set DNS records to switch back to primary`,
)
cmd.PersistentFlags().BoolVar(&includeCommon, "include-common", false,
`also set DNS records for services used by every IdP`,
)
}

func runDnsCommand(failback bool) {
func runDnsCommand(failback, includeCommon bool) {
pFlags := getPersistentFlags()

if pFlags.readOnlyMode {
fmt.Println("-- Read-only mode enabled --")
}

d := newDnsCommand(pFlags, failback)
d := newDnsCommand(pFlags, failback, includeCommon)

d.setDnsRecordValues(pFlags.idp)
}

func newDnsCommand(pFlags PersistentFlags, failback bool) *DnsCommand {
func newDnsCommand(pFlags PersistentFlags, failback, includeCommon bool) *DnsCommand {
d := DnsCommand{
testMode: pFlags.readOnlyMode,
domainName: viper.GetString(flags.DomainName),
Expand Down Expand Up @@ -98,6 +102,7 @@ func newDnsCommand(pFlags PersistentFlags, failback bool) *DnsCommand {
d.region2 = pFlags.secondaryRegion

d.failback = failback
d.includeCommon = includeCommon

return &d
}
Expand All @@ -119,10 +124,19 @@ func (d *DnsCommand) setDnsRecordValues(idpKey string) {
supportBotName = "watson"
}

dnsRecords := []struct {
type nameValuePair struct {
name string
value string
}{
}

dnsRecords := []nameValuePair{
// ECS services
{idpKey + "-pw-api", idpKey + "-pw-api-" + region},
{idpKey, idpKey + "-" + region},
{idpKey + "-sync", idpKey + "-sync-" + region},
}

common := []nameValuePair{
// "mfa-api" is the TOTP API, also known as serverless-mfa-api
{"mfa-api", "mfa-api-" + region},

Expand All @@ -131,11 +145,10 @@ func (d *DnsCommand) setDnsRecordValues(idpKey string) {

// this is the idp-support-bot API that is configured in the Slack API dashboard
{supportBotName, supportBotName + "-" + region},
}

// ECS services
{idpKey + "-pw-api", idpKey + "-pw-api-" + region},
{idpKey, idpKey + "-" + region},
{idpKey + "-sync", idpKey + "-sync-" + region},
if d.includeCommon {
dnsRecords = append(dnsRecords, common...)
}

for _, record := range dnsRecords {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -329,8 +329,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -340,8 +340,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down

0 comments on commit 943f1b9

Please sign in to comment.