{"action":"created","comment":{"url":"https://api.github.com/repos/Clever/sftp/pulls/comments/70310523","id":70310523,"diff_hunk":"@@ -0,0 +1,120 @@\n+package sftp\r\n+\r\n+import (\r\n+\t\"fmt\"\r\n+\t\"io/ioutil\"\r\n+\t\"log\"\r\n+\t\"net\"\r\n+\r\n+\t\"golang.org/x/crypto/ssh\"\r\n+)\r\n+\r\n+type LoginRequest struct {\r\n+\tUsername string\r\n+\tPassword string\r\n+}\r\n+\r\n+type ManagedServer struct {\r\n+\tdriverGenerator func(LoginRequest) ServerDriver\r\n+}\r\n+\r\n+func NewManagedServer(driverGenerator func(LoginRequest) ServerDriver) *ManagedServer {\r\n+\treturn &ManagedServer{\r\n+\t\tdriverGenerator,\r\n+\t}\r\n+}\r\n+\r\n+func (m ManagedServer) Start(port int, privateKeyPath string) {\r\n+\tfmt.Println(\"Starting SFTP server...\")\r\n+\r\n+\tprivateBytes, err := ioutil.ReadFile(privateKeyPath)\r\n+\tif err != nil {\r\n+\t\tlog.Fatal(\"Failed to load private key\", err)\r\n+\t}\r\n+\r\n+\tprivate, err := ssh.ParsePrivateKey(privateBytes)\r\n+\tif err != nil {\r\n+\t\tlog.Fatal(\"Failed to parse private key\", err)\r\n+\t}\r\n+\r\n+\tlistener, err := net.Listen(\"tcp\", fmt.Sprintf(\"0.0.0.0:%v\", port))\r\n+\tif err != nil {\r\n+\t\tlog.Fatal(\"failed to listen for connection\", err)\r\n+\t}\r\n+\tfmt.Printf(\"Listening on %v\\n\", listener.Addr())\r\n+\r\n+\tfor {\r\n+\t\tnewConn, err := listener.Accept()\r\n+\t\tif err != nil {\r\n+\t\t\tlog.Fatal(\"failed to accept incoming connection\", err)\r\n+\t\t}\r\n+\r\n+\t\tgo func(conn net.Conn) {\r\n+\t\t\tfmt.Println(\"Got connection!\")\r\n+\r\n+\t\t\tvar driver ServerDriver\r\n+\t\t\tconfig := &ssh.ServerConfig{\r\n+\t\t\t\tPasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {\r\n+\t\t\t\t\tdriver = m.driverGenerator(LoginRequest{\r\n+\t\t\t\t\t\tUsername: c.User(),\r\n+\t\t\t\t\t\tPassword: string(pass),\r\n+\t\t\t\t\t})\r\n+\t\t\t\t\tif driver == nil {\r\n+\t\t\t\t\t\treturn nil, fmt.Errorf(\"password rejected for %q\", c.User())\r\n+\t\t\t\t\t}\r\n+\t\t\t\t\treturn nil, nil\r\n+\t\t\t\t},\r\n+\t\t\t}\r\n+\t\t\tconfig.AddHostKey(private)\r\n+\r\n+\t\t\t_, newChan, requestChan, err := ssh.NewServerConn(conn, config)\r\n+\t\t\tif err != nil {\r\n+\t\t\t\tlog.Fatal(\"failed to handshake\", err)\r\n+\t\t\t}\r\n+\t\t\tfmt.Println(\"Handshake completed...\")\r\n+\r\n+\t\t\tgo ssh.DiscardRequests(requestChan)\r","path":"managedserver.go","position":76,"original_position":76,"commit_id":"86e327a1482c4bbd1f131f9d31e27f0098172cd9","original_commit_id":"86e327a1482c4bbd1f131f9d31e27f0098172cd9","user":{"login":"rgarcia","id":72655,"avatar_url":"https://avatars.githubusercontent.com/u/72655?v=3","gravatar_id":"","url":"https://api.github.com/users/rgarcia","html_url":"https://github.com/rgarcia","followers_url":"https://api.github.com/users/rgarcia/followers","following_url":"https://api.github.com/users/rgarcia/following{/other_user}","gists_url":"https://api.github.com/users/rgarcia/gists{/gist_id}","starred_url":"https://api.github.com/users/rgarcia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgarcia/subscriptions","organizations_url":"https://api.github.com/users/rgarcia/orgs","repos_url":"https://api.github.com/users/rgarcia/repos","events_url":"https://api.github.com/users/rgarcia/events{/privacy}","received_events_url":"https://api.github.com/users/rgarcia/received_events","type":"User","site_admin":false},"body":"I don't quite understand the difference between `newChan` and `requestChan`--can you explain?","created_at":"2016-07-11T18:27:17Z","updated_at":"2016-07-11T18:27:17Z","html_url":"https://github.com/Clever/sftp/pull/1#discussion_r70310523","pull_request_url":"https://api.github.com/repos/Clever/sftp/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/Clever/sftp/pulls/comments/70310523"},"html":{"href":"https://github.com/Clever/sftp/pull/1#discussion_r70310523"},"pull_request":{"href":"https://api.github.com/repos/Clever/sftp/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/Clever/sftp/pulls/1","id":74707080,"html_url":"https://github.com/Clever/sftp/pull/1","diff_url":"https://github.com/Clever/sftp/pull/1.diff","patch_url":"https://github.com/Clever/sftp/pull/1.patch","issue_url":"https://api.github.com/repos/Clever/sftp/issues/1","number":1,"state":"open","locked":false,"title":"Add driver for server","user":{"login":"jefff","id":124665,"avatar_url":"https://avatars.githubusercontent.com/u/124665?v=3","gravatar_id":"","url":"https://api.github.com/users/jefff","html_url":"https://github.com/jefff","followers_url":"https://api.github.com/users/jefff/followers","following_url":"https://api.github.com/users/jefff/following{/other_user}","gists_url":"https://api.github.com/users/jefff/gists{/gist_id}","starred_url":"https://api.github.com/users/jefff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jefff/subscriptions","organizations_url":"https://api.github.com/users/jefff/orgs","repos_url":"https://api.github.com/users/jefff/repos","events_url":"https://api.github.com/users/jefff/events{/privacy}","received_events_url":"https://api.github.com/users/jefff/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-22T00:21:52Z","updated_at":"2016-07-11T18:27:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9654e045fb2e98c1c86b63d4054c9ca957e05f65","assignee":{"login":"rgarcia","id":72655,"avatar_url":"https://avatars.githubusercontent.com/u/72655?v=3","gravatar_id":"","url":"https://api.github.com/users/rgarcia","html_url":"https://github.com/rgarcia","followers_url":"https://api.github.com/users/rgarcia/followers","following_url":"https://api.github.com/users/rgarcia/following{/other_user}","gists_url":"https://api.github.com/users/rgarcia/gists{/gist_id}","starred_url":"https://api.github.com/users/rgarcia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgarcia/subscriptions","organizations_url":"https://api.github.com/users/rgarcia/orgs","repos_url":"https://api.github.com/users/rgarcia/repos","events_url":"https://api.github.com/users/rgarcia/events{/privacy}","received_events_url":"https://api.github.com/users/rgarcia/received_events","type":"User","site_admin":false},"assignees":[{"login":"rgarcia","id":72655,"avatar_url":"https://avatars.githubusercontent.com/u/72655?v=3","gravatar_id":"","url":"https://api.github.com/users/rgarcia","html_url":"https://github.com/rgarcia","followers_url":"https://api.github.com/users/rgarcia/followers","following_url":"https://api.github.com/users/rgarcia/following{/other_user}","gists_url":"https://api.github.com/users/rgarcia/gists{/gist_id}","starred_url":"https://api.github.com/users/rgarcia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgarcia/subscriptions","organizations_url":"https://api.github.com/users/rgarcia/orgs","repos_url":"https://api.github.com/users/rgarcia/repos","events_url":"https://api.github.com/users/rgarcia/events{/privacy}","received_events_url":"https://api.github.com/users/rgarcia/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Clever/sftp/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Clever/sftp/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Clever/sftp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Clever/sftp/issues/1/comments","statuses_url":"https://api.github.com/repos/Clever/sftp/statuses/86e327a1482c4bbd1f131f9d31e27f0098172cd9","head":{"label":"Clever:add-driver-for-server","ref":"add-driver-for-server","sha":"86e327a1482c4bbd1f131f9d31e27f0098172cd9","user":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"repo":{"id":61251852,"name":"sftp","full_name":"Clever/sftp","owner":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Clever/sftp","description":"SFTP support for the go.crypto/ssh package","fork":true,"url":"https://api.github.com/repos/Clever/sftp","forks_url":"https://api.github.com/repos/Clever/sftp/forks","keys_url":"https://api.github.com/repos/Clever/sftp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Clever/sftp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Clever/sftp/teams","hooks_url":"https://api.github.com/repos/Clever/sftp/hooks","issue_events_url":"https://api.github.com/repos/Clever/sftp/issues/events{/number}","events_url":"https://api.github.com/repos/Clever/sftp/events","assignees_url":"https://api.github.com/repos/Clever/sftp/assignees{/user}","branches_url":"https://api.github.com/repos/Clever/sftp/branches{/branch}","tags_url":"https://api.github.com/repos/Clever/sftp/tags","blobs_url":"https://api.github.com/repos/Clever/sftp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Clever/sftp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Clever/sftp/git/refs{/sha}","trees_url":"https://api.github.com/repos/Clever/sftp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Clever/sftp/statuses/{sha}","languages_url":"https://api.github.com/repos/Clever/sftp/languages","stargazers_url":"https://api.github.com/repos/Clever/sftp/stargazers","contributors_url":"https://api.github.com/repos/Clever/sftp/contributors","subscribers_url":"https://api.github.com/repos/Clever/sftp/subscribers","subscription_url":"https://api.github.com/repos/Clever/sftp/subscription","commits_url":"https://api.github.com/repos/Clever/sftp/commits{/sha}","git_commits_url":"https://api.github.com/repos/Clever/sftp/git/commits{/sha}","comments_url":"https://api.github.com/repos/Clever/sftp/comments{/number}","issue_comment_url":"https://api.github.com/repos/Clever/sftp/issues/comments{/number}","contents_url":"https://api.github.com/repos/Clever/sftp/contents/{+path}","compare_url":"https://api.github.com/repos/Clever/sftp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Clever/sftp/merges","archive_url":"https://api.github.com/repos/Clever/sftp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Clever/sftp/downloads","issues_url":"https://api.github.com/repos/Clever/sftp/issues{/number}","pulls_url":"https://api.github.com/repos/Clever/sftp/pulls{/number}","milestones_url":"https://api.github.com/repos/Clever/sftp/milestones{/number}","notifications_url":"https://api.github.com/repos/Clever/sftp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Clever/sftp/labels{/name}","releases_url":"https://api.github.com/repos/Clever/sftp/releases{/id}","deployments_url":"https://api.github.com/repos/Clever/sftp/deployments","created_at":"2016-06-16T01:14:18Z","updated_at":"2016-06-16T01:14:18Z","pushed_at":"2016-07-11T17:53:10Z","git_url":"git://github.com/Clever/sftp.git","ssh_url":"git@github.com:Clever/sftp.git","clone_url":"https://github.com/Clever/sftp.git","svn_url":"https://github.com/Clever/sftp","homepage":null,"size":1679,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"Clever:master","ref":"master","sha":"d4c18e7ffdc496a38de67dde6e29b2f364afc472","user":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"repo":{"id":61251852,"name":"sftp","full_name":"Clever/sftp","owner":{"login":"Clever","id":1885509,"avatar_url":"https://avatars.githubusercontent.com/u/1885509?v=3","gravatar_id":"","url":"https://api.github.com/users/Clever","html_url":"https://github.com/Clever","followers_url":"https://api.github.com/users/Clever/followers","following_url":"https://api.github.com/users/Clever/following{/other_user}","gists_url":"https://api.github.com/users/Clever/gists{/gist_id}","starred_url":"https://api.github.com/users/Clever/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Clever/subscriptions","organizations_url":"https://api.github.com/users/Clever/orgs","repos_url":"https://api.github.com/users/Clever/repos","events_url":"https://api.github.com/users/Clever/events{/privacy}","received_events_url":"https://api.github.com/users/Clever/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Clever/sftp","description":"SFTP support for the go.crypto/ssh package","fork":true,"url":"https://api.github.com/repos/Clever/sftp","forks_url":"https://api.github.com/repos/Clever/sftp/forks","keys_url":"https://api.github.com/repos/Clever/sftp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Clever/sftp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Clever/sftp/teams","hooks_url":"https://api.github.com/repos/Clever/sftp/hooks","issue_events_url":"https://api.github.com/repos/Clever/sftp/issues/events{/number}","events_url":"https://api.github.com/repos/Clever/sftp/events","assignees_url":"https://api.github.com/repos/Clever/sftp/assignees{/user}","branches_url":"https://api.github.com/repos/Clever/sftp/branches{/branch}","tags_url":"https://api.github.com/repos/Clever/sftp/tags","blobs_url":"https://api.github.com/repos/Clever/sftp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Clever/sftp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Clever/sftp/git/refs{/sha}","trees_url":"https://api.github.com/repos/Clever/sftp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Clever/sftp/statuses/{sha}","languages_url":"https://api.github.com/repos/Clever/sftp/languages","stargazers_url":"https://api.github.com/repos/Clever/sftp/stargazers","contributors_url":"https://api.github.com/repos/Clever/sftp/contributors","subscribers_url":"https://api.github.com/repos/Clever/sftp/subscribers","subscription_url":"https://api.github.com/repos/Clever/sftp/subscription","commits_url":"https://api.github.com/repos/Clever/sftp/commits{/sha}","git_commits_url":"https://api.github.com/repos/Clever/sftp/git/commits{/sha}","comments_url":"https://api.github.com/repos/Clever/sftp/comments{/number}","issue_comment_url":"https://api.github.com/repos/Clever/sftp/issues/comments{/number}","contents_url":"https://api.github.com/repos/Clever/sftp/contents/{+path}","compare_url":"https://api.github.com/repos/Clever/sftp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Clever/sftp/merges","archive_url":"https://api.github.com/repos/Clever/sftp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Clever/sftp/downloads","issues_url":"https://api.github.com/repos/Clever/sftp/issues{/number}","pulls_url":"https://api.github.com/repos/Clever/sftp/pulls{/number}","milestones_url":"https://api.github.com/repos/Clever/sftp/milestones{/number}","notifications_url":"https://api.github.com/repos/Clever/sftp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Clever/sftp/labels{/name}","releases_url":"https://api.github.com/repos/Clever/sftp/releases{/id}","deployments_url":"https://api.github.com/repos/Clever/sftp/deployments","created_at":"2016-06-16T01:14:18Z","updated_at":"2016-06-16T01:14:18Z","pushed_at":"2016-07-11T17:53:10Z","git_url":"git://github.com/Clever/sftp.git","ssh_url":"git@github.com:Clever/sftp.git","clone_url":"https://github.com/Clever/sftp.git","svn_url":"https://github.com/Clever/sftp","homepage":null,"size":1679,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Clever/sftp/pulls/1"},"html":{"href":"https://github.com/Clever/sftp/pull/1"},"issue":{"href":"https://api.github.com/repos/Clever/sftp/issues/1"},"comments":{"href":"https://api.github.com/repos/Clever/sftp/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Clever/sftp/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Clever/sftp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Clever/sftp/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Clever/sftp/statuses/86e327a1482c4bbd1f131f9d31e27f0098172cd9"}}}}
{"actor":{"display_login":"rgarcia"}}