Skip to content

Commit b6ea300

Browse files
Feat: Ruby SDK
1 parent e5cab02 commit b6ea300

9 files changed

+225
-1
lines changed

languages/ruby/Gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem "rake", "~> 13.0"
6+
gem "rspec", "~> 3.0"
7+
gem "rubocop", "~> 1.21"
8+
gem 'ffi', '~> 1.9', '>= 1.9.10'

languages/ruby/Gemfile.lock

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
ast (2.4.2)
5+
diff-lcs (1.5.1)
6+
ffi (1.17.0)
7+
ffi (1.17.0-arm64-darwin)
8+
json (2.7.1)
9+
language_server-protocol (3.17.0.3)
10+
parallel (1.25.1)
11+
parser (3.3.3.0)
12+
ast (~> 2.4.1)
13+
racc
14+
racc (1.7.3)
15+
rainbow (3.1.1)
16+
rake (13.2.1)
17+
regexp_parser (2.9.2)
18+
rexml (3.2.8)
19+
rspec (3.13.0)
20+
rspec-core (~> 3.13.0)
21+
rspec-expectations (~> 3.13.0)
22+
rspec-mocks (~> 3.13.0)
23+
rspec-core (3.13.0)
24+
rspec-support (~> 3.13.0)
25+
rspec-expectations (3.13.1)
26+
diff-lcs (>= 1.2.0, < 2.0)
27+
rspec-support (~> 3.13.0)
28+
rspec-mocks (3.13.1)
29+
diff-lcs (>= 1.2.0, < 2.0)
30+
rspec-support (~> 3.13.0)
31+
rspec-support (3.13.1)
32+
rubocop (1.65.0)
33+
json (~> 2.3)
34+
language_server-protocol (>= 3.17.0)
35+
parallel (~> 1.10)
36+
parser (>= 3.3.0.2)
37+
rainbow (>= 2.2.2, < 4.0)
38+
regexp_parser (>= 2.4, < 3.0)
39+
rexml (>= 3.2.5, < 4.0)
40+
rubocop-ast (>= 1.31.1, < 2.0)
41+
ruby-progressbar (~> 1.7)
42+
unicode-display_width (>= 2.4.0, < 3.0)
43+
rubocop-ast (1.31.3)
44+
parser (>= 3.3.1.0)
45+
ruby-progressbar (1.13.0)
46+
unicode-display_width (2.5.0)
47+
48+
PLATFORMS
49+
arm64-darwin-23
50+
ruby
51+
52+
DEPENDENCIES
53+
ffi (~> 1.9, >= 1.9.10)
54+
rake (~> 13.0)
55+
rspec (~> 3.0)
56+
rubocop (~> 1.21)
57+
58+
BUNDLED WITH
59+
2.5.16

languages/ruby/Rakefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rubocop/rake_task"
5+
require 'rspec/core/rake_task'
6+
7+
RSpec::Core::RakeTask.new
8+
9+
RuboCop::RakeTask.new
10+
11+
task default: :rubocop

languages/ruby/infisical-sdk.gemspec

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'lib/version'
4+
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']
10+
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+
spec.files = Dir.chdir(__dir__) do
23+
`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+
end
26+
end
27+
28+
spec.files += Dir.glob('lib/linux-x64/**/*')
29+
spec.files += Dir.glob('lib/macos-x64/**/*')
30+
spec.files += Dir.glob('lib/windows-x64/**/*')
31+
spec.files += Dir.glob('lib/macos-arm64/**/*')
32+
spec.files += Dir.glob('lib/schemas.rb')
33+
34+
spec.bindir = 'exe'
35+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
36+
spec.require_paths = ['lib']
37+
38+
# Uncomment to register a new dependency of your gem
39+
# spec.add_dependency "example-gem", "~> 1.0"
40+
spec.add_dependency 'dry-struct', '~> 1.6'
41+
spec.add_dependency 'dry-types', '~> 1.7'
42+
spec.add_dependency 'ffi', '~> 1.15'
43+
spec.add_dependency 'json', '~> 2.6'
44+
spec.add_dependency 'rake', '~> 13.0'
45+
spec.add_dependency 'rubocop', '~> 1.21'
46+
47+
end

languages/ruby/lib/infisical-sdk.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require 'json'
4+
require 'dry-types'
5+
6+
require_relative 'schemas'
7+
require_relative 'infisical_lib'
8+
require_relative 'infisical_error'
9+
10+
module InfisicalSDK
11+
class InfisicalSettings
12+
attr_accessor :api_url, :identity_url
13+
14+
def initialize(api_url, identity_url)
15+
# if api_url.nil? || identity_url.nil?
16+
# raise ArgumentError, "api_url and identity_url cannot be nil"
17+
# end
18+
19+
@api_url = api_url
20+
@identity_url = identity_url
21+
end
22+
end
23+
24+
class InfisicalClient
25+
attr_reader :infisical
26+
27+
def initialize(infisical_settings)
28+
client_settings = ClientSettings.new()
29+
30+
@infisical = InfisicalLib
31+
@handle = @infisical.init(client_settings.to_dynamic.compact.to_json)
32+
33+
# @command_runner = CommandRunner.new(@infisical, @handle)
34+
# @project_client = ProjectsClient.new(@command_runner)
35+
# @secrets_client = SecretsClient.new(@command_runner)
36+
end
37+
38+
def free_mem
39+
@infisical.free_mem(@handle)
40+
end
41+
end
42+
end

languages/ruby/lib/infisical_error.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
module InfisicalSDK
4+
class InfisicalError < StandardError
5+
def initialize(message = 'Failed to get get response')
6+
super(message)
7+
end
8+
end
9+
end

languages/ruby/lib/infisical_lib.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require "ffi"
4+
5+
module InfisicalSDK
6+
module InfisicalLib
7+
extend FFI::Library
8+
9+
def self.mac_with_intel?
10+
`uname -m`.strip == 'x86_64'
11+
end
12+
13+
ffi_lib case RUBY_PLATFORM
14+
when /darwin/
15+
local_file = if mac_with_intel?
16+
File.expand_path('macos-x64/libinfisical_c.dylib', __dir__)
17+
else
18+
File.expand_path('macos-arm64/libinfisical_c.dylib', __dir__)
19+
end
20+
File.exist?(local_file) ? local_file : File.expand_path('../../../../target/debug/libinfisical_c.dylib', __dir__)
21+
when /linux/
22+
local_file = File.expand_path('linux-x64/libinfisical_c.so', __dir__)
23+
File.exist?(local_file) ? local_file : File.expand_path('../../../../target/debug/libinfisical_c.so', __dir__)
24+
when /mswin|mingw/
25+
local_file = File.expand_path('windows-x64/infisical_c.dll', __dir__)
26+
File.exist?(local_file) ? local_file : File.expand_path('../../../../target/debug/infisical_c.dll', __dir__)
27+
else
28+
raise "Unsupported platform: #{RUBY_PLATFORM}"
29+
end
30+
31+
attach_function :init, [:string], :pointer
32+
attach_function :run_command, %i[string pointer], :string
33+
attach_function :free_mem, [:pointer], :void
34+
end
35+
end

languages/ruby/lib/version.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
module InfisicalSDK
4+
VERSION = '0.2.0'
5+
end

support/scripts/schemas.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ async function main() {
6363
});
6464
await ensureDir("./languages/csharp/Infisical.Sdk");
6565
writeToFile("./languages/csharp/Infisical.Sdk/schemas.cs", csharp.lines);
66-
66+
67+
const ruby = await quicktype({
68+
inputData,
69+
lang: "ruby",
70+
rendererOptions: {
71+
"ruby-version": "3.0",
72+
},
73+
});
74+
writeToFile("./languages/ruby/lib/schemas.rb", ruby.lines);
6775

6876
const java = await quicktypeMultiFile({
6977
inputData,

0 commit comments

Comments
 (0)