infisical-sdk 2.3.8 → 3.0.0

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +37 -0
  4. data/.ruby-version +1 -0
  5. data/.yardopts +5 -0
  6. data/LICENSE +201 -0
  7. data/README.md +134 -0
  8. data/Rakefile +5 -5
  9. data/infisical-sdk.gemspec +21 -38
  10. data/lib/infisical/auth.rb +50 -0
  11. data/lib/infisical/client.rb +67 -0
  12. data/lib/infisical/errors.rb +82 -0
  13. data/lib/infisical/http_client.rb +212 -0
  14. data/lib/infisical/models/machine_identity_credential.rb +34 -0
  15. data/lib/infisical/models/secret.rb +93 -0
  16. data/lib/infisical/secrets.rb +213 -0
  17. data/lib/infisical/version.rb +6 -0
  18. data/lib/infisical-sdk.rb +3 -43
  19. data/lib/infisical.rb +9 -0
  20. metadata +35 -124
  21. data/Steepfile +0 -46
  22. data/lib/clients/auth.rb +0 -100
  23. data/lib/clients/cryptography.rb +0 -90
  24. data/lib/clients/secrets.rb +0 -171
  25. data/lib/command_runner.rb +0 -16
  26. data/lib/extended_schemas/schemas.rb +0 -38
  27. data/lib/infisical_error.rb +0 -10
  28. data/lib/infisical_lib.rb +0 -44
  29. data/lib/linux-arm64/libinfisical_c.so +0 -0
  30. data/lib/linux-x64/libinfisical_c.so +0 -0
  31. data/lib/macos-arm64/libinfisical_c.dylib +0 -0
  32. data/lib/macos-x64/libinfisical_c.dylib +0 -0
  33. data/lib/schemas.rb +0 -1728
  34. data/lib/version.rb +0 -5
  35. data/lib/windows-x64/infisical_c.dll +0 -0
  36. data/sig/infisical_sdk/auth_client.rbs +0 -20
  37. data/sig/infisical_sdk/command_runner.rbs +0 -10
  38. data/sig/infisical_sdk/cryptography_client.rbs +0 -15
  39. data/sig/infisical_sdk/infisical_client.rbs +0 -30
  40. data/sig/infisical_sdk/infisical_lib.rbs +0 -7
  41. data/sig/infisical_sdk/sdk.rbs +0 -3
  42. data/sig/infisical_sdk/secrets_client.rbs +0 -56
  43. data/sig/infisical_sdk/structs.rbs +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0e691ce4b2c0e45a78924794e8ea8479c19e24227a6dec75a44536c1f2b6019
4
- data.tar.gz: b29ccd2faf5afb1594d1a21bada02ce22227386c813a7023eddb26558baa401f
3
+ metadata.gz: 2336fc2716e609a98572e6106c11e028292155bf931ed3d617698f4022296a6d
4
+ data.tar.gz: f3c6e1d79a55db3feb9c79e0db65fefef3ec2fc3881d955401958291f4a2ae02
5
5
  SHA512:
6
- metadata.gz: a14ccca5d3ee69e14deb7efb2eaed6d30e7dc7569334b05c321e83176a9d2ebb5fbf00b4e8e560c309b5a512dfd970d333851d5368662c88a59691b93fb57113
7
- data.tar.gz: aeaf409ea23e1b6cfd4649315706d119840dfe748b186ed7f5d08bf875f6e491c07a283e67d02689b287ea74b3576d4a86d914d16dae6a05f1f751d41b666233
6
+ metadata.gz: ec2e2027d1a6cd9caed723561f798faaebc644cd18ac38252556bfde95cfb42f6b26854207bd7c2173ddab19234be3ae527078e78f388b11dc8d7538e742be98
7
+ data.tar.gz: 8ef6a5c37b01d85e332536c97a234eab1d0e287a2b6e44b7a8a1e699e466f84dc4e28e8d7affe41a77b8a507aa1e47d02169eaec25ad3a67a5b172a0dd2edb58
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,37 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - "bin/**/*"
7
+ - "vendor/**/*"
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Naming/FileName:
13
+ Exclude:
14
+ # Deliberately dashed: it must match the gem name so Bundler.require
15
+ # (`gem "infisical-sdk"`) resolves without a `require:` override.
16
+ - "lib/infisical-sdk.rb"
17
+
18
+ Style/StringLiterals:
19
+ EnforcedStyle: double_quotes
20
+
21
+ Metrics/MethodLength:
22
+ Max: 25
23
+
24
+ Metrics/ClassLength:
25
+ Max: 150
26
+
27
+ Metrics/AbcSize:
28
+ Max: 25
29
+
30
+ Metrics/ParameterLists:
31
+ # Keyword args are self-documenting at the call site; don't penalize a
32
+ # wide options surface the way positional args would be.
33
+ CountKeywordArgs: false
34
+
35
+ Metrics/BlockLength:
36
+ Exclude:
37
+ - "spec/**/*"
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.6
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --markup markdown
2
+ lib/**/*.rb
3
+ -
4
+ README.md
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ <h1 align="center">Infisical Ruby SDK</h1>
2
+
3
+ <h4 align="center">
4
+ <a href="https://infisical.com/docs/sdks/languages/ruby">Documentation</a> |
5
+ <a href="https://www.infisical.com">Website</a> |
6
+ <a href="https://infisical.com/slack">Slack</a>
7
+ </h4>
8
+
9
+ ## Introduction
10
+
11
+ **[Infisical](https://infisical.com)** is the open source secret management platform that teams use to centralize their secrets like API keys, database credentials, and configurations.
12
+
13
+ This is the official native Ruby SDK — it talks directly to the Infisical REST API and has no Rust/FFI dependency. It replaces the deprecated `infisical-sdk` gem that was built on Infisical's legacy cross-language architecture, so it is **not** a drop-in replacement: the public API differs from the old gem.
14
+
15
+ ## Installation
16
+
17
+ ```ruby
18
+ gem "infisical-sdk"
19
+ ```
20
+
21
+ ## Quick start
22
+
23
+ ```ruby
24
+ require "infisical"
25
+
26
+ client = Infisical::Client.new
27
+
28
+ client.auth.universal_auth_login(
29
+ client_id: ENV.fetch("INFISICAL_CLIENT_ID"),
30
+ client_secret: ENV.fetch("INFISICAL_CLIENT_SECRET")
31
+ )
32
+
33
+ secrets = client.secrets.list(
34
+ project_id: "<your-project-id>",
35
+ environment: "dev"
36
+ )
37
+
38
+ secrets.each { |secret| puts "#{secret.secret_key}=#{secret.secret_value}" }
39
+ ```
40
+
41
+ ### Authentication
42
+
43
+ ```ruby
44
+ # Universal Auth (machine identity client id/secret). Returns the full
45
+ # credential, so you can build your own token refresh on top of it.
46
+ credential = client.auth.universal_auth_login(client_id: "...", client_secret: "...")
47
+ credential.access_token # the token this client now uses
48
+ credential.expires_in # seconds until it expires
49
+ credential.access_token_max_ttl
50
+ credential.token_type # "Bearer"
51
+
52
+ # Or use a token you already have
53
+ client.auth.access_token("existing-access-token")
54
+ ```
55
+
56
+ ### Secrets
57
+
58
+ ```ruby
59
+ client.secrets.list(project_id: "...", environment: "dev", secret_path: "/")
60
+
61
+ # Imported secrets are folded in by default; pass include_imports: false to
62
+ # opt out. Recursive mode collapses duplicate keys across folders to one
63
+ # secret per key unless skip_unique_validation: true is passed.
64
+ client.secrets.list(project_id: "...", environment: "dev", recursive: true)
65
+
66
+ # Export fetched secrets into the process environment (never overrides
67
+ # variables that already have a value):
68
+ client.secrets.list(project_id: "...", environment: "dev", attach_to_process_env: true)
69
+ ENV.fetch("DATABASE_URL")
70
+
71
+ client.secrets.get("DATABASE_URL", project_id: "...", environment: "dev")
72
+ client.secrets.create("DATABASE_URL", "postgres://...", project_id: "...", environment: "dev")
73
+ client.secrets.update("DATABASE_URL", project_id: "...", environment: "dev", secret_value: "postgres://...")
74
+ client.secrets.delete("DATABASE_URL", project_id: "...", environment: "dev")
75
+
76
+ # create and update accept skip_multiline_encoding: true to disable the
77
+ # API's encoding of multi-line values.
78
+ ```
79
+
80
+ Each returned secret exposes `secret_key`, `secret_value`, `secret_comment`,
81
+ `secret_path`, `version`, `metadata` (an array of key/value entries), and
82
+ `tags` (an array with `id`, `slug`, `name`, and `color`).
83
+
84
+ ### Error handling
85
+
86
+ Every error raised by the SDK inherits from `Infisical::Error`. API failures
87
+ raise `Infisical::APIError` (with `status`, `url`, `http_method`, and
88
+ `request_id` readers), and well-known statuses raise a dedicated subclass:
89
+
90
+ ```ruby
91
+ begin
92
+ client.secrets.get("DATABASE_URL", project_id: "...", environment: "dev")
93
+ rescue Infisical::NotFoundError # 404
94
+ # secret does not exist
95
+ rescue Infisical::AuthenticationError # 401: bad or expired credentials
96
+ # re-authenticate
97
+ rescue Infisical::APIError => e # anything else the API rejected
98
+ # e.status, e.url, e.http_method, e.request_id
99
+ end
100
+ ```
101
+
102
+ Also available: `Infisical::PermissionError` (403), `Infisical::RateLimitError`
103
+ (429, raised only after automatic retries are exhausted), and
104
+ `Infisical::ServerError` (5xx). Network-level failures (timeouts, DNS,
105
+ connection resets) raise `Infisical::RequestError` after retries.
106
+
107
+ ### Self-hosted instances
108
+
109
+ ```ruby
110
+ client = Infisical::Client.new(site_url: "https://your-infisical-instance.com")
111
+ ```
112
+
113
+ A trailing `/api` on the site URL (as used with some other Infisical SDKs) is
114
+ accepted and normalized away.
115
+
116
+ ## Documentation
117
+
118
+ You can find the documentation for the Ruby SDK on our [SDK documentation page](https://infisical.com/docs/sdks/languages/ruby).
119
+
120
+ ## Development
121
+
122
+ ```bash
123
+ bin/setup # bundle install
124
+ bundle exec rspec
125
+ bundle exec rubocop
126
+ ```
127
+
128
+ ## Security
129
+
130
+ Please do not file GitHub issues or post on our public forum for security vulnerabilities, as they are public!
131
+
132
+ Infisical takes security issues very seriously. If you have any concerns about Infisical or believe you have uncovered a vulnerability, please get in touch via the e-mail address security@infisical.com. In the message, try to provide a description of the issue and ideally a way of reproducing it. The security team will get back to you as soon as possible.
133
+
134
+ Note that this security address should be used only for undisclosed vulnerabilities. Please report any security problems to us before disclosing it publicly.
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rubocop/rake_task'
5
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
6
5
 
7
- RSpec::Core::RakeTask.new
6
+ RSpec::Core::RakeTask.new(:spec)
8
7
 
8
+ require "rubocop/rake_task"
9
9
  RuboCop::RakeTask.new
10
10
 
11
- task default: :rubocop
11
+ task default: %i[spec rubocop]
@@ -1,49 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/version'
3
+ require_relative "lib/infisical/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'infisical-sdk'
7
- spec.version = InfisicalSDK::VERSION
8
- spec.authors = ['Infisical Inc.']
9
- spec.email = ['team@infisical.com']
6
+ spec.name = "infisical-sdk"
7
+ spec.version = Infisical::VERSION
8
+ spec.authors = ["Infisical"]
9
+ spec.email = ["support@infisical.com"]
10
+
11
+ spec.summary = "Official Infisical SDK for Ruby"
12
+ spec.description = "Native Ruby SDK for fetching and managing secrets with Infisical."
13
+ spec.homepage = "https://github.com/Infisical/ruby-sdk"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"
20
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/infisical-sdk"
21
+ spec.metadata["rubygems_mfa_required"] = "true"
10
22
 
11
- spec.summary = 'Ruby SDK for interacting with the Infisical platform.'
12
- spec.description = 'The official Infisical Ruby SDK.'
13
- spec.homepage = 'https://infisical.com'
14
- spec.required_ruby_version = '>= 2.7'
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/infisical/sdk'
18
- spec.metadata['changelog_uri'] = 'https://infisical.com/docs/changelog/overview'
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
23
  spec.files = Dir.chdir(__dir__) do
23
24
  `git ls-files -z`.split("\x0").reject do |f|
24
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git Gemfile])
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
25
27
  end
26
28
  end
27
-
28
- spec.files += Dir.glob('lib/linux-x64/**/*')
29
- spec.files += Dir.glob('lib/linux-arm64/**/*')
30
- spec.files += Dir.glob('lib/macos-x64/**/*')
31
- spec.files += Dir.glob('lib/windows-x64/**/*')
32
- spec.files += Dir.glob('lib/macos-arm64/**/*')
33
- spec.files += Dir.glob('lib/schemas.rb')
34
- spec.files += Dir.glob('lib/extended_schemas/schemas.rb')
35
-
36
- spec.bindir = 'exe'
29
+ spec.bindir = "exe"
37
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
38
- spec.require_paths = ['lib']
39
-
40
- # Uncomment to register a new dependency of your gem
41
- # spec.add_dependency "example-gem", "~> 1.0"
42
- spec.add_dependency 'dry-struct', '~> 1.6'
43
- spec.add_dependency 'dry-types', '~> 1.7'
44
- spec.add_dependency 'ffi', '~> 1.15'
45
- spec.add_dependency 'json', '~> 2.6'
46
- spec.add_dependency 'rake', '~> 13.0'
47
- spec.add_dependency 'rubocop', '~> 1.21'
48
-
31
+ spec.require_paths = ["lib"]
49
32
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "models/machine_identity_credential"
4
+
5
+ module Infisical
6
+ # Authenticates the underlying HTTP client. Every other resource client
7
+ # shares that same HTTP client, so a successful login here authenticates
8
+ # the whole {Client} instance.
9
+ class Auth
10
+ UNIVERSAL_AUTH_LOGIN_PATH = "api/v1/auth/universal-auth/login"
11
+
12
+ # @api private Obtain instances via {Client#auth} instead.
13
+ def initialize(http_client)
14
+ @http_client = http_client
15
+ end
16
+
17
+ # Logs in with Universal Auth (machine identity client id/secret) and
18
+ # authenticates this client with the resulting access token. The full
19
+ # credential is returned so callers can track `expires_in` and re-login
20
+ # (or renew) before the token lapses.
21
+ #
22
+ # @param client_id [String] machine identity client id
23
+ # @param client_secret [String] machine identity client secret
24
+ # @return [Models::MachineIdentityCredential] the credential now used by
25
+ # this client
26
+ # @raise [AuthenticationError] if the credentials are rejected
27
+ def universal_auth_login(client_id:, client_secret:)
28
+ # auth: false keeps any previously stored (possibly expired) bearer
29
+ # token off the login request; the API breaks on stale tokens there.
30
+ response = @http_client.post(
31
+ UNIVERSAL_AUTH_LOGIN_PATH,
32
+ body: { clientId: client_id, clientSecret: client_secret },
33
+ auth: false
34
+ )
35
+
36
+ access_token(response["accessToken"])
37
+ Models::MachineIdentityCredential.from_api(response)
38
+ end
39
+
40
+ # Authenticates with an access token obtained out-of-band, skipping
41
+ # the login request entirely.
42
+ #
43
+ # @param token [String] a valid Infisical access token
44
+ # @return [String] the token, now used by this client
45
+ def access_token(token)
46
+ @http_client.access_token = token
47
+ token
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ require_relative "http_client"
6
+ require_relative "auth"
7
+ require_relative "secrets"
8
+
9
+ module Infisical
10
+ # Entry point for the SDK. Construct one, authenticate via {#auth}, then
11
+ # use {#secrets} to talk to Infisical.
12
+ #
13
+ # @example Fetch a secret
14
+ # client = Infisical::Client.new
15
+ # client.auth.universal_auth_login(client_id: "...", client_secret: "...")
16
+ # secret = client.secrets.get("DATABASE_URL", project_id: "...", environment: "dev")
17
+ # secret.secret_value # => "postgres://..."
18
+ class Client
19
+ DEFAULT_SITE_URL = "https://app.infisical.com"
20
+ ALLOWED_SCHEMES = %w[http https].freeze
21
+
22
+ # @param site_url [String] base URL of the Infisical instance; defaults to
23
+ # Infisical Cloud, so only self-hosted deployments need to set it. A
24
+ # trailing "/api" is tolerated and stripped.
25
+ # @param timeout [Numeric] open/read timeout in seconds for each request
26
+ # @raise [ArgumentError] if site_url is not an http(s) URL
27
+ def initialize(site_url: DEFAULT_SITE_URL, timeout: HTTPClient::DEFAULT_TIMEOUT)
28
+ validate_site_url!(site_url)
29
+ @http_client = HTTPClient.new(base_url: normalize_site_url(site_url), timeout: timeout)
30
+ end
31
+
32
+ # Authentication operations. Logging in through this authenticates the
33
+ # whole client, since all resource clients share one HTTP client.
34
+ #
35
+ # @return [Auth]
36
+ def auth
37
+ @auth ||= Auth.new(@http_client)
38
+ end
39
+
40
+ # Secret CRUD operations.
41
+ #
42
+ # @return [Secrets]
43
+ def secrets
44
+ @secrets ||= Secrets.new(@http_client)
45
+ end
46
+
47
+ private
48
+
49
+ # Users coming from other Infisical SDKs are used to passing the site
50
+ # URL with an "/api" suffix; the SDK adds that segment itself, so strip
51
+ # it (and any trailing slashes) rather than requesting ".../api/api/...".
52
+ def normalize_site_url(site_url)
53
+ url = site_url.dup
54
+ url.chomp!("/") while url.end_with?("/")
55
+ url.delete_suffix("/api")
56
+ end
57
+
58
+ def validate_site_url!(site_url)
59
+ uri = URI.parse(site_url)
60
+ return if ALLOWED_SCHEMES.include?(uri.scheme) && uri.host
61
+
62
+ raise ArgumentError, "site_url must be an http(s) URL, got: #{site_url.inspect}"
63
+ rescue URI::InvalidURIError
64
+ raise ArgumentError, "site_url is not a valid URL: #{site_url.inspect}"
65
+ end
66
+ end
67
+ end