Class: SupportOps::GitLab::UserTokens
- Defined in:
- lib/support_ops_gitlab/gitlab/user_tokens.rb
Overview
Get details on a personal access token => docs.gitlab.com/api/personal_access_tokens/#get-details-on-a-personal-access-token
List all token associations => docs.gitlab.com/api/personal_access_tokens/#list-all-token-associations
Get an impersonation token for a user => docs.gitlab.com/api/user_tokens/#get-an-impersonation-token-for-a-user
Defines the class UserTokens within the module SupportOps::GitLab.
Instance Attribute Summary collapse
-
#active ⇒ Boolean
If the token is active or not.
-
#created_at ⇒ String
Timestamp when the token was created.
-
#description ⇒ String
Description of token.
-
#expires_at ⇒ String
Expiration date of the token in ISO format (YYYY-MM-DD).
-
#id ⇒ Integer
ID of token.
-
#impersonation ⇒ Boolean
If the token is an impersonation token.
-
#name ⇒ String
Name of token.
-
#revoked ⇒ Boolean
If the token is revoked or not.
-
#scopes ⇒ Array
Array of approved scopes.
-
#token ⇒ String
The token itself.
-
#user_id ⇒ Integer
ID of user account.
Class Method Summary collapse
-
.list(key: value) ⇒ Array
List all impersonation tokens for a user.
-
.list(key: value) ⇒ Array
List all personal access tokens.
Instance Method Summary collapse
-
#revoke! ⇒ Object
Revokes a token (personal access or impersonation).
-
#rotate! ⇒ Object
Rotates a personal access token (does not work on impersonation tokens).
-
#save! ⇒ Object
Creates a user token (personal access or impersonation).
Methods inherited from Base
#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #delete!, #diffs, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #ssh_keys, #status, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks
Constructor Details
This class inherits a constructor from SupportOps::GitLab::Base
Instance Attribute Details
#active ⇒ Boolean
If the token is active or not
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def active @active end |
#created_at ⇒ String
Timestamp when the token was created
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def created_at @created_at end |
#description ⇒ String
Description of token
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def description @description end |
#expires_at ⇒ String
Expiration date of the token in ISO format (YYYY-MM-DD)
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def expires_at @expires_at end |
#id ⇒ Integer
ID of token
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def id @id end |
#impersonation ⇒ Boolean
If the token is an impersonation token
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def impersonation @impersonation end |
#name ⇒ String
Name of token
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def name @name end |
#revoked ⇒ Boolean
If the token is revoked or not
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def revoked @revoked end |
#scopes ⇒ Array
Array of approved scopes
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def scopes @scopes end |
#token ⇒ String
The token itself
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def token @token end |
#user_id ⇒ Integer
ID of user account
26 27 28 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 26 def user_id @user_id end |
Class Method Details
.list(key: value) ⇒ Array
List all impersonation tokens for a user
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 265 def self.list_impersonation(**args) raise 'You must provide a user_id for this' unless args[:user_id] args[:state] = nil unless args[:state] params = '' params += "state=#{args[:state]}&" unless args[:state].nil? tokens = [] page = 1 loop do response = client.connection.get("users/#{args[:user_id]}/impersonation_tokens?#{params}&page=#{page}&per_page=100") body = Oj.load(response.body) tokens += body.map { |p| UserTokens.new(p) } break if body.count < 100 page += 1 end tokens end |
.list(key: value) ⇒ Array
List all personal access tokens
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 201 def self.list_pats(**args) args[:created_after] = nil unless args[:created_after] args[:created_before] = nil unless args[:created_before] args[:expires_after] = nil unless args[:expires_after] args[:expires_before] = nil unless args[:expires_before] args[:last_used_after] = nil unless args[:last_used_after] args[:last_used_before] = nil unless args[:last_used_before] args[:revoked] = nil unless args[:revoked] args[:search] = nil unless args[:search] args[:state] = nil unless args[:state] args[:user_id] = nil unless args[:user_id] params = '' params += "created_after=#{args[:created_after]}&" unless args[:created_after].nil? params += "created_before=#{args[:created_before]}&" unless args[:created_before].nil? params += "expires_after=#{args[:expires_after]}&" unless args[:expires_after].nil? params += "expires_before=#{args[:expires_before]}&" unless args[:expires_before].nil? params += "last_used_after=#{args[:last_used_after]}&" unless args[:last_used_after].nil? params += "last_used_before=#{args[:last_used_before]}&" unless args[:last_used_before].nil? params += "revoked=#{args[:revoked]}&" unless args[:revoked].nil? params += "search=#{args[:search]}&" unless args[:search].nil? params += "state=#{args[:state]}&" unless args[:state].nil? params += "user_id=#{args[:user_id]}&" unless args[:user_id].nil? tokens = [] page = 1 loop do response = client.connection.get("personal_access_tokens?#{params}&page=#{page}&per_page=100") body = Oj.load(response.body) tokens += body.map { |p| UserTokens.new(p) } break if body.count < 100 page += 1 end tokens end |
Instance Method Details
#revoke! ⇒ Object
This is inherited from Base#revoke!
Revokes a token (personal access or impersonation)
24 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 24 def revoke!; end |
#rotate! ⇒ Object
This is inherited from Base#rotate!
Rotates a personal access token (does not work on impersonation tokens)
23 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 23 def rotate!; end |
#save! ⇒ Object
This is inherited from Base#save!
Creates a user token (personal access or impersonation)
75 |
# File 'lib/support_ops_gitlab/gitlab/user_tokens.rb', line 75 def save!; end |