switch-case-passbolt-sdk 0.1.1 → 0.1.6
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 +4 -4
- data/lib/native/darwin-aarch64/libpassbolt_ffi.dylib +0 -0
- data/lib/native/darwin-x86_64/libpassbolt_ffi.dylib +0 -0
- data/lib/native/linux-aarch64/libpassbolt_ffi.so +0 -0
- data/lib/native/linux-x86_64/libpassbolt_ffi.so +0 -0
- data/lib/native/windows-x86_64/passbolt_ffi.dll +0 -0
- data/lib/passbolt/passbolt_ffi.rb +7593 -0
- data/lib/passbolt.rb +208 -0
- data/lib/passbolt_sdk.rb +3 -9
- metadata +4 -3
- data/lib/passbolt_ffi.rb +0 -5418
data/lib/passbolt.rb
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Entry point of the gem: the generated UniFFI bindings (PassboltFfi), with Ruby names.
|
|
4
|
+
#
|
|
5
|
+
# require "passbolt"
|
|
6
|
+
#
|
|
7
|
+
# Passbolt::Client.login(url, File.read("private.asc"), passphrase) do |client|
|
|
8
|
+
# client.list_resource_views("github").each { |view| puts view.name }
|
|
9
|
+
# end
|
|
10
|
+
require "English"
|
|
11
|
+
require "ffi"
|
|
12
|
+
|
|
13
|
+
module Passbolt
|
|
14
|
+
# The native library of this platform, shipped under lib/native/<os>-<arch>/: the generated
|
|
15
|
+
# bindings load it (`cdylib_path` in crates/passbolt-ffi/uniffi.toml).
|
|
16
|
+
NATIVE_LIBRARY = File.expand_path(
|
|
17
|
+
"native/#{FFI::Platform::OS}-#{FFI::Platform::ARCH}/#{FFI.map_library_name('passbolt_ffi')}",
|
|
18
|
+
__dir__
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
require_relative "passbolt/passbolt_ffi"
|
|
23
|
+
|
|
24
|
+
# The Ruby generator of UniFFI 0.29 does not support async methods: each call of the generated
|
|
25
|
+
# AsyncPassboltClient would return the handle of a Rust future, and leak it. Ruby has the
|
|
26
|
+
# blocking Passbolt::Client only.
|
|
27
|
+
PassboltFfi.send(:remove_const, :AsyncPassboltClient)
|
|
28
|
+
|
|
29
|
+
module Passbolt
|
|
30
|
+
# In every error the SDK raises: `rescue Passbolt::Error`. The classes below say what failed;
|
|
31
|
+
# each has a `reason`, and Passbolt::ApiError the HTTP `status`.
|
|
32
|
+
module Error
|
|
33
|
+
def to_s
|
|
34
|
+
respond_to?(:status) ? "#{reason} (HTTP #{status})" : reason.to_s
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
PassboltFfi::PassboltError.constants.each do |name|
|
|
39
|
+
PassboltFfi::PassboltError.const_get(name).prepend(Error)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
TransportError = PassboltFfi::PassboltError::Transport
|
|
43
|
+
AuthError = PassboltFfi::PassboltError::Auth
|
|
44
|
+
CryptoError = PassboltFfi::PassboltError::Crypto
|
|
45
|
+
ApiError = PassboltFfi::PassboltError::Api
|
|
46
|
+
NotFoundError = PassboltFfi::PassboltError::NotFound
|
|
47
|
+
ConfigError = PassboltFfi::PassboltError::Config
|
|
48
|
+
InvalidArgumentError = PassboltFfi::PassboltError::InvalidArgument
|
|
49
|
+
|
|
50
|
+
# The records, under Passbolt: Passbolt::ResourceView, Passbolt::NewResource, Passbolt::Folder…
|
|
51
|
+
RECORDS = %i[
|
|
52
|
+
Aro Comment DeleteBlockers Favorite Folder FolderQuery FolderTreeNode GpgKey Group
|
|
53
|
+
GroupDeleteDryRun GroupUser LoginOptions ManagedGroup MetadataKeysSettings
|
|
54
|
+
MetadataTypesSettings NewResource OwnedItem PassphraseGeneratorSettings
|
|
55
|
+
PasswordExpirySettings PasswordGeneratorSettings PasswordPolicies Permission Resource
|
|
56
|
+
ResourceChanges ResourceQuery ResourceType ResourceView Role Secret SecretData ServerKey Tag
|
|
57
|
+
TotpData User UserDeleteDryRun UserProfile UserQuery
|
|
58
|
+
].freeze
|
|
59
|
+
RECORDS.each { |name| const_set(name, PassboltFfi.const_get(name)) }
|
|
60
|
+
|
|
61
|
+
# The enums: Passbolt::WordCase::CAMELCASE, Passbolt::Strength::VERY_STRONG…
|
|
62
|
+
ENUMS = %i[GeneratorType Strength WordCase].freeze
|
|
63
|
+
ENUMS.each { |name| const_set(name, PassboltFfi.const_get(name)) }
|
|
64
|
+
|
|
65
|
+
# Passbolt's permission types, for share_resource and share_folder.
|
|
66
|
+
module PermissionType
|
|
67
|
+
READ = 1
|
|
68
|
+
UPDATE = 7
|
|
69
|
+
OWNER = 15
|
|
70
|
+
# Removes the access of the users and groups given.
|
|
71
|
+
REVOKE = -1
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# The server public key and its fingerprint, to pin with
|
|
75
|
+
# `Client.login(..., server_public_key:)` once the user confirmed the fingerprint.
|
|
76
|
+
def self.fetch_server_key(server_url, tls_skip_verify: false)
|
|
77
|
+
PassboltFfi.fetch_server_key(server_url, tls_skip_verify)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.get_key_fingerprint(private_key_armored)
|
|
81
|
+
PassboltFfi.get_key_fingerprint(private_key_armored)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The ciphertext, armored, for every key of public_keys_armored.
|
|
85
|
+
def self.encrypt_message(plaintext, public_keys_armored)
|
|
86
|
+
PassboltFfi.encrypt_message(plaintext, public_keys_armored)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# A password drawn as the browser extension draws it: by default 18 characters of every set
|
|
90
|
+
# but emoji. The keywords are the fields of PasswordGeneratorSettings: length: 24…
|
|
91
|
+
def self.generate_password(**settings)
|
|
92
|
+
PassboltFfi.generate_password(PasswordGeneratorSettings.new(**settings))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# A passphrase of words of the EFF list: by default 9 lowercase words joined by spaces. The
|
|
96
|
+
# keywords are the fields of PassphraseGeneratorSettings: words:, word_separator:, word_case:.
|
|
97
|
+
def self.generate_passphrase(**settings)
|
|
98
|
+
PassboltFfi.generate_passphrase(PassphraseGeneratorSettings.new(**settings))
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# A secret from the default generator of policies, those of client.get_password_policies.
|
|
102
|
+
def self.generate_secret(policies = PassboltFfi.default_password_policies)
|
|
103
|
+
PassboltFfi.generate_secret(policies)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# A PIN code of length digits, brought within 4 to 12.
|
|
107
|
+
def self.generate_pin_code(length = 4)
|
|
108
|
+
PassboltFfi.generate_pin_code(length)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# The policies of a server without settings: passwords of 18 characters by default.
|
|
112
|
+
def self.default_password_policies
|
|
113
|
+
PassboltFfi.default_password_policies
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# The entropy of secret in bits, measured as the extension does.
|
|
117
|
+
def self.secret_entropy(secret)
|
|
118
|
+
PassboltFfi.secret_entropy(secret)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# The strength the extension shows for secret: a Passbolt::Strength.
|
|
122
|
+
def self.secret_strength(secret)
|
|
123
|
+
PassboltFfi.secret_strength(secret)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# The plaintext, as a binary String.
|
|
127
|
+
def self.decrypt_message(armored_message, private_key_armored, passphrase)
|
|
128
|
+
PassboltFfi.decrypt_message(armored_message, private_key_armored, passphrase)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# A logged-in session. The calls block; the methods not redefined here are those of
|
|
132
|
+
# PassboltFfi::PassboltClient.
|
|
133
|
+
class Client < PassboltFfi::PassboltClient
|
|
134
|
+
# Log in with GPGAuth. With a block, yields the client and logs out at the end.
|
|
135
|
+
#
|
|
136
|
+
# server_public_key and metadata_key_fingerprint pin the keys saved earlier;
|
|
137
|
+
# mfa_totp_token is the base32 TOTP secret of an account with TOTP; timeout_seconds is 60
|
|
138
|
+
# by default, 0 waits forever.
|
|
139
|
+
def self.login(server_url, private_key_armored, passphrase, server_public_key: nil,
|
|
140
|
+
metadata_key_fingerprint: nil, mfa_totp_token: nil, timeout_seconds: nil,
|
|
141
|
+
tls_skip_verify: false, proxy: nil, client_certificate_pem: nil,
|
|
142
|
+
client_key_pem: nil)
|
|
143
|
+
options = LoginOptions.new(
|
|
144
|
+
tls_skip_verify: tls_skip_verify, proxy: proxy, mfa_totp_token: mfa_totp_token,
|
|
145
|
+
server_public_key: server_public_key, metadata_key_fingerprint: metadata_key_fingerprint,
|
|
146
|
+
timeout_seconds: timeout_seconds, client_certificate_pem: client_certificate_pem,
|
|
147
|
+
client_key_pem: client_key_pem
|
|
148
|
+
)
|
|
149
|
+
client = login_with_config(server_url, private_key_armored, passphrase, options)
|
|
150
|
+
return client unless block_given?
|
|
151
|
+
|
|
152
|
+
begin
|
|
153
|
+
yield client
|
|
154
|
+
ensure
|
|
155
|
+
in_flight = $ERROR_INFO
|
|
156
|
+
begin
|
|
157
|
+
client.logout
|
|
158
|
+
rescue Passbolt::Error
|
|
159
|
+
# A failed logout raises, unless it would hide the exception that left the block.
|
|
160
|
+
raise unless in_flight
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# The flags and optional arguments below are keywords; the generated methods take them as
|
|
166
|
+
# positional arguments with defaults.
|
|
167
|
+
|
|
168
|
+
def list_resource_views(search = nil, with_secrets: false)
|
|
169
|
+
super(search, with_secrets)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def list_resources(search = nil, favorites_only: false, owned_by_me: false)
|
|
173
|
+
super(search, favorites_only, owned_by_me)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def list_users(search = nil, group_id: nil, admin_only: false)
|
|
177
|
+
super(search, group_id, admin_only)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def share_resource(id, permission_type:, user_ids: [], group_ids: [])
|
|
181
|
+
super(id, permission_type, user_ids, group_ids)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def share_folder(id, permission_type:, user_ids: [], group_ids: [], with_content: false)
|
|
185
|
+
super(id, permission_type, user_ids, group_ids, with_content)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def create_folder(name, folder_parent_id: nil)
|
|
189
|
+
super(name, folder_parent_id)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def update_user(id, first_name: nil, last_name: nil, role: nil)
|
|
193
|
+
super(id, first_name, last_name, role)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def create_group(name, member_ids: [], manager_ids: [])
|
|
197
|
+
super(name, member_ids, manager_ids)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def update_group(id, name: nil, add_member_ids: [], add_manager_ids: [], remove_member_ids: [])
|
|
201
|
+
super(id, name, add_member_ids, add_manager_ids, remove_member_ids)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def create_comment(resource_id, content, parent_id: nil)
|
|
205
|
+
super(resource_id, content, parent_id)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
data/lib/passbolt_sdk.rb
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
require "ffi"
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
# The
|
|
5
|
-
|
|
6
|
-
"native/#{FFI::Platform::OS}-#{FFI::Platform::ARCH}/#{FFI.map_library_name('passbolt_ffi')}",
|
|
7
|
-
__dir__
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
require_relative "passbolt_ffi"
|
|
3
|
+
# The former entry point of the gem: `require "passbolt"` instead.
|
|
4
|
+
require_relative "passbolt"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: switch-case-passbolt-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Passbolt SA
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ffi
|
|
@@ -35,7 +35,8 @@ files:
|
|
|
35
35
|
- lib/native/linux-aarch64/libpassbolt_ffi.so
|
|
36
36
|
- lib/native/linux-x86_64/libpassbolt_ffi.so
|
|
37
37
|
- lib/native/windows-x86_64/passbolt_ffi.dll
|
|
38
|
-
- lib/
|
|
38
|
+
- lib/passbolt.rb
|
|
39
|
+
- lib/passbolt/passbolt_ffi.rb
|
|
39
40
|
- lib/passbolt_sdk.rb
|
|
40
41
|
homepage: https://github.com/scadra/passbolt-rust-sdk
|
|
41
42
|
licenses:
|