Class: MistApi::ProtectRe

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/mist_api/models/protect_re.rb

Overview

Restrict inbound-traffic to host when enabled, all traffic that is not essential to our operation will be dropped e.g. ntp / dns / traffic to mist will be allowed by default, if dhcpd is enabled, we’ll make sure it works

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(allowed_services = SKIP, custom = SKIP, enabled = false, hit_count = false, trusted_hosts = SKIP) ⇒ ProtectRe

Returns a new instance of ProtectRe.



64
65
66
67
68
69
70
71
# File 'lib/mist_api/models/protect_re.rb', line 64

def initialize(allowed_services = SKIP, custom = SKIP, enabled = false,
               hit_count = false, trusted_hosts = SKIP)
  @allowed_services = allowed_services unless allowed_services == SKIP
  @custom = custom unless custom == SKIP
  @enabled = enabled unless enabled == SKIP
  @hit_count = hit_count unless hit_count == SKIP
  @trusted_hosts = trusted_hosts unless trusted_hosts == SKIP
end

Instance Attribute Details

#allowed_servicesArray[ProtectReAllowedServiceEnum]

Optionally, services we’ll allow

Returns:



16
17
18
# File 'lib/mist_api/models/protect_re.rb', line 16

def allowed_services
  @allowed_services
end

#customArray[ProtectReCustom]

Optionally, services we’ll allow

Returns:



20
21
22
# File 'lib/mist_api/models/protect_re.rb', line 20

def custom
  @custom
end

#enabledTrueClass | FalseClass

When enabled, all traffic that is not essential to our operation will be dropped e.g. ntp / dns / traffic to mist will be allowed by default

if dhcpd is enabled, we'll make sure it works

Returns:

  • (TrueClass | FalseClass)


27
28
29
# File 'lib/mist_api/models/protect_re.rb', line 27

def enabled
  @enabled
end

#hit_countTrueClass | FalseClass

Whether to enable hit count for Protect_RE policy

Returns:

  • (TrueClass | FalseClass)


31
32
33
# File 'lib/mist_api/models/protect_re.rb', line 31

def hit_count
  @hit_count
end

#trusted_hostsArray[String]

host/subnets we’ll allow traffic to/from

Returns:

  • (Array[String])


35
36
37
# File 'lib/mist_api/models/protect_re.rb', line 35

def trusted_hosts
  @trusted_hosts
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mist_api/models/protect_re.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  allowed_services =
    hash.key?('allowed_services') ? hash['allowed_services'] : SKIP
  # Parameter is an array, so we need to iterate through it
  custom = nil
  unless hash['custom'].nil?
    custom = []
    hash['custom'].each do |structure|
      custom << (ProtectReCustom.from_hash(structure) if structure)
    end
  end

  custom = SKIP unless hash.key?('custom')
  enabled = hash['enabled'] ||= false
  hit_count = hash['hit_count'] ||= false
  trusted_hosts = hash.key?('trusted_hosts') ? hash['trusted_hosts'] : SKIP

  # Create object from extracted values.
  ProtectRe.new(allowed_services,
                custom,
                enabled,
                hit_count,
                trusted_hosts)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
46
# File 'lib/mist_api/models/protect_re.rb', line 38

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['allowed_services'] = 'allowed_services'
  @_hash['custom'] = 'custom'
  @_hash['enabled'] = 'enabled'
  @_hash['hit_count'] = 'hit_count'
  @_hash['trusted_hosts'] = 'trusted_hosts'
  @_hash
end

.nullablesObject

An array for nullable fields



60
61
62
# File 'lib/mist_api/models/protect_re.rb', line 60

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
56
57
# File 'lib/mist_api/models/protect_re.rb', line 49

def self.optionals
  %w[
    allowed_services
    custom
    enabled
    hit_count
    trusted_hosts
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (ProtectRe | Hash)

    value against the validation is performed.



104
105
106
107
108
109
110
# File 'lib/mist_api/models/protect_re.rb', line 104

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



120
121
122
123
124
125
# File 'lib/mist_api/models/protect_re.rb', line 120

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} allowed_services: #{@allowed_services.inspect}, custom: #{@custom.inspect},"\
  " enabled: #{@enabled.inspect}, hit_count: #{@hit_count.inspect}, trusted_hosts:"\
  " #{@trusted_hosts.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



113
114
115
116
117
# File 'lib/mist_api/models/protect_re.rb', line 113

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} allowed_services: #{@allowed_services}, custom: #{@custom}, enabled:"\
  " #{@enabled}, hit_count: #{@hit_count}, trusted_hosts: #{@trusted_hosts}>"
end