@@ -52,7 +52,7 @@ var cpHelp bool // -h, --help flag
52
52
var cpGateway string // -g, --gateway flag
53
53
54
54
// TarFromSource creates a stream buffer with the tarballed content of the user source
55
- func TarFromSource (api * api.ScalewayAPI , source string ) (* io.ReadCloser , error ) {
55
+ func TarFromSource (apiClient * api.ScalewayAPI , source string ) (* io.ReadCloser , error ) {
56
56
var tarOutputStream io.ReadCloser
57
57
58
58
// source is a server address + path (scp-like uri)
@@ -63,9 +63,9 @@ func TarFromSource(api *api.ScalewayAPI, source string) (*io.ReadCloser, error)
63
63
return nil , fmt .Errorf ("invalid source uri, see 'scw cp -h' for usage" )
64
64
}
65
65
66
- serverID := api .GetServerID (serverParts [0 ])
66
+ serverID := apiClient .GetServerID (serverParts [0 ])
67
67
68
- server , err := api .GetServer (serverID )
68
+ server , err := apiClient .GetServer (serverID )
69
69
if err != nil {
70
70
return nil , err
71
71
}
@@ -83,8 +83,14 @@ func TarFromSource(api *api.ScalewayAPI, source string) (*io.ReadCloser, error)
83
83
remoteCommand = append (remoteCommand , "-cf" , "-" )
84
84
remoteCommand = append (remoteCommand , base )
85
85
86
+ // Resolve gateway
87
+ gateway , err := api .ResolveGateway (apiClient , cpGateway )
88
+ if err != nil {
89
+ log .Fatalf ("Cannot resolve Gateway '%s': %v" , cpGateway , err )
90
+ }
91
+
86
92
// execCmd contains the ssh connection + the remoteCommand
87
- execCmd := append (utils .NewSSHExecCmd (server .PublicAddress .IP , server .PrivateIP , false , nil , remoteCommand , cpGateway ))
93
+ execCmd := append (utils .NewSSHExecCmd (server .PublicAddress .IP , server .PrivateIP , false , nil , remoteCommand , gateway ))
88
94
log .Debugf ("Executing: ssh %s" , strings .Join (execCmd , " " ))
89
95
spawnSrc := exec .Command ("ssh" , execCmd ... )
90
96
@@ -141,7 +147,7 @@ func TarFromSource(api *api.ScalewayAPI, source string) (*io.ReadCloser, error)
141
147
}
142
148
143
149
// UntarToDest writes to user destination the streamed tarball in input
144
- func UntarToDest (api * api.ScalewayAPI , sourceStream * io.ReadCloser , destination string ) error {
150
+ func UntarToDest (apiClient * api.ScalewayAPI , sourceStream * io.ReadCloser , destination string ) error {
145
151
// destination is a server address + path (scp-like uri)
146
152
if strings .Index (destination , ":" ) > - 1 {
147
153
log .Debugf ("Streaming using ssh and untaring remotely" )
@@ -150,9 +156,9 @@ func UntarToDest(api *api.ScalewayAPI, sourceStream *io.ReadCloser, destination
150
156
return fmt .Errorf ("invalid destination uri, see 'scw cp -h' for usage" )
151
157
}
152
158
153
- serverID := api .GetServerID (serverParts [0 ])
159
+ serverID := apiClient .GetServerID (serverParts [0 ])
154
160
155
- server , err := api .GetServer (serverID )
161
+ server , err := apiClient .GetServer (serverID )
156
162
if err != nil {
157
163
return err
158
164
}
@@ -166,8 +172,14 @@ func UntarToDest(api *api.ScalewayAPI, sourceStream *io.ReadCloser, destination
166
172
}
167
173
remoteCommand = append (remoteCommand , "-xf" , "-" )
168
174
175
+ // Resolve gateway
176
+ gateway , err := api .ResolveGateway (apiClient , cpGateway )
177
+ if err != nil {
178
+ log .Fatalf ("Cannot resolve Gateway '%s': %v" , cpGateway , err )
179
+ }
180
+
169
181
// execCmd contains the ssh connection + the remoteCommand
170
- execCmd := append (utils .NewSSHExecCmd (server .PublicAddress .IP , server .PrivateIP , false , nil , remoteCommand , cpGateway ))
182
+ execCmd := append (utils .NewSSHExecCmd (server .PublicAddress .IP , server .PrivateIP , false , nil , remoteCommand , gateway ))
171
183
log .Debugf ("Executing: ssh %s" , strings .Join (execCmd , " " ))
172
184
spawnDst := exec .Command ("ssh" , execCmd ... )
173
185
0 commit comments