lib/terminalwire/client/entitlement.rb in terminalwire-0.1.15 vs lib/terminalwire/client/entitlement.rb in terminalwire-0.1.16
- old
+ new
@@ -143,12 +143,11 @@
def root_path
Pathname.new(ROOT_PATH)
end
def authority_path
- # TODO: Change this so it's per endpoint and not domain
- root_path.join("authorities/#{authority.domain}")
+ root_path.join("authorities/#{authority}")
end
def storage_path
authority_path.join("storage")
end
@@ -157,11 +156,11 @@
storage_path.join("**/*")
end
def serialize
{
- authority: @authority.to_s,
+ authority: @authority,
schemes: @schemes.serialize,
paths: @paths.serialize,
storage_path: storage_path.to_s,
}
end
@@ -202,16 +201,26 @@
binary_path.join("*")
end
end
def self.from_url(url)
- authority = Terminalwire::Authority.new(url:)
+ url = URI(url)
- case authority.domain
+ case url.host
when RootPolicy::HOST
- RootPolicy.new authority:
+ RootPolicy.new
else
- Policy.new authority:
+ Policy.new authority: url_authority(url)
+ end
+ end
+
+ def self.url_authority(url)
+ # I had to lift this from URI::HTTP because `ws://` doesn't
+ # have an authority method.
+ if url.port == url.default_port
+ url.host
+ else
+ "#{url.host}:#{url.port}"
end
end
end
end