class WarpEngine::AdminApi::Principal
The authenticated caller of the Admin API: who owns it, which scopes it holds and, when it came from one, the WarpEngine::ApplicationToken behind it. Returned by the Authenticator (or the host’s own authenticator).
Attributes
The owning record (the host’s token owner, e.g. a user), the frozen scope strings, a display label and the application token, when there is one.
The owning record (the host’s token owner, e.g. a user), the frozen scope strings, a display label and the application token, when there is one.
The owning record (the host’s token owner, e.g. a user), the frozen scope strings, a display label and the application token, when there is one.
The owning record (the host’s token owner, e.g. a user), the frozen scope strings, a display label and the application token, when there is one.
Public Class Methods
Source
# File lib/warp_engine/admin_api/principal.rb, line 12 def self.from_token(token) new(owner: token.owner, scopes: token.scopes, unrestricted: token.unrestricted?, label: token.name, token: token) end
Builds the principal of an authenticated WarpEngine::ApplicationToken token.
# File lib/warp_engine/admin_api/principal.rb, line 22 def initialize(owner:, scopes:, unrestricted: false, label: nil, token: nil) @owner = owner @scopes = Array(scopes).map(&:to_s).freeze @unrestricted = unrestricted ? true : false @label = label @token = token end
- owner
-
the record the caller acts for
- scopes
-
the scopes it holds, strings or symbols
- unrestricted
-
whether it may grant unrestricted tokens
- label
-
a display name
- token
-
the
WarpEngine::ApplicationTokenit came from, if any
Public Instance Methods
Source
# File lib/warp_engine/admin_api/principal.rb, line 50 def as_json(*) { label: label, ownerType: owner&.class&.name, ownerId: owner.try(:id), scopes: scopes, unrestricted: unrestricted?, tokenPrefix: token&.token_prefix, expiresAt: expires_at } end
The JSON form shown by GET /me: label, ownerType, ownerId, scopes, unrestricted, tokenPrefix and expiresAt.
Source
# File lib/warp_engine/admin_api/principal.rb, line 39 def expires_at = token&.expires_at
When the caller’s token expires, or nil when it never does or there is no token.
Source
# File lib/warp_engine/admin_api/principal.rb, line 42 def rate_limit_key return "token:#{token.id}" if token "principal:#{owner.class.name}:#{owner.try(:id)}:#{label}" end
The key the RateLimiter counts requests under: the token id, or the owner and label.
Source
# File lib/warp_engine/admin_api/principal.rb, line 34 def scope?(scope) scopes.include?(scope.to_s) end
Whether the caller holds scope.
Source
# File lib/warp_engine/admin_api/principal.rb, line 31 def unrestricted? = @unrestricted
Whether the caller is unrestricted.