Skip to content

Commit 5c992ae

Browse files
Generate key and switch default (#855)
* Default API endpoint switched * fix: Remove branch from gh dependency gem (#854) * v1.13.0
1 parent 90e06f7 commit 5c992ae

9 files changed

+119
-44
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source 'https://rubygems.org'
44
gemspec
55

6-
gem 'gh', git: 'https://github.com/travis-ci/gh', branch: 'prd-ruby-upgrade-dev'
6+
gem 'gh', git: 'https://github.com/travis-ci/gh'
77
gem 'rake'
88
gem 'activesupport', '~> 7.0.6'
99

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The [travis gem](https://rubygems.org/gems/travis) includes both a [command line
1717
* [`login`](#login) - authenticates against the API and stores the token
1818
* [`monitor`](#monitor) - live monitor for what's going on
1919
* [`raw`](#raw) - makes an (authenticated) API call and prints out the result
20+
* [`regenerate-token`](#regenerate-token) - regenerates the stored API token
21+
* [`remove-token`](#remove-token) - deletes the stored API token
2022
* [`report`](#report) - generates a report useful for filing issues
2123
* [`repos`](#repos) - lists repositories the user has certain permissions on
2224
* [`sync`](#sync) - triggers a new sync with GitHub
@@ -329,6 +331,24 @@ $ travis raw /repos/travis-ci/travis.rb
329331

330332
Use `--json` if you'd rather prefer the output to be JSON.
331333

334+
#### `regenerate-token`
335+
336+
This command is used to regenerate the stored API token. New token will be stored in the config.
337+
338+
``` console
339+
$ travis regenerate-token
340+
Successfully regenerated the token!
341+
```
342+
343+
#### `remove-token`
344+
345+
This command is used to remove the access token from the config, log out the user and disable the token.
346+
347+
``` console
348+
$ travis remove-token
349+
Successfully removed the access token!
350+
```
351+
332352
#### `report`
333353

334354
When inspecting a bug or reporting an issue, it can be handy to include a report about the system and configuration used for running a command.
@@ -2066,6 +2086,11 @@ See https://github.com/travis-ci/travis.rb/issues/768#issuecomment-700220351 for
20662086

20672087
## Version History
20682088

2089+
### 1.13.0
2090+
2091+
* Default API endpoint switched https://github.com/travis-ci/travis.rb/pull/840
2092+
* Api key regenerate https://github.com/travis-ci/travis.rb/pull/842
2093+
20692094
### 1.12.0
20702095

20712096
* Upgraded ruby version to 3.2 https://github.com/travis-ci/travis.rb/pull/848

lib/travis/cli.rb

+42-40
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,48 @@
1313

1414
module Travis
1515
module CLI
16-
autoload :Token, 'travis/cli/token'
17-
autoload :ApiCommand, 'travis/cli/api_command'
18-
autoload :Accounts, 'travis/cli/accounts'
19-
autoload :Branches, 'travis/cli/branches'
20-
autoload :Cache, 'travis/cli/cache'
21-
autoload :Cancel, 'travis/cli/cancel'
22-
autoload :Command, 'travis/cli/command'
23-
autoload :Console, 'travis/cli/console'
24-
autoload :Disable, 'travis/cli/disable'
25-
autoload :Enable, 'travis/cli/enable'
26-
autoload :Encrypt, 'travis/cli/encrypt'
27-
autoload :EncryptFile, 'travis/cli/encrypt_file'
28-
autoload :Endpoint, 'travis/cli/endpoint'
29-
autoload :Env, 'travis/cli/env'
30-
autoload :Help, 'travis/cli/help'
31-
autoload :History, 'travis/cli/history'
32-
autoload :Init, 'travis/cli/init'
33-
autoload :Lint, 'travis/cli/lint'
34-
autoload :Login, 'travis/cli/login'
35-
autoload :Logout, 'travis/cli/logout'
36-
autoload :Logs, 'travis/cli/logs'
37-
autoload :Monitor, 'travis/cli/monitor'
38-
autoload :Open, 'travis/cli/open'
39-
autoload :Parser, 'travis/cli/parser'
40-
autoload :Pubkey, 'travis/cli/pubkey'
41-
autoload :Raw, 'travis/cli/raw'
42-
autoload :RepoCommand, 'travis/cli/repo_command'
43-
autoload :Report, 'travis/cli/report'
44-
autoload :Repos, 'travis/cli/repos'
45-
autoload :Restart, 'travis/cli/restart'
46-
autoload :Requests, 'travis/cli/requests'
47-
autoload :Settings, 'travis/cli/settings'
48-
autoload :Setup, 'travis/cli/setup'
49-
autoload :Show, 'travis/cli/show'
50-
autoload :Sshkey, 'travis/cli/sshkey'
51-
autoload :Status, 'travis/cli/status'
52-
autoload :Sync, 'travis/cli/sync'
53-
autoload :Version, 'travis/cli/version'
54-
autoload :Whatsup, 'travis/cli/whatsup'
55-
autoload :Whoami, 'travis/cli/whoami'
16+
autoload :Token, 'travis/cli/token'
17+
autoload :ApiCommand, 'travis/cli/api_command'
18+
autoload :Accounts, 'travis/cli/accounts'
19+
autoload :Branches, 'travis/cli/branches'
20+
autoload :Cache, 'travis/cli/cache'
21+
autoload :Cancel, 'travis/cli/cancel'
22+
autoload :Command, 'travis/cli/command'
23+
autoload :Console, 'travis/cli/console'
24+
autoload :Disable, 'travis/cli/disable'
25+
autoload :Enable, 'travis/cli/enable'
26+
autoload :Encrypt, 'travis/cli/encrypt'
27+
autoload :EncryptFile, 'travis/cli/encrypt_file'
28+
autoload :Endpoint, 'travis/cli/endpoint'
29+
autoload :Env, 'travis/cli/env'
30+
autoload :Help, 'travis/cli/help'
31+
autoload :History, 'travis/cli/history'
32+
autoload :Init, 'travis/cli/init'
33+
autoload :Lint, 'travis/cli/lint'
34+
autoload :Login, 'travis/cli/login'
35+
autoload :Logout, 'travis/cli/logout'
36+
autoload :Logs, 'travis/cli/logs'
37+
autoload :Monitor, 'travis/cli/monitor'
38+
autoload :Open, 'travis/cli/open'
39+
autoload :Parser, 'travis/cli/parser'
40+
autoload :Pubkey, 'travis/cli/pubkey'
41+
autoload :Raw, 'travis/cli/raw'
42+
autoload :RegenerateToken, 'travis/cli/regenerate_token'
43+
autoload :RemoveToken, 'travis/cli/remove_token'
44+
autoload :RepoCommand, 'travis/cli/repo_command'
45+
autoload :Report, 'travis/cli/report'
46+
autoload :Repos, 'travis/cli/repos'
47+
autoload :Restart, 'travis/cli/restart'
48+
autoload :Requests, 'travis/cli/requests'
49+
autoload :Settings, 'travis/cli/settings'
50+
autoload :Setup, 'travis/cli/setup'
51+
autoload :Show, 'travis/cli/show'
52+
autoload :Sshkey, 'travis/cli/sshkey'
53+
autoload :Status, 'travis/cli/status'
54+
autoload :Sync, 'travis/cli/sync'
55+
autoload :Version, 'travis/cli/version'
56+
autoload :Whatsup, 'travis/cli/whatsup'
57+
autoload :Whoami, 'travis/cli/whoami'
5658

5759
extend self
5860

lib/travis/cli/help.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run(command = nil)
2121
[other_cmds, api_cmds, repo_cmds].each do |cmd_grp|
2222
say " #{cmd_grp.header}"
2323
cmd_grp.cmds.each do |cmd|
24-
say " #{color(cmd.command_name, :command).ljust(22)} #{color(cmd.description, :info)}"
24+
say " #{color(cmd.command_name, :command).ljust(25)} #{color(cmd.description, :info)}"
2525
end
2626
end
2727
say "\nrun `#{$PROGRAM_NAME} help COMMAND` for more info"

lib/travis/cli/regenerate_token.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'travis/cli'
2+
3+
module Travis
4+
module CLI
5+
class RegenerateToken < ApiCommand
6+
description "regenerates the stored API token"
7+
8+
def run
9+
token = session.regenerate_token['token']
10+
endpoint_config['access_token'] = token
11+
success("Successfully regenerated the token!")
12+
end
13+
end
14+
end
15+
end

lib/travis/cli/remove_token.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'travis/cli'
2+
3+
module Travis
4+
module CLI
5+
class RemoveToken < ApiCommand
6+
description "deletes the stored API token"
7+
8+
def run
9+
session.remove_token
10+
endpoint_config['access_token'] = nil
11+
success("Successfully removed the access token!")
12+
end
13+
end
14+
end
15+
end

lib/travis/client/methods.rb

+16
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def logout
9797
session.get_raw('/logout')
9898
end
9999

100+
def regenerate_token
101+
session.headers['Travis-Api-Version'] = '3'
102+
token = session.patch_raw('/access_token')
103+
session.headers.delete('Travis-Api-Version')
104+
105+
token
106+
end
107+
108+
def remove_token
109+
session.headers['Travis-Api-Version'] = '3'
110+
resp = session.delete_raw('/access_token')
111+
session.headers.delete('Travis-Api-Version')
112+
113+
resp
114+
end
115+
100116
def listen(*entities, &block)
101117
listener = Listener.new(session)
102118
listener.subscribe(*entities, &block)

lib/travis/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Travis
4-
VERSION = '1.12.0'
4+
VERSION = '1.13.0'
55
end

travis.gemspec

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Gem::Specification.new do |s|
55
# general info
66
s.name = 'travis'
7-
s.version = '1.12.0'
7+
s.version = '1.13.0'
88
s.required_ruby_version = '>= 3.2.0'
99
s.description = 'CLI and Ruby client library for Travis CI'
1010
s.homepage = 'https://github.com/travis-ci/travis.rb'
@@ -288,6 +288,8 @@ Gem::Specification.new do |s|
288288
'lib/travis/cli/parser.rb',
289289
'lib/travis/cli/pubkey.rb',
290290
'lib/travis/cli/raw.rb',
291+
'lib/travis/cli/regenerate_token.rb',
292+
'lib/travis/cli/remove_token.rb',
291293
'lib/travis/cli/repo_command.rb',
292294
'lib/travis/cli/report.rb',
293295
'lib/travis/cli/repos.rb',

0 commit comments

Comments
 (0)