{"action":"created","issue":{"url":"https://api.github.com/repos/kentaroi/sshkit-sudo/issues/2","labels_url":"https://api.github.com/repos/kentaroi/sshkit-sudo/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/kentaroi/sshkit-sudo/issues/2/comments","events_url":"https://api.github.com/repos/kentaroi/sshkit-sudo/issues/2/events","html_url":"https://github.com/kentaroi/sshkit-sudo/issues/2","id":68132888,"number":2,"title":"Support for 'as' method","user":{"login":"robd","id":11879,"avatar_url":"https://avatars.githubusercontent.com/u/11879?v=3","gravatar_id":"","url":"https://api.github.com/users/robd","html_url":"https://github.com/robd","followers_url":"https://api.github.com/users/robd/followers","following_url":"https://api.github.com/users/robd/following{/other_user}","gists_url":"https://api.github.com/users/robd/gists{/gist_id}","starred_url":"https://api.github.com/users/robd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robd/subscriptions","organizations_url":"https://api.github.com/users/robd/orgs","repos_url":"https://api.github.com/users/robd/repos","events_url":"https://api.github.com/users/robd/events{/privacy}","received_events_url":"https://api.github.com/users/robd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-04-13T15:59:17Z","updated_at":"2015-04-18T16:03:38Z","closed_at":null,"body":"I was wondering if it would be possible to support calls to the [as()](https://github.com/capistrano/sshkit/blob/e60b80ab13f0df89a9843dbca28c8163509e3c18/lib/sshkit/backends/abstract.rb#L91) method?\r\n\r\nFor some reason I couldn't work out, when [execute](https://github.com/capistrano/sshkit/blob/e60b80ab13f0df89a9843dbca28c8163509e3c18/lib/sshkit/backends/abstract.rb#L99) is called, it does not call the patched [_execute!](https://github.com/kentaroi/sshkit-sudo/blob/master/lib/sshkit/sudo/backends_ext/netssh.rb#L15) method, it calls the original one, which hangs waiting for input.\r\n\r\nI couldn't understand the class hierarchy, but is something that could be fixed?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/kentaroi/sshkit-sudo/issues/comments/94177034","html_url":"https://github.com/kentaroi/sshkit-sudo/issues/2#issuecomment-94177034","issue_url":"https://api.github.com/repos/kentaroi/sshkit-sudo/issues/2","id":94177034,"user":{"login":"robd","id":11879,"avatar_url":"https://avatars.githubusercontent.com/u/11879?v=3","gravatar_id":"","url":"https://api.github.com/users/robd","html_url":"https://github.com/robd","followers_url":"https://api.github.com/users/robd/followers","following_url":"https://api.github.com/users/robd/following{/other_user}","gists_url":"https://api.github.com/users/robd/gists{/gist_id}","starred_url":"https://api.github.com/users/robd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robd/subscriptions","organizations_url":"https://api.github.com/users/robd/orgs","repos_url":"https://api.github.com/users/robd/repos","events_url":"https://api.github.com/users/robd/events{/privacy}","received_events_url":"https://api.github.com/users/robd/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T16:03:38Z","updated_at":"2015-04-18T16:03:38Z","body":"Hey @kentaroi\r\n\r\nI certainly understand that getting a PR to sshkit would be a lot more work than maintaining the separate sshkit-sudo gem, and from what I've seen over there, the sshkit team are very against sudo with passwords, and just close anything mentioning them as 'not a bug'. So I probably don't have time to try and get this added.\r\n\r\nUnderstand about the per-command config. The one thing I am not sure about is whether the `pty:` option should be on the `command` api, because it only applies to the NetSSH backend, not the local backend. \r\n\r\n> `echo 'appending line' | sudo tee -a somewhere`\r\n\r\nThis could be achieved by writing a more general or a specific custom `Netssh.config.pty` proc:\r\n\r\n```ruby\r\nPTY_ON_CONTAINS_SUDO = lambda do |cmd| \r\n  cmd.command.to_s =~ /sudo/ # General\r\nend\r\n\r\n# Or\r\n\r\nPTY_FOR_TEE_ONLY = lambda do |cmd| \r\n  cmd.command == \"echo 'appending line' | sudo tee -a somewhere\" # Brittle, but highly targetted\r\nend\r\n```\r\n\r\nConfiguring it like this has a big advantage that any user can target any commands in any gem by writing a custom matching rule without having to monkey patch the gem to add the :pty option.\r\n\r\nAnother approach for your example might be to use `as(:root)` (not sure if this would work in all cases though):\r\n\r\n```ruby\r\nas(:root)  do\r\n  execute(\"echo 'appending line' | tee -a somewhere\")\r\nend\r\n```\r\n\r\nCheers,\r\nRob"}}