Class: Totvs::PasswordVault::Key
- Inherits:
-
Object
- Object
- Totvs::PasswordVault::Key
- Extended by:
- Forwardable
- Includes:
- JsonParser
- Defined in:
- lib/totvs/password_vault/key.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #destroy(id:) ⇒ Object
-
#initialize(connection: nil) ⇒ Key
constructor
A new instance of Key.
-
#retrieve(id:) ⇒ Hash<Symbol, String>
Content the saved content.
- #save(id:, public_key:, private_key:, hostname:, ip:, username: nil, maker: nil, device_type: nil, device_model: nil, site: nil, password_type: nil, expiration_time: nil, tags: [], **kwargs) ⇒ Object
Methods included from JsonParser
Constructor Details
#initialize(connection: nil) ⇒ Key
Returns a new instance of Key.
17 18 19 |
# File 'lib/totvs/password_vault/key.rb', line 17 def initialize(connection: nil) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object
21 22 23 |
# File 'lib/totvs/password_vault/key.rb', line 21 def connection @connection ||= Connection.new end |
Instance Method Details
#destroy(id:) ⇒ Object
113 114 115 116 |
# File 'lib/totvs/password_vault/key.rb', line 113 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].
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/totvs/password_vault/key.rb', line 39 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"], expiration_time: response["chave"]["datahora_expiracao"], 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, expiration_time: nil, tags: [], **kwargs) ⇒ Object
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 105 106 107 108 109 |
# File 'lib/totvs/password_vault/key.rb', line 72 def save( id:, public_key:, private_key:, hostname:, ip:, username: nil, maker: nil, device_type: nil, device_model: nil, site: nil, password_type: nil, expiration_time: 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, datahora_expiracao: expiration_time ? expiration_time.iso8601 : nil, tags: .compact.join(", ") }.merge(kwargs).delete_if { |_, value| value.nil? || value.empty? } post path: build_path(id), body: body, headers: headers end |