require "db/mongo/models/key"
require_relative 'base'

module Connectors
  class Key < Base
    include Helpers::InsertCommand,
      Helpers::ShowCommand,
      Helpers::ListCommand,
      Helpers::DeleteCommand

    def initialize(db)
      super(db)
    end

    def collection_name
      'keys'
    end

    def key(id, scope=nil)
      options = scope ? {'scope' => scope} : {}
      show(id, options)
    end

    def key_delete id
      delete(id, 'scope' => Devops::Model::Key::USER)
    end

    private

    def model_from_bson(bson)
      Devops::Model::Key.build_from_bson(bson)
    end
  end

end
