summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gliderlabs/ssh/options.go
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2019-07-06 21:28:09 -0400
committerGitHub <noreply@github.com>2019-07-06 21:28:09 -0400
commitd0ec940dd7b79876c91288be54e8fd62eb42fe54 (patch)
treefb378674d89e02aeca8de4b399c32ffc31f81a93 /vendor/github.com/gliderlabs/ssh/options.go
parentc44f0b1c760855f578d2e5ce6fafbf9cba97da4f (diff)
downloadgitea-d0ec940dd7b79876c91288be54e8fd62eb42fe54.tar.gz
gitea-d0ec940dd7b79876c91288be54e8fd62eb42fe54.zip
switch to use gliderlabs/ssh for builtin server (#7250)
resolves git conflicts from #3896 (credit to @belak, in case github doesn't keep original author during squash) Co-Authored-By: Matti Ranta <techknowlogick@gitea.io>
Diffstat (limited to 'vendor/github.com/gliderlabs/ssh/options.go')
-rw-r--r--vendor/github.com/gliderlabs/ssh/options.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/vendor/github.com/gliderlabs/ssh/options.go b/vendor/github.com/gliderlabs/ssh/options.go
new file mode 100644
index 0000000000..af748985be
--- /dev/null
+++ b/vendor/github.com/gliderlabs/ssh/options.go
@@ -0,0 +1,77 @@
+package ssh
+
+import (
+ "io/ioutil"
+
+ gossh "golang.org/x/crypto/ssh"
+)
+
+// PasswordAuth returns a functional option that sets PasswordHandler on the server.
+func PasswordAuth(fn PasswordHandler) Option {
+ return func(srv *Server) error {
+ srv.PasswordHandler = fn
+ return nil
+ }
+}
+
+// PublicKeyAuth returns a functional option that sets PublicKeyHandler on the server.
+func PublicKeyAuth(fn PublicKeyHandler) Option {
+ return func(srv *Server) error {
+ srv.PublicKeyHandler = fn
+ return nil
+ }
+}
+
+// HostKeyFile returns a functional option that adds HostSigners to the server
+// from a PEM file at filepath.
+func HostKeyFile(filepath string) Option {
+ return func(srv *Server) error {
+ pemBytes, err := ioutil.ReadFile(filepath)
+ if err != nil {
+ return err
+ }
+
+ signer, err := gossh.ParsePrivateKey(pemBytes)
+ if err != nil {
+ return err
+ }
+
+ srv.AddHostKey(signer)
+
+ return nil
+ }
+}
+
+// HostKeyPEM returns a functional option that adds HostSigners to the server
+// from a PEM file as bytes.
+func HostKeyPEM(bytes []byte) Option {
+ return func(srv *Server) error {
+ signer, err := gossh.ParsePrivateKey(bytes)
+ if err != nil {
+ return err
+ }
+
+ srv.AddHostKey(signer)
+
+ return nil
+ }
+}
+
+// NoPty returns a functional option that sets PtyCallback to return false,
+// denying PTY requests.
+func NoPty() Option {
+ return func(srv *Server) error {
+ srv.PtyCallback = func(ctx Context, pty Pty) bool {
+ return false
+ }
+ return nil
+ }
+}
+
+// WrapConn returns a functional option that sets ConnCallback on the server.
+func WrapConn(fn ConnCallback) Option {
+ return func(srv *Server) error {
+ srv.ConnCallback = fn
+ return nil
+ }
+}