Class: MistApi::OrgApitoken

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

Overview

Org API Token Note: ‘privilege` field is required to create the object, but may not be returned in the POST API Response (only in the afterward GET)

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(name = nil, created_by = SKIP, created_time = SKIP, id = SKIP, key = SKIP, last_used = SKIP, org_id = SKIP, privileges = SKIP, src_ips = SKIP, additional_properties = nil) ⇒ OrgApitoken

Returns a new instance of OrgApitoken.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/mist_api/models/org_apitoken.rb', line 89

def initialize(name = nil, created_by = SKIP, created_time = SKIP,
               id = SKIP, key = SKIP, last_used = SKIP, org_id = SKIP,
               privileges = SKIP, src_ips = SKIP,
               additional_properties = nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @created_by = created_by unless created_by == SKIP
  @created_time = created_time unless created_time == SKIP
  @id = id unless id == SKIP
  @key = key unless key == SKIP
  @last_used = last_used unless last_used == SKIP
  @name = name
  @org_id = org_id unless org_id == SKIP
  @privileges = privileges unless privileges == SKIP
  @src_ips = src_ips unless src_ips == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#created_byString

email of the token creator / null if creator is deleted

Returns:

  • (String)


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

def created_by
  @created_by
end

#created_timeFloat

When the object has been created, in epoch

Returns:

  • (Float)


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

def created_time
  @created_time
end

#idUUID | String

Unique ID of the object instance in the Mist Organization

Returns:

  • (UUID | String)


24
25
26
# File 'lib/mist_api/models/org_apitoken.rb', line 24

def id
  @id
end

#keyString

Unique ID of the object instance in the Mist Organization

Returns:

  • (String)


28
29
30
# File 'lib/mist_api/models/org_apitoken.rb', line 28

def key
  @key
end

#last_usedFloat

Unique ID of the object instance in the Mist Organization

Returns:

  • (Float)


32
33
34
# File 'lib/mist_api/models/org_apitoken.rb', line 32

def last_used
  @last_used
end

#nameString

Name of the token

Returns:

  • (String)


36
37
38
# File 'lib/mist_api/models/org_apitoken.rb', line 36

def name
  @name
end

#org_idUUID | String

Name of the token

Returns:

  • (UUID | String)


40
41
42
# File 'lib/mist_api/models/org_apitoken.rb', line 40

def org_id
  @org_id
end

#privilegesArray[PrivilegeOrg]

List of privileges the token has on the orgs/sites

Returns:



44
45
46
# File 'lib/mist_api/models/org_apitoken.rb', line 44

def privileges
  @privileges
end

#src_ipsArray[String]

List of allowed IP addresses from where the token can be used from. At most 10 IP addresses can be specified, cannot be changed once the API Token is created.

Returns:

  • (Array[String])


50
51
52
# File 'lib/mist_api/models/org_apitoken.rb', line 50

def src_ips
  @src_ips
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/mist_api/models/org_apitoken.rb', line 109

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  created_by = hash.key?('created_by') ? hash['created_by'] : SKIP
  created_time = hash.key?('created_time') ? hash['created_time'] : SKIP
  id = hash.key?('id') ? hash['id'] : SKIP
  key = hash.key?('key') ? hash['key'] : SKIP
  last_used = hash.key?('last_used') ? hash['last_used'] : SKIP
  org_id = hash.key?('org_id') ? hash['org_id'] : SKIP
  # Parameter is an array, so we need to iterate through it
  privileges = nil
  unless hash['privileges'].nil?
    privileges = []
    hash['privileges'].each do |structure|
      privileges << (PrivilegeOrg.from_hash(structure) if structure)
    end
  end

  privileges = SKIP unless hash.key?('privileges')
  src_ips = hash.key?('src_ips') ? hash['src_ips'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  OrgApitoken.new(name,
                  created_by,
                  created_time,
                  id,
                  key,
                  last_used,
                  org_id,
                  privileges,
                  src_ips,
                  additional_properties)
end

.namesObject

A mapping from model property names to API property names.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/mist_api/models/org_apitoken.rb', line 53

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['created_by'] = 'created_by'
  @_hash['created_time'] = 'created_time'
  @_hash['id'] = 'id'
  @_hash['key'] = 'key'
  @_hash['last_used'] = 'last_used'
  @_hash['name'] = 'name'
  @_hash['org_id'] = 'org_id'
  @_hash['privileges'] = 'privileges'
  @_hash['src_ips'] = 'src_ips'
  @_hash
end

.nullablesObject

An array for nullable fields



82
83
84
85
86
87
# File 'lib/mist_api/models/org_apitoken.rb', line 82

def self.nullables
  %w[
    created_by
    last_used
  ]
end

.optionalsObject

An array for optional fields



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mist_api/models/org_apitoken.rb', line 68

def self.optionals
  %w[
    created_by
    created_time
    id
    key
    last_used
    org_id
    privileges
    src_ips
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



161
162
163
164
165
166
167
# File 'lib/mist_api/models/org_apitoken.rb', line 161

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} created_by: #{@created_by.inspect}, created_time: #{@created_time.inspect},"\
  " id: #{@id.inspect}, key: #{@key.inspect}, last_used: #{@last_used.inspect}, name:"\
  " #{@name.inspect}, org_id: #{@org_id.inspect}, privileges: #{@privileges.inspect}, src_ips:"\
  " #{@src_ips.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



153
154
155
156
157
158
# File 'lib/mist_api/models/org_apitoken.rb', line 153

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} created_by: #{@created_by}, created_time: #{@created_time}, id: #{@id},"\
  " key: #{@key}, last_used: #{@last_used}, name: #{@name}, org_id: #{@org_id}, privileges:"\
  " #{@privileges}, src_ips: #{@src_ips}, additional_properties: #{@additional_properties}>"
end