Class: Virgil::SDK::HighLevel::VirgilCardManager
- Inherits:
-
Object
- Object
- Virgil::SDK::HighLevel::VirgilCardManager
- Defined in:
- lib/virgil/sdk/high_level/virgil_card_manager.rb
Defined Under Namespace
Classes: AccessTokenException, AppCredentialsException, CardArray
Instance Method Summary collapse
-
#create(identity, owner_key, custom_data = {}) ⇒ Object
Creates a new Virgil Card that is representing user’s Public key and information.
-
#create_global(identity:, identity_type:, owner_key:, custom_data: {}) ⇒ Object
Creates a new Global Virgil Card that is representing user’s Public key and information.
-
#find(*identities) ⇒ Object
Find Virgil cards by specified identities in application scope.
- #find_global(identity_type, *identities) ⇒ Object
-
#get(card_id) ⇒ Object
Get a card from Virgil Security services by specified Card ID.
-
#import(exported_card) ⇒ Object
Create new Card from base64-encoded json representation of card’s content_snapshot and meta.
-
#initialize(context) ⇒ VirgilCardManager
constructor
A new instance of VirgilCardManager.
-
#publish(card) ⇒ Object
Publish synchronously a card into application Virgil Services scope Args: card: the card to be published Raises: Client::HTTP::BaseConnection::ApiError if application credentials is invalid or Virgil Card with the same fingerprint already exists in Virgil Security services.
-
#publish_async(card) ⇒ Object
Publish asynchronously a card into application Virgil Services scope Args: card: the card to be published Raises: Virgil::SDK::Client::HTTP::BaseConnection::ApiError if application credentials is invalid or Virgil Card with the same fingerprint already exists in Virgil Security services.
-
#publish_global(card, validation_token) ⇒ Object
Publish a global card into application Virgil Services scope Args: card: the global card to be published Raises: Client::HTTP::BaseConnection::ApiError if VirgilIdentity Validation Token is invalid or has expired Virgil Card with the same fingerprint already exists in Virgil Security services.
-
#revoke(card) ⇒ Object
Revoke a card from Virgil Services.
-
#revoke_global(global_card, key_pair, validation_token) ⇒ Object
Revoke a global card from Virgil Services.
Constructor Details
#initialize(context) ⇒ VirgilCardManager
Returns a new instance of VirgilCardManager.
41 42 43 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 41 def initialize(context) @context = context end |
Instance Method Details
#create(identity, owner_key, custom_data = {}) ⇒ Object
Creates a new Virgil Card that is representing user’s Public key and information
Args:
identity: The user's identity.
owner_key: The owner's Virgil key.
custom_data(optional): is an associative array that contains application specific
parameters(under key :data) and information about the device
on which the keypair was created(under key :device and :device_name).
example: {data: {my_key1: "my_val1", my_key2: "my_val2"}, device: "iPhone6s", device_name: "Space grey one"}
Returns:
Created unpublished Virgil Card that is representing user's Public key
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 112 def create(identity, owner_key, custom_data={}) card = context.client.new_card( identity, VirgilIdentity::USERNAME, owner_key.private_key, custom_data ) VirgilCard.new(context: context, card: card) end |
#create_global(identity:, identity_type:, owner_key:, custom_data: {}) ⇒ Object
Creates a new Global Virgil Card that is representing user’s Public key and information
Args:
identity: The user's identity.
owner_key: The owner's Virgil key.
custom_data(optional): is an associative array that contains application specific
parameters(under key :data) and information about the device
on which the keypair was created(under key :device and :device_name).
example: {data: {my_key1: "my_val1", my_key2: "my_val2"}, device: "iPhone6s", device_name: "Space grey one"}
Returns:
Created unpublished Global Virgil Card that is representing user's Public key
136 137 138 139 140 141 142 143 144 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 136 def create_global(identity:, identity_type:, owner_key:, custom_data: {}) card = context.client.new_global_card( identity, identity_type, owner_key.private_key, custom_data ) VirgilCard.new(context: context, card: card) end |
#find(*identities) ⇒ Object
Find Virgil cards by specified identities in application scope.
Args:
identities: the list of identities
Returns:
A list of found Virgil cards
Raises:
VirgilClient::InvalidCardException if client has validator
and retrieved card signatures are not valid.
AccessTokenException:: "For this operation access token can't be empty"
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 209 def find(*identities) raise AccessTokenException unless (context && context.access_token) validate_identities_param(identities) cards = context.client.search_cards_by_identities(*identities) virgil_cards = cards.map { |v| VirgilCard.new(context: context, card: v) } CardArray.new(virgil_cards) end |
#find_global(identity_type, *identities) ⇒ Object
221 222 223 224 225 226 227 228 229 230 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 221 def find_global(identity_type, *identities) validate_identities_param(identities) cards = context.client.search_cards_by_criteria( Client::SearchCriteria.new(identities, identity_type, Client::Card::GLOBAL) ) virgil_global_cards = cards.map { |v| VirgilCard.new(context: context, card: v) } CardArray.new(virgil_global_cards) end |
#get(card_id) ⇒ Object
Get a card from Virgil Security services by specified Card ID.
Args:
card_id: unique string that identifies the Card within Virgil Security services
Returns:
Found card from server response.
Raises:
VirgilClient::InvalidCardException if client has validator
and retrieved card signatures are not valid.
191 192 193 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 191 def get(card_id) VirgilCard.new(context: context, card: context.client.get_card(card_id)) end |
#import(exported_card) ⇒ Object
Create new Card from base64-encoded json representation of card’s content_snapshot and meta
Args:
base64-encoded json representation of card
Returns:
Virgil Card restored from snapshot.
276 277 278 279 280 281 282 283 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 276 def import(exported_card) request = Client::Requests::CreateCardRequest.import(exported_card) VirgilCard.new( context: self.context, card: Client::Card.from_request_model(request.request_model) ) end |
#publish(card) ⇒ Object
Publish synchronously a card into application Virgil Services scope Args:
card: the card to be published
Raises: Client::HTTP::BaseConnection::ApiError if application credentials is invalid or Virgil Card with the same fingerprint already exists in Virgil Security services
164 165 166 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 164 def publish(card) card.publish end |
#publish_async(card) ⇒ Object
Publish asynchronously a card into application Virgil Services scope Args:
card: the card to be published
Raises: Virgil::SDK::Client::HTTP::BaseConnection::ApiError if application credentials is invalid or Virgil Card with the same fingerprint already exists in Virgil Security services
153 154 155 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 153 def publish_async(card) card.publish_async end |
#publish_global(card, validation_token) ⇒ Object
Publish a global card into application Virgil Services scope Args:
card: the global card to be published
Raises: Client::HTTP::BaseConnection::ApiError if VirgilIdentity Validation Token is invalid or has expired Virgil Card with the same fingerprint already exists in Virgil Security services
175 176 177 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 175 def publish_global(card, validation_token) card.publish_as_global(validation_token) end |
#revoke(card) ⇒ Object
Revoke a card from Virgil Services
Args:
card: the card to be revoked
Raises:
Client::HTTP::BaseConnection::ApiError if the card was not published
or application credentials is not valid.
AppCredentialsException: For this operation we need app_id and app_key
if application credentials are missing
244 245 246 247 248 249 250 251 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 244 def revoke(card) validate_app_credentials context.client.revoke_card( card.id, context.credentials.app_id, context.credentials.app_key(context.crypto)) end |
#revoke_global(global_card, key_pair, validation_token) ⇒ Object
Revoke a global card from Virgil Services
Args:
card: the global card to be revoked
Raises:
Client::HTTP::BaseConnection::ApiError if the global card was not published
Client::HTTP::BaseConnection::ApiError if VirgilIdentity Validation Token is invalid or has expired
262 263 264 265 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 262 def revoke_global(global_card, key_pair, validation_token) context.client.revoke_global_card(global_card.id, key_pair, validation_token) end |