class Travis::CLI::Sshkey
def generate_key
def generate_key access_token = nil github.with_token do |token| access_token = github_auth(token) end raise Travis::Client::GitHubLoginFailed, 'all GitHub tokens given were invalid' unless access_token gh = GH.with(token: github_token) login = gh['user']['login'] check_access(gh) empty_line say 'Generating RSA key.' private_key = Tools::SSLKey.generate_rsa self.description ||= "key for fetching dependencies for #{slug} via #{login}" say 'Uploading public key to GitHub.' gh.post('/user/keys', title: "#{description} (Travis CI)", key: Tools::SSLKey.rsa_ssh(private_key.public_key)) say 'Uploading private key to Travis CI.' ssh_key.update(value: private_key.to_s, description:) empty_line say 'You can store the private key to reuse it for other repositories (travis sshkey --upload FILE).' return unless agree('Store private key? ') { |q| q.default = 'no' } path = ask('Path: ') { |q| q.default = 'id_travis_rsa' } File.write(path, private_key.to_s) end