Skip to content

Commit

Permalink
Fix the reading of the SSH config. (#408)
Browse files Browse the repository at this point in the history
In particular, read the config once and with all the right
fields specified.
  • Loading branch information
spetrovic77 committed Jun 20, 2023
1 parent 9e2b34d commit 004abd4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 89 deletions.
2 changes: 1 addition & 1 deletion examples/collatz/colocated.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ colocate = [
]

[ssh]
locations_file = "./ssh_locations.txt"
locations = "./ssh_locations.txt"

[gke]
regions = ["us-west1"]
Expand Down
2 changes: 1 addition & 1 deletion examples/collatz/weaver.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ listeners.collatz = {address = "localhost:9000"}

[ssh]
listeners.collatz = {address = "localhost:9000"}
locations_file = "./ssh_locations.txt"
locations = "./ssh_locations.txt"

[gke]
regions = ["us-west1"]
Expand Down
21 changes: 4 additions & 17 deletions internal/tool/ssh/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func deploy(ctx context.Context, args []string) error {
}

// Retrieve the list of locations to deploy.
locs, err := getLocations(app)
locs, err := getLocations(config)
if err != nil {
return err
}
Expand Down Expand Up @@ -192,21 +192,8 @@ func terminateDeployment(locs []string, dep *protos.Deployment) error {
}

// getLocations returns the list of locations at which to deploy the application.
func getLocations(app *protos.AppConfig) ([]string, error) {
// SSH config as found in TOML config file.
const sshKey = "github.com/ServiceWeaver/weaver/ssh"
const shortSSHKey = "ssh"

// TODO(spetrovic): Avoid parsing the config twice.
type sshConfigSchema struct {
LocationsFile string `toml:"locations_file"`
}
parsed := &sshConfigSchema{}
if err := runtime.ParseConfigSection(sshKey, shortSSHKey, app.Sections, parsed); err != nil {
return nil, fmt.Errorf("unable to parse ssh config: %w", err)
}

file, err := getAbsoluteFilePath(parsed.LocationsFile)
func getLocations(config *impl.SshConfig) ([]string, error) {
file, err := getAbsoluteFilePath(config.Locations)
if err != nil {
return nil, err
}
Expand All @@ -222,7 +209,7 @@ func getLocations(app *protos.AppConfig) ([]string, error) {
for fileScanner.Scan() {
loc := fileScanner.Text()
if _, ok := locations[loc]; ok {
return nil, fmt.Errorf("no duplicate locations allowed to deploy using the ssh deployer")
return nil, fmt.Errorf("duplicate locations in the locations file")
}
locations[loc] = true
}
Expand Down
150 changes: 81 additions & 69 deletions internal/tool/ssh/impl/ssh.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion internal/tool/ssh/impl/ssh.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ message SshConfig {
// host:port, or it may be the empty string, which is treated as ":0".
string address = 1;
}
map<string, ListenerOptions> listeners = 3;
map<string, ListenerOptions> listeners = 2;

// File that contains the IP addresses of all locations where the application
// can run.
string locations = 3;
}

// BabysitterInfo contains app deployment information that is needed by a
Expand Down

0 comments on commit 004abd4

Please sign in to comment.