Sha256: 737f7127d44789b3995f352909081b2e6511c9c0c19011c95294a561b06294ef

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require 'macaroons/raw_macaroon'

module Macaroons
  class Macaroon
    def initialize(key: nil, identifier: nil, location: nil, raw_macaroon: nil)
      @raw_macaroon = raw_macaroon || RawMacaroon.new(key: key, identifier: identifier, location: location)
    end

    def identifier
      @raw_macaroon.identifier
    end

    def location
      @raw_macaroon.location
    end

    def signature
      @raw_macaroon.signature
    end

    def caveats
      @raw_macaroon.caveats
    end

    def self.from_binary(serialized)
      raw_macaroon = RawMacaroon.from_binary(serialized: serialized)
      macaroon = Macaroons::Macaroon.new(raw_macaroon: raw_macaroon)
    end

    def self.from_json(serialized)
      raw_macaroon = RawMacaroon.from_json(serialized: serialized)
      macaroon = Macaroons::Macaroon.new(raw_macaroon: raw_macaroon)
    end

    def serialize
      @raw_macaroon.serialize()
    end

    def serialize_json
      @raw_macaroon.serialize_json()
    end

    def add_first_party_caveat(predicate)
      @raw_macaroon.add_first_party_caveat(predicate)
    end

    def first_party_caveats
      caveats.select(&:first_party?)
    end

    def add_third_party_caveat(caveat_key, caveat_id, caveat_location)
      @raw_macaroon.add_third_party_caveat(caveat_key, caveat_id, caveat_location)
    end

    def third_party_caveats
      caveats.select(&:third_party?)
    end

    def prepare_for_request(macaroon)
      @raw_macaroon.prepare_for_request(macaroon)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
macaroons-0.4.1 lib/macaroons/macaroons.rb
macaroons-0.4.0 lib/macaroons/macaroons.rb