@@ -93,23 +93,24 @@ func (c *etcdChecker) doCheck(hostport string) utils.State {
93
93
// findDestination finds a reachable destination for the sshd server according
94
94
// to the etcd database if available or the routes and route_select algorithm.
95
95
// It returns a string with the service name, a string with host:port, a string
96
- // containing ForceCommand value and a bool containing CommandMustMatch; a
96
+ // containing ForceCommand value, a bool containing CommandMustMatch, an int64
97
+ // with etcd_keyttl and a map of strings with the environment variables; a
97
98
// string with the service name and an empty string if no destination is found
98
99
// or an error if any.
99
- func findDestination (cli * utils.Client , username string , routes map [string ]* utils.RouteConfig , sshdHostport string , checkInterval utils.Duration ) (string , string , string , bool , error ) {
100
+ func findDestination (cli * utils.Client , username string , routes map [string ]* utils.RouteConfig , sshdHostport string , checkInterval utils.Duration ) (string , string , string , bool , int64 , map [ string ] string , error ) {
100
101
checker := & etcdChecker {
101
102
checkInterval : checkInterval ,
102
103
cli : cli ,
103
104
}
104
105
105
106
service , err := findService (routes , sshdHostport )
106
107
if err != nil {
107
- return "" , "" , "" , false , err
108
+ return "" , "" , "" , false , 0 , nil , err
108
109
}
109
110
key := fmt .Sprintf ("%s@%s" , username , service )
110
111
111
112
if routes [service ].Mode == "sticky" && cli != nil && cli .IsAlive () {
112
- dest , err := cli .GetDestination (key )
113
+ dest , err := cli .GetDestination (key , routes [ service ]. EtcdKeyTTL )
113
114
if err != nil {
114
115
if err != utils .ErrKeyNotFound {
115
116
log .Errorf ("problem with etcd: %v" , err )
@@ -118,7 +119,7 @@ func findDestination(cli *utils.Client, username string, routes map[string]*util
118
119
if utils .IsDestinationInRoutes (dest , routes [service ].Dest ) {
119
120
if checker .Check (dest ) {
120
121
log .Debugf ("found destination in etcd: %s" , dest )
121
- return service , dest , routes [service ].ForceCommand , routes [service ].CommandMustMatch , nil
122
+ return service , dest , routes [service ].ForceCommand , routes [service ].CommandMustMatch , routes [ service ]. EtcdKeyTTL , routes [ service ]. Environment , nil
122
123
}
123
124
log .Infof ("cannot connect %s to already existing connection(s) to %s: host %s" , key , dest , checker .LastState )
124
125
} else {
@@ -129,10 +130,10 @@ func findDestination(cli *utils.Client, username string, routes map[string]*util
129
130
130
131
if len (routes [service ].Dest ) > 0 {
131
132
selected , err := utils .SelectRoute (routes [service ].RouteSelect , routes [service ].Dest , checker , cli , key )
132
- return service , selected , routes [service ].ForceCommand , routes [service ].CommandMustMatch , err
133
+ return service , selected , routes [service ].ForceCommand , routes [service ].CommandMustMatch , routes [ service ]. EtcdKeyTTL , routes [ service ]. Environment , err
133
134
}
134
135
135
- return service , "" , "" , false , fmt .Errorf ("no destination set for service %s" , service )
136
+ return service , "" , "" , false , 0 , nil , fmt .Errorf ("no destination set for service %s" , service )
136
137
}
137
138
138
139
// findService finds the first service containing a suitable source in the conf,
@@ -326,7 +327,7 @@ func mainExitCode() int {
326
327
log .Errorf ("Cannot contact etcd cluster to update state: %v" , err )
327
328
}
328
329
329
- service , hostport , forceCommand , commandMustMatch , err := findDestination (cli , username , config .Routes , sshInfos .Dst (), config .CheckInterval )
330
+ service , hostport , forceCommand , commandMustMatch , etcdKeyTTL , environment , err := findDestination (cli , username , config .Routes , sshInfos .Dst (), config .CheckInterval )
330
331
switch {
331
332
case err != nil :
332
333
log .Fatalf ("Finding destination: %s" , err )
@@ -345,6 +346,8 @@ func mainExitCode() int {
345
346
log .Fatalf ("Invalid destination '%s': %s" , hostport , err )
346
347
}
347
348
349
+ setEnvironment (environment )
350
+
348
351
// waitgroup and channel to stop our background command when exiting.
349
352
var wg sync.WaitGroup
350
353
ctx , cancel := context .WithCancel (context .Background ())
@@ -366,7 +369,7 @@ func mainExitCode() int {
366
369
// Register destination in etcd and keep it alive while running.
367
370
if cli != nil && cli .IsAlive () {
368
371
key := fmt .Sprintf ("%s@%s" , username , service )
369
- keepAliveChan , eP , err := cli .SetDestination (ctx , key , sshInfos .Dst (), hostport )
372
+ keepAliveChan , eP , err := cli .SetDestination (ctx , key , sshInfos .Dst (), hostport , etcdKeyTTL )
370
373
etcdPath = eP
371
374
if err != nil {
372
375
log .Warningf ("setting destination in etcd: %v" , err )
0 commit comments