class Virgil::SDK::HighLevel::VirgilCardManager

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/virgil/sdk/high_level/virgil_card_manager.rb, line 41
def initialize(context)
  @context = context
end

Public Instance Methods

create(identity, owner_key, custom_data={}) click to toggle source

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
# 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: {}) click to toggle source

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
# 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) click to toggle source

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"
# 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) click to toggle source
# 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) click to toggle source

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.
# 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) click to toggle source

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.
# 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) click to toggle source

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

# File lib/virgil/sdk/high_level/virgil_card_manager.rb, line 164
def publish(card)
  card.publish
end
publish_async(card) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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
# 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) click to toggle source

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
# 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

Private Instance Methods

validate_app_credentials() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card_manager.rb, line 292
def validate_app_credentials

  if !(context.credentials && context.credentials.app_id && context.credentials.app_key(context.crypto))
    raise AppCredentialsException
  end

end
validate_identities_param(param) click to toggle source
# File lib/virgil/sdk/high_level/virgil_card_manager.rb, line 288
def validate_identities_param(param)
  raise ArgumentError.new("identities is not valid") if (!param.is_a?(Array) || param.empty?)
end