flipt_client 0.0.4 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34a376996b99b4e4dea4cd4f75adad3e912c9ee00371859598558acfb2af9113
4
- data.tar.gz: da0c0f08d2089edd9d89f7e3183cd8d1d4c2789909cc2afaa3d7b6733bc43931
3
+ metadata.gz: 1cbfce772261a0e968cbcc2b0135b851e86dda4107abe8cac583a2c2cb23692c
4
+ data.tar.gz: ae3cad47961fabefe5abd90310a3f91a3e57d35dbd976e98b0a82939bfd988b3
5
5
  SHA512:
6
- metadata.gz: db3ff379854f6b67d11061f73d6fde96bc6b181f0714cf280929f0b00ff1b303c0b742b6518c27d24dbb880d3c8b2d0b9e61515685dd09be1910d7cc24c26eb7
7
- data.tar.gz: 66a92e9c6ba318fb16a00cc6161ad3f7f111635185f39d2f24d98d1c17637a2b7701ae8999a8634241efee2f996ab4c829a1284ac1fb6bee9d31563cc84eda56
6
+ metadata.gz: edb56a32998775cc00ff7cbc54302978e40a1f0eae8f16b15684a872d3f713b73652e924391556d6a2683a2483059a8421cb98603bc724723dc9d095813deb61
7
+ data.tar.gz: 7d684bead44f7d8eae6091f46dfcfe1bcdb8d391cdaad9796f398ab96b902e71d7a04e87678d66c5fc7df215796620a069be770d764c05e1d2f6234ca911a16f
data/README.md CHANGED
@@ -10,6 +10,17 @@ The `flipt-client-ruby` directory contains the Ruby source code for the Flipt [c
10
10
  gem install flipt_client
11
11
  ```
12
12
 
13
+ ## Using System Libffi
14
+
15
+ If you are experiencing segfaults when using this gem, you may need to configure `ffi` to use the system libffi instead of the bundled one.
16
+
17
+ You can do this before installing the gem by running the following command:
18
+
19
+ ```bash
20
+ gem install ffi -- --enable-system-libffi # to install the gem manually
21
+ bundle config build.ffi --enable-system-libffi # for bundle install
22
+ ```
23
+
13
24
  ## Usage
14
25
 
15
26
  In your Ruby code you can import this client and use it as so:
@@ -22,7 +33,9 @@ require 'flipt_client'
22
33
  # {
23
34
  # "url": "http://localhost:8080",
24
35
  # "update_interval": 120,
25
- # "auth_token": "secret"
36
+ # "authentication": {
37
+ # "client_token": "secret"
38
+ # }
26
39
  # }
27
40
  #
28
41
  # You can replace the url with where your upstream Flipt instance points to, the update interval for how long you are willing
@@ -1 +1 @@
1
- /Users/runner/work/flipt-client-sdks/flipt-client-sdks/target/aarch64-apple-darwin/release/libfliptengine.rlib: /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/build.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/error/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/common.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/flipt.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/source.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/parser/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/store/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/src/lib.rs
1
+ /Users/runner/work/flipt-client-sdks/flipt-client-sdks/target/aarch64-apple-darwin/release/libfliptengine.rlib: /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/build.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/error/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/common.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/flipt.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/source.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/parser/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/store/mod.rs
@@ -1 +1 @@
1
- /target/aarch64-unknown-linux-gnu/release/libfliptengine.rlib: /project/flipt-engine/build.rs /project/flipt-engine/lib/evaluation/src/error/mod.rs /project/flipt-engine/lib/evaluation/src/lib.rs /project/flipt-engine/lib/evaluation/src/models/common.rs /project/flipt-engine/lib/evaluation/src/models/flipt.rs /project/flipt-engine/lib/evaluation/src/models/mod.rs /project/flipt-engine/lib/evaluation/src/models/source.rs /project/flipt-engine/lib/evaluation/src/parser/mod.rs /project/flipt-engine/lib/evaluation/src/store/mod.rs /project/flipt-engine/src/lib.rs
1
+ /target/aarch64-unknown-linux-gnu/release/libfliptengine.rlib: /project/flipt-engine-ffi/build.rs /project/flipt-engine-ffi/src/lib.rs /project/flipt-evaluation/src/error/mod.rs /project/flipt-evaluation/src/lib.rs /project/flipt-evaluation/src/models/common.rs /project/flipt-evaluation/src/models/flipt.rs /project/flipt-evaluation/src/models/mod.rs /project/flipt-evaluation/src/models/source.rs /project/flipt-evaluation/src/parser/mod.rs /project/flipt-evaluation/src/store/mod.rs
Binary file
@@ -1 +1 @@
1
- /home/runner/work/flipt-client-sdks/flipt-client-sdks/target/x86_64-unknown-linux-gnu/release/libfliptengine.rlib: /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/build.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/error/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/lib.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/common.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/flipt.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/models/source.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/parser/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/lib/evaluation/src/store/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine/src/lib.rs
1
+ /home/runner/work/flipt-client-sdks/flipt-client-sdks/target/x86_64-unknown-linux-gnu/release/libfliptengine.rlib: /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/build.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/lib.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/error/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/lib.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/common.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/flipt.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/source.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/parser/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/store/mod.rs
Binary file
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flipt
4
+ class AuthenticationStrategy
5
+ def strategy
6
+ raise NotImplementedError
7
+ end
8
+ end
9
+
10
+ class NoAuthentication < AuthenticationStrategy
11
+ def strategy
12
+ nil
13
+ end
14
+ end
15
+
16
+ class ClientTokenAuthentication < AuthenticationStrategy
17
+ def initialize(token)
18
+ @token = token
19
+ end
20
+
21
+ def strategy
22
+ {
23
+ client_token: @token
24
+ }
25
+ end
26
+ end
27
+
28
+ class JWTAuthentication < AuthenticationStrategy
29
+ def initialize(token)
30
+ @token = token
31
+ end
32
+
33
+ def strategy
34
+ {
35
+ jwt_token: @token
36
+ }
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flipt
4
- VERSION = '0.0.4'
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/flipt_client.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'flipt_client/version'
4
+ require 'flipt_client/models'
4
5
  require 'ffi'
5
6
  require 'json'
6
7
 
@@ -36,8 +37,23 @@ module Flipt
36
37
  # const char *evaluate_boolean(void *engine_ptr, const char *evaluation_request);
37
38
  attach_function :evaluate_boolean, %i[pointer string], :string
38
39
 
40
+ # Create a new Flipt client
41
+ #
42
+ # @param namespace [String] namespace
43
+ # @param opts [Hash] options
44
+ # @option opts [String] :url Flipt server url
45
+ # @option opts [AuthenticationStrategy] :authentication strategy to authenticate with Flipt
46
+ # @option opts [Integer] :update_interval interval in seconds to update the cache
47
+ # @option opts [String] :reference reference to use for namespace data
39
48
  def initialize(namespace = 'default', opts = {})
40
49
  @namespace = namespace
50
+
51
+ # set default no auth if not provided
52
+ authentication = opts.fetch(:authentication, Flipt::NoAuthentication.new)
53
+ raise ArgumentError, "invalid authentication strategy" unless authentication && authentication.is_a?(Flipt::AuthenticationStrategy)
54
+
55
+ opts[:authentication] = authentication.strategy
56
+
41
57
  namespace_list = [namespace]
42
58
  ns = FFI::MemoryPointer.new(:pointer, namespace_list.size)
43
59
  namespace_list.each_with_index do |namespace, i|
@@ -52,6 +68,12 @@ module Flipt
52
68
  proc { destroy_engine(engine) }
53
69
  end
54
70
 
71
+ # Evaluate a variant flag for a given request
72
+ #
73
+ # @param evaluation_request [Hash] evaluation request
74
+ # @option evaluation_request [String] :entity_id entity id
75
+ # @option evaluation_request [String] :flag_key flag key
76
+ # @option evaluation_request [String] :namespace_key override namespace key
55
77
  def evaluate_variant(evaluation_request = {})
56
78
  evaluation_request[:namespace_key] = @namespace
57
79
  validate_evaluation_request(evaluation_request)
@@ -59,6 +81,12 @@ module Flipt
59
81
  JSON.parse(resp)
60
82
  end
61
83
 
84
+ # Evaluate a boolean flag for a given request
85
+ #
86
+ # @param evaluation_request [Hash] evaluation request
87
+ # @option evaluation_request [String] :entity_id entity id
88
+ # @option evaluation_request [String] :flag_key flag key
89
+ # @option evaluation_request [String] :namespace_key override namespace key
62
90
  def evaluate_boolean(evaluation_request = {})
63
91
  evaluation_request[:namespace_key] = @namespace
64
92
  validate_evaluation_request(evaluation_request)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipt_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flipt Devs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-16 00:00:00.000000000 Z
11
+ date: 2024-01-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Flipt Client Evaluation SDK
14
14
  email:
@@ -30,6 +30,7 @@ files:
30
30
  - lib/ext/linux_x86_64/libfliptengine.rlib
31
31
  - lib/ext/linux_x86_64/libfliptengine.so
32
32
  - lib/flipt_client.rb
33
+ - lib/flipt_client/models.rb
33
34
  - lib/flipt_client/version.rb
34
35
  homepage: https://www.flipt.io
35
36
  licenses: