Class: Totvs::PasswordVault::Key

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
JsonParser
Defined in:
lib/totvs/password_vault/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JsonParser

#parse_json

Constructor Details

#initialize(connection: nil) ⇒ Key



16
17
18
# File 'lib/totvs/password_vault/key.rb', line 16

def initialize(connection: nil)
  @connection = connection
end

Instance Attribute Details

#connectionObject



20
21
22
# File 'lib/totvs/password_vault/key.rb', line 20

def connection
  @connection ||= Connection.new
end

Instance Method Details

#destroy(id:) ⇒ Object

Raises:



108
109
110
111
# File 'lib/totvs/password_vault/key.rb', line 108

def destroy(id:)
  headers = { "Accept" => "application/json" }
  delete path: build_path(id), headers: headers
end

#retrieve(id:) ⇒ Hash<Symbol, String>

Returns content the saved content @param public_key [String] @param private_key [String] @param hostname [String] @param ip [String] @param username [String] @param maker [String] @param device_type [String] @param device_model [String] @param site [String] @param password_type [String] @param tags [Array].

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/totvs/password_vault/key.rb', line 38

def retrieve(id:)
  headers = { "Accept" => "application/json" }
  response = get(path: build_path(id), headers: headers)
  response = parse_json response.body

  {
    public_key: response["chave"]["chave_publica"],
    private_key: response["chave"]["chave_privada"],
    hostname: response["chave"]["hostname"],
    ip: response["chave"]["ip"],
    username: response["chave"]["username"],
    maker: response["chave"]["fabricante"],
    device_type: response["chave"]["tipo"],
    device_model: response["chave"]["modelo"],
    site: response["chave"]["site"],
    password_type: response["chave"]["tipo_senha"],
    tags: response["chave"]["tags"]
  }
end

#save(id:, public_key:, private_key:, hostname:, ip:, username: nil, maker: nil, device_type: nil, device_model: nil, site: nil, password_type: nil, tags: [], **kwargs) ⇒ Object



69
70
71
72
73
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
101
102
103
104
# File 'lib/totvs/password_vault/key.rb', line 69

def save(
  id:,
  public_key:,
  private_key:,
  hostname:,
  ip:,
  username: nil,
  maker: nil,
  device_type: nil,
  device_model: nil,
  site: nil,
  password_type: nil,
  tags: [],
  **kwargs
)
  headers = {
    "Accept" => "application/json",
    "Content-Type" => "application/json"
  }

  body = {
    chave_publica: public_key,
    chave_privada: private_key,
    hostname: hostname,
    ip: ip,
    username: username,
    fabricante: maker,
    tipo: device_type,
    modelo: device_model,
    site: site,
    tipo_senha: password_type,
    tags: tags.compact
  }.merge(kwargs).delete_if { |_, value| value.nil? || value.empty? }

  post path: build_path(id), body: body, headers: headers
end