-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Client application draft #66
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2015 Gravitational, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/gravitational/teleport/Godeps/_workspace/src/github.com/gravitational/log" | ||
"github.com/gravitational/teleport/tool/tsh/tsh" | ||
) | ||
|
||
func main() { | ||
log.Initialize("console", "INFO") | ||
|
||
err := tsh.RunTSH(os.Args) | ||
if err != nil { | ||
log.Errorf(err.Error()) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
Copyright 2015 Gravitational, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package tsh | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/gravitational/teleport/Godeps/_workspace/src/github.com/gravitational/trace" | ||
"github.com/gravitational/teleport/Godeps/_workspace/src/golang.org/x/crypto/ssh/agent" | ||
"github.com/gravitational/teleport/Godeps/_workspace/src/gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
func RunTSH(args []string) error { | ||
app := kingpin.New("tsh", "teleport SSH client") | ||
|
||
user := app.Flag("user", "SSH user").Required().String() | ||
sshAgentAddress := app.Flag("ssh-agent", "SSH agent address").OverrideDefaultFromEnvar("SSH_AUTH_SOCK").String() | ||
sshAgentNetwork := app.Flag("ssh-agent-network", "SSH agent address network type('tcp','unix' etc.)").Default("unix").String() | ||
|
||
connect := app.Command("connect", "Helper operations with SSH keypairs") | ||
connectAddress := connect.Arg("address", "Target server address").Required().String() | ||
connectProxy := connect.Flag("proxy", "Optional proxy address").String() | ||
connectCommand := connect.Flag("command", "Run proveded command instead of shell").String() | ||
|
||
upload := app.Command("upload", "Helper operations with SSH keypairs") | ||
uploadAddress := upload.Arg("address", "Target server address").Required().String() | ||
uploadProxy := upload.Flag("proxy", "Optional proxy address").String() | ||
uploadLocalSource := upload.Flag("source", "Local source path").Required().String() | ||
uploadRemoteDest := upload.Flag("dest", "Remote destination path").Required().String() | ||
|
||
download := app.Command("download", "Helper operations with SSH keypairs") | ||
downloadAddress := download.Arg("address", "Target server address").Required().String() | ||
downloadProxy := download.Flag("proxy", "Optional proxy address").String() | ||
downloadLocalDest := download.Flag("dest", "Local destination path").Required().String() | ||
downloadRemoteSource := download.Flag("source", "Remote source path").Required().String() | ||
downloadRecursively := download.Flag("r", "Source path is directory").Bool() | ||
|
||
getServers := app.Command("get-servers", "Returns list of servers") | ||
getServersProxy := getServers.Flag("proxy", "Target proxy address").String() | ||
getServersLabelName := getServers.Flag("label", "Label name").String() | ||
getServersLabelValue := getServers.Flag("value", "Label value regexp").String() | ||
|
||
selectedCommand := kingpin.MustParse(app.Parse(args[1:])) | ||
|
||
agent, err := connectToSSHAgent(*sshAgentNetwork, *sshAgentAddress) | ||
if err != nil { | ||
return trace.Wrap(err) | ||
} | ||
|
||
err = trace.Errorf("No command") | ||
|
||
switch selectedCommand { | ||
case connect.FullCommand(): | ||
err = Connect(*user, *connectAddress, *connectProxy, *connectCommand, agent) | ||
case upload.FullCommand(): | ||
err = Upload(*user, *uploadAddress, *uploadProxy, *uploadLocalSource, | ||
*uploadRemoteDest, agent) | ||
case download.FullCommand(): | ||
err = Download(*user, *downloadAddress, *downloadProxy, | ||
*downloadRemoteSource, *downloadLocalDest, | ||
*downloadRecursively, agent) | ||
case getServers.FullCommand(): | ||
err = GetServers(*user, *getServersProxy, *getServersLabelName, | ||
*getServersLabelValue, agent) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func connectToSSHAgent(network, address string) (agent.Agent, error) { | ||
conn, err := net.Dial(network, address) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
return agent.NewClient(conn), nil | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunTSH
is a bit redundant(because of the package name), how about simplyRun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but there is Run() function in the test(check.v1) package