-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from soracom/dont-store-credential
add flags to prevent the configuration from persisting on local file system
- Loading branch information
Showing
12 changed files
with
120 additions
and
38 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,88 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net" | ||
"os" | ||
"strings" | ||
|
||
"github.com/soracom/soratun" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
mtu int | ||
persistentKeepalive int | ||
additionalAllowedIPs string | ||
readStdin bool | ||
) | ||
|
||
func upCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
cmd := &cobra.Command{ | ||
Use: "up", | ||
Aliases: []string{"u"}, | ||
Short: "Setup SORACOM Arc interface", | ||
Args: cobra.NoArgs, | ||
PreRun: initSoratun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if readStdin { | ||
b, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
log.Fatalf("Failed to read configuration from stdin: %v", err) | ||
} | ||
|
||
var config soratun.Config | ||
err = json.Unmarshal(b, &config) | ||
if err != nil { | ||
log.Fatalf("Failed to read configuration from stdin: %v", err) | ||
} | ||
Config = &config | ||
} else { | ||
initSoratun(cmd, args) | ||
} | ||
|
||
// override only if the flag was explicitly set | ||
if cmd.Flags().Changed("mtu") { | ||
Config.Mtu = mtu | ||
} | ||
|
||
if cmd.Flags().Changed("persistent-keepalive") { | ||
Config.PersistentKeepalive = persistentKeepalive | ||
} | ||
|
||
if Config.ArcSession == nil { | ||
log.Fatal("Failed to determine connection information. Please bootstrap or create a new session from the user console.") | ||
} | ||
|
||
if additionalAllowedIPs != "" { | ||
for _, s := range strings.Split(additionalAllowedIPs, ",") { | ||
_, ipnet, err := net.ParseCIDR(strings.TrimSpace(s)) | ||
if err != nil { | ||
log.Fatalf("Invalid CIDR is set for \"--additional-allowd-ips\": %v", err) | ||
} | ||
Config.ArcSession.ArcAllowedIPs = append(Config.ArcSession.ArcAllowedIPs, &soratun.IPNet{ | ||
IP: ipnet.IP, | ||
Mask: ipnet.Mask, | ||
}) | ||
} | ||
} | ||
|
||
if v := os.Getenv("SORACOM_VERBOSE"); v != "" { | ||
fmt.Println("--- WireGuard configuration ----------------------") | ||
dumpWireGuardConfig(true) | ||
fmt.Println("--- End of WireGuard configuration ---------------") | ||
fmt.Fprintln(os.Stderr, "--- WireGuard configuration ----------------------") | ||
dumpWireGuardConfig(true, os.Stderr) | ||
fmt.Fprintln(os.Stderr, "--- End of WireGuard configuration ---------------") | ||
} | ||
|
||
soratun.Up(ctx, Config) | ||
}, | ||
} | ||
|
||
cmd.Flags().IntVar(&mtu, "mtu", soratun.DefaultMTU, "MTU for the interface, which will override arc.json#mtu value") | ||
cmd.Flags().IntVar(&persistentKeepalive, "persistent-keepalive", soratun.DefaultPersistentKeepaliveInterval, "WireGuard `PersistentKeepalive` for the SORACOM Arc server, which will override arc.json#persistentKeepalive value") | ||
cmd.Flags().StringVar(&additionalAllowedIPs, "additional-allowed-ips", "", "Comma separated string of additional WireGuard allowed CIDRs, which will be added to arc.json#additionalAllowedIPs array") | ||
cmd.Flags().BoolVar(&readStdin, "read-stdin", false, "read configuration from stdin, ignoring --config setting") | ||
|
||
return cmd | ||
} |
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