sdls 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1649a83c3850e7e6a8657edfa6fce674ca844211d5264ef016dd9ddc6c413e8f
4
- data.tar.gz: f826f7983ee0a67f1c1aabaeb6e172df8541f76c63415dbbf028600d479beeef
3
+ metadata.gz: 80ab5c882f651304f21232bd31b312a328d08531c13db2a023e3a6ea28d47fd5
4
+ data.tar.gz: b40ac3decbb740eddef2e8a97e16e8079783bfa858b73ab922ef8849c3076eb6
5
5
  SHA512:
6
- metadata.gz: 17ab00c3765268aa845339d54e65caea98c69e791d3f9f1d13345ab6aea5c82bc58576449b0921b1e6d9720163e30c03337ad0e1b6fbd3241b60601fe13b13d1
7
- data.tar.gz: 54eca13f2a055533da40642741dd1e897816ea0daed83b59108cc92d53040bdeac0d29ebe3a5cdedf9e4ed19dd43c055113f3ee43a5ef0d5005d2470647f3d9f
6
+ metadata.gz: c2193a8357febf6e99d1164bdbdd7b12fbd7e374ba851ef267fda2b53f09bccde84fed20ddcc03d6ca72da39d177a6c698e8028abb04e0abbd84a2a058938a22
7
+ data.tar.gz: 48924c08c46cc3862e61cd6101c5b0c68b75500fdd3f43c46e9eb7c969591864954489b141e3bf0b9f092c888ad987e9790a1651e32be0c19bc288ed82c8add0
data/lib/sdls/cli.rb CHANGED
@@ -23,7 +23,8 @@ module SDLS
23
23
  host: current_config.host,
24
24
  username: current_config.username,
25
25
  password: current_config.password,
26
- op_item_name: current_config.op_item_name
26
+ op_item_name: current_config.op_item_name,
27
+ op_account: current_config.op_account
27
28
  )
28
29
  end
29
30
 
@@ -49,6 +50,7 @@ module SDLS
49
50
  puts " username: #{current_config.username}"
50
51
  puts " password: [REDACTED]"
51
52
  puts " op_item_name: #{current_config.op_item_name || "[NOT SET]"}"
53
+ puts " op_account: #{current_config.op_account || "[NOT SET]"}"
52
54
  puts " directories: #{current_config.directories.join(", ")}" if current_config.directories&.any?
53
55
  end
54
56
 
data/lib/sdls/client.rb CHANGED
@@ -6,11 +6,12 @@ require "tty-prompt"
6
6
 
7
7
  module SDLS
8
8
  class Client
9
- def initialize(host:, username:, password:, op_item_name: nil)
9
+ def initialize(host:, username:, password:, op_item_name: nil, op_account: nil)
10
10
  @host = host
11
11
  @username = username
12
12
  @password = password
13
13
  @op_item_name = op_item_name
14
+ @op_account = op_account
14
15
  end
15
16
 
16
17
  def authenticate(otp: nil)
@@ -121,7 +122,10 @@ module SDLS
121
122
  def fetch_otp_from_1password
122
123
  return nil unless @op_item_name
123
124
 
124
- stdout, stderr, status = Open3.capture3("op item get \"#{@op_item_name}\" --otp")
125
+ cmd = ["op", "item", "get", @op_item_name, "--otp"]
126
+ cmd += ["--account", @op_account] if @op_account && !@op_account.to_s.strip.empty?
127
+
128
+ stdout, stderr, status = Open3.capture3(*cmd)
125
129
  if status.success?
126
130
  stdout.strip
127
131
  else
data/lib/sdls/config.rb CHANGED
@@ -13,7 +13,7 @@ module SDLS
13
13
  # Core configuration keys that must be present
14
14
  REQUIRED_KEYS = %i[host].freeze
15
15
 
16
- Config = Data.define(:host, :username, :password, :op_item_name, :directories) do
16
+ Config = Data.define(:host, :username, :password, :op_item_name, :op_account, :directories) do
17
17
  class << self
18
18
  def load(path, prompt: nil)
19
19
  validate_file_exists!(path)
@@ -52,6 +52,7 @@ module SDLS
52
52
 
53
53
  def set_defaults(data)
54
54
  data[:op_item_name] ||= nil
55
+ data[:op_account] ||= nil
55
56
  data[:directories] ||= []
56
57
  data
57
58
  end
@@ -62,6 +63,7 @@ module SDLS
62
63
 
63
64
  def resolve_credentials(data, prompt: nil)
64
65
  op_item_name = data[:op_item_name]
66
+ op_account = data[:op_account]
65
67
 
66
68
  # Check if we have both username and password from config
67
69
  has_config_username = data[:username] && !data[:username].to_s.strip.empty?
@@ -77,7 +79,7 @@ module SDLS
77
79
 
78
80
  # If 1Password item is specified and we're missing some credentials, try to fetch from there
79
81
  if op_item_name && !op_item_name.to_s.strip.empty? && (!has_config_username || !has_config_password)
80
- onepassword_credentials = fetch_credentials_from_1password(op_item_name)
82
+ onepassword_credentials = fetch_credentials_from_1password(op_item_name, op_account)
81
83
  if onepassword_credentials[:success]
82
84
  final_username = has_config_username ? data[:username] : onepassword_credentials[:username]
83
85
  final_password = has_config_password ? data[:password] : onepassword_credentials[:password]
@@ -122,13 +124,13 @@ module SDLS
122
124
  prompt_for_credential("password", mask: true, prompt: prompt)
123
125
  end
124
126
 
125
- def fetch_credentials_from_1password(op_item_name)
127
+ def fetch_credentials_from_1password(op_item_name, op_account = nil)
126
128
  return {success: false} unless onepassword_cli_available?
127
129
 
128
130
  puts "Fetching credentials from 1Password for item: #{op_item_name}..."
129
131
 
130
- username = fetch_field_from_1password(op_item_name, "username")
131
- password = fetch_field_from_1password(op_item_name, "password")
132
+ username = fetch_field_from_1password(op_item_name, "username", op_account)
133
+ password = fetch_field_from_1password(op_item_name, "password", op_account)
132
134
 
133
135
  puts "1Password item '#{op_item_name}' retrieved successfully."
134
136
  puts "Username: #{username.nil? ? "not found" : username}"
@@ -152,10 +154,11 @@ module SDLS
152
154
  {success: false}
153
155
  end
154
156
 
155
- def fetch_field_from_1password(op_item_name, field)
156
- stdout, _, status = Open3.capture3(
157
- "op", "item", "get", op_item_name, "--fields", field, "--reveal"
158
- )
157
+ def fetch_field_from_1password(op_item_name, field, op_account = nil)
158
+ cmd = ["op", "item", "get", op_item_name, "--fields", field, "--reveal"]
159
+ cmd += ["--account", op_account] if op_account && !op_account.to_s.strip.empty?
160
+
161
+ stdout, _, status = Open3.capture3(*cmd)
159
162
 
160
163
  if status.success? && !stdout.strip.empty?
161
164
  stdout.strip
data/lib/sdls/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SDLS
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camillo Visini