Class: Terminalwire::Client::Entitlement::Policy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/terminalwire/client/entitlement/policy.rb

Overview

A policy has the authority, paths, and schemes that the server is allowed to access.

Direct Known Subclasses

Root

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authority:) ⇒ Base



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/terminalwire/client/entitlement/policy.rb', line 7

def initialize(authority:)
  @authority = authority
  @paths = Paths.new

  # Permit the domain directory. This is necessary for basic operation of the client.
  @paths.permit storage_path
  @paths.permit storage_pattern

  @schemes = Schemes.new
  # Permit http & https by default.
  @schemes.permit "http"
  @schemes.permit "https"

  @environment_variables = EnvironmentVariables.new
  # Permit the HOME and TERMINALWIRE_HOME environment variables.
  @environment_variables.permit "TERMINALWIRE_HOME"
end

Instance Attribute Details

#authorityObject (readonly)

Returns the value of attribute authority.



5
6
7
# File 'lib/terminalwire/client/entitlement/policy.rb', line 5

def authority
  @authority
end

#environment_variablesObject (readonly)

Returns the value of attribute environment_variables.



5
6
7
# File 'lib/terminalwire/client/entitlement/policy.rb', line 5

def environment_variables
  @environment_variables
end

#pathsObject (readonly)

Returns the value of attribute paths.



5
6
7
# File 'lib/terminalwire/client/entitlement/policy.rb', line 5

def paths
  @paths
end

#schemesObject (readonly)

Returns the value of attribute schemes.



5
6
7
# File 'lib/terminalwire/client/entitlement/policy.rb', line 5

def schemes
  @schemes
end

Instance Method Details

#authority_pathObject



30
31
32
# File 'lib/terminalwire/client/entitlement/policy.rb', line 30

def authority_path
  root_path.join("authorities/#{authority}")
end

#root_pathObject



25
26
27
28
# File 'lib/terminalwire/client/entitlement/policy.rb', line 25

def root_path
  # TODO: This needs to be passed into the Policy so that it can be set by the client.
  Terminalwire::Client.root_path
end

#serializeObject



42
43
44
45
46
47
48
49
# File 'lib/terminalwire/client/entitlement/policy.rb', line 42

def serialize
  {
    authority: @authority,
    schemes: @schemes.serialize,
    paths: @paths.serialize,
    environment_variables: @environment_variables.serialize
  }
end

#storage_pathObject



34
35
36
# File 'lib/terminalwire/client/entitlement/policy.rb', line 34

def storage_path
  authority_path.join("storage")
end

#storage_patternObject



38
39
40
# File 'lib/terminalwire/client/entitlement/policy.rb', line 38

def storage_pattern
  storage_path.join("**/*")
end