Skip to content

Commit 93be13e

Browse files
committed
Update ruby examples to ruby 3, rack 3, flipper-ui 1.3
1 parent b527f52 commit 93be13e

File tree

10 files changed

+156
-69
lines changed

10 files changed

+156
-69
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 3.4

examples/ui-postgres/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ gem 'flipper-sequel'
99
gem 'flipper-ui'
1010
gem 'pg'
1111
gem 'rack'
12+
gem 'rack-session'
1213
gem 'sequel'
1314
gem 'webrick'

examples/ui-postgres/Gemfile.lock

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,76 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
concurrent-ruby (1.2.2)
4+
base64 (0.3.0)
5+
bigdecimal (3.2.2)
6+
concurrent-ruby (1.3.5)
57
crass (1.0.6)
6-
erubi (1.12.0)
7-
flipper (0.26.0)
8+
erubi (1.13.1)
9+
flipper (1.3.4)
810
concurrent-ruby (< 2)
9-
flipper-sequel (0.26.0)
10-
flipper (~> 0.26.0)
11+
flipper-sequel (1.3.4)
12+
flipper (~> 1.3.4)
1113
sequel (>= 4.0.0, < 6)
12-
flipper-ui (0.26.0)
14+
flipper-ui (1.3.4)
1315
erubi (>= 1.0.0, < 2.0.0)
14-
flipper (~> 0.26.0)
15-
rack (>= 1.4, < 3)
16-
rack-protection (>= 1.5.3, <= 4.0.0)
17-
sanitize (< 7)
18-
nokogiri (1.14.2-arm64-darwin)
19-
racc (~> 1.4)
20-
pg (1.4.6)
21-
racc (1.6.2)
22-
rack (2.2.6.2)
23-
rack-protection (3.0.5)
24-
rack
25-
sanitize (6.0.1)
16+
flipper (~> 1.3.4)
17+
rack (>= 1.4, < 4)
18+
rack-protection (>= 1.5.3, < 5.0.0)
19+
rack-session (>= 1.0.2, < 3.0.0)
20+
sanitize (< 8)
21+
logger (1.7.0)
22+
nokogiri (1.18.8-aarch64-linux-gnu)
23+
racc (~> 1.4)
24+
nokogiri (1.18.8-aarch64-linux-musl)
25+
racc (~> 1.4)
26+
nokogiri (1.18.8-arm-linux-gnu)
27+
racc (~> 1.4)
28+
nokogiri (1.18.8-arm-linux-musl)
29+
racc (~> 1.4)
30+
nokogiri (1.18.8-arm64-darwin)
31+
racc (~> 1.4)
32+
nokogiri (1.18.8-x86_64-darwin)
33+
racc (~> 1.4)
34+
nokogiri (1.18.8-x86_64-linux-gnu)
35+
racc (~> 1.4)
36+
nokogiri (1.18.8-x86_64-linux-musl)
37+
racc (~> 1.4)
38+
pg (1.5.9)
39+
racc (1.8.1)
40+
rack (3.1.16)
41+
rack-protection (4.1.1)
42+
base64 (>= 0.1.0)
43+
logger (>= 1.6.0)
44+
rack (>= 3.0.0, < 4)
45+
rack-session (2.1.1)
46+
base64 (>= 0.1.0)
47+
rack (>= 3.0.0)
48+
sanitize (7.0.0)
2649
crass (~> 1.0.2)
27-
nokogiri (>= 1.12.0)
28-
sequel (5.65.0)
29-
webrick (1.8.1)
50+
nokogiri (>= 1.16.8)
51+
sequel (5.93.0)
52+
bigdecimal
53+
webrick (1.9.1)
3054

3155
PLATFORMS
32-
arm64-darwin-21
56+
aarch64-linux-gnu
57+
aarch64-linux-musl
58+
arm-linux-gnu
59+
arm-linux-musl
60+
arm64-darwin
61+
x86_64-darwin
62+
x86_64-linux-gnu
63+
x86_64-linux-musl
3364

3465
DEPENDENCIES
3566
flipper
3667
flipper-sequel
3768
flipper-ui
3869
pg
3970
rack
71+
rack-session
4072
sequel
4173
webrick
4274

4375
BUNDLED WITH
44-
2.3.15
76+
2.6.7

examples/ui-postgres/config.ru

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
# https://www.flippercloud.io/docs/ui
44

5+
require 'bundler/setup'
56
require 'sequel'
7+
require 'rack/session/cookie'
68

79
# configure Sequel before requiring flipper-sequel
810
DB = Sequel.connect ENV['DATABASE_URL']
@@ -34,8 +36,8 @@ Flipper::UI.configure do |config|
3436
end
3537

3638
run Flipper::UI.app(fstore) { |builder|
37-
secret = ENV.fetch('SESSION_SECRET') { SecureRandom.hex(20) }
38-
builder.use(Rack::Session::Cookie, secret:)
39+
secret = ENV.fetch('SESSION_SECRET') { SecureRandom.hex(64) }
40+
builder.use Rack::Session::Cookie, secret: secret
3941
builder.use Rack::Auth::Basic do |_username, password|
4042
password == 'secret'
4143
end

examples/ui-postgres/start

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
#!/usr/bin/env bash
22

3-
set -o errexit
4-
set -o nounset
5-
set -o pipefail
3+
set -euo pipefail
64
IFS=$'\n\t'
75
if [[ "${TRACE-0}" == "1" ]]; then
8-
set -o xtrace
6+
set -o xtrace
97
fi
108

9+
1110
export FLIPPER_BANNER="hyak2 ui-postgres example"
1211
export FLIPPER_COLOR="primary"
12+
export PORT="${PORT:-9292}"
13+
14+
# generate rack session cookie secret
15+
16+
SESSION_SECRET=$(head -c64 /dev/urandom | base64)
17+
export SESSION_SECRET=$SESSION_SECRET
18+
19+
# configure connection to feature store
20+
1321
export DATABASE_URL="postgres://localhost:5432/hyak_test"
1422
export HYAK_TABLE_PREFIX="scratch_"
15-
export SESSION_SECRET=$(head -c20 /dev/urandom | base64)
1623

17-
(sleep 1; open "http://localhost:9292") & # open web UI 1s after launch
24+
(
25+
sleep 2 # wait for rackup start
26+
open "http://localhost:$PORT"
27+
) &
1828

19-
bundle exec rackup config.ru -p 9292
29+
rackup config.ru -p "$PORT"

examples/ui-redis/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 3.4

examples/ui-redis/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ gem 'flipper'
88
gem 'flipper-redis'
99
gem 'flipper-ui'
1010
gem 'rack'
11+
gem 'rack-session'
1112
gem 'webrick'

examples/ui-redis/Gemfile.lock

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,75 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
concurrent-ruby (1.2.2)
5-
connection_pool (2.3.0)
4+
base64 (0.3.0)
5+
concurrent-ruby (1.3.5)
6+
connection_pool (2.5.3)
67
crass (1.0.6)
7-
erubi (1.12.0)
8-
flipper (0.26.0)
8+
erubi (1.13.1)
9+
flipper (1.3.4)
910
concurrent-ruby (< 2)
10-
flipper-redis (0.26.0)
11-
flipper (~> 0.26.0)
11+
flipper-redis (1.3.4)
12+
flipper (~> 1.3.4)
1213
redis (>= 3.0, < 6)
13-
flipper-ui (0.26.0)
14+
flipper-ui (1.3.4)
1415
erubi (>= 1.0.0, < 2.0.0)
15-
flipper (~> 0.26.0)
16-
rack (>= 1.4, < 3)
17-
rack-protection (>= 1.5.3, <= 4.0.0)
18-
sanitize (< 7)
19-
nokogiri (1.14.2-arm64-darwin)
20-
racc (~> 1.4)
21-
racc (1.6.2)
22-
rack (2.2.6.2)
23-
rack-protection (3.0.5)
24-
rack
25-
redis (5.0.6)
26-
redis-client (>= 0.9.0)
27-
redis-client (0.12.2)
16+
flipper (~> 1.3.4)
17+
rack (>= 1.4, < 4)
18+
rack-protection (>= 1.5.3, < 5.0.0)
19+
rack-session (>= 1.0.2, < 3.0.0)
20+
sanitize (< 8)
21+
logger (1.7.0)
22+
nokogiri (1.18.8-aarch64-linux-gnu)
23+
racc (~> 1.4)
24+
nokogiri (1.18.8-aarch64-linux-musl)
25+
racc (~> 1.4)
26+
nokogiri (1.18.8-arm-linux-gnu)
27+
racc (~> 1.4)
28+
nokogiri (1.18.8-arm-linux-musl)
29+
racc (~> 1.4)
30+
nokogiri (1.18.8-arm64-darwin)
31+
racc (~> 1.4)
32+
nokogiri (1.18.8-x86_64-darwin)
33+
racc (~> 1.4)
34+
nokogiri (1.18.8-x86_64-linux-gnu)
35+
racc (~> 1.4)
36+
nokogiri (1.18.8-x86_64-linux-musl)
37+
racc (~> 1.4)
38+
racc (1.8.1)
39+
rack (3.1.16)
40+
rack-protection (4.1.1)
41+
base64 (>= 0.1.0)
42+
logger (>= 1.6.0)
43+
rack (>= 3.0.0, < 4)
44+
rack-session (2.1.1)
45+
base64 (>= 0.1.0)
46+
rack (>= 3.0.0)
47+
redis (5.4.0)
48+
redis-client (>= 0.22.0)
49+
redis-client (0.24.0)
2850
connection_pool
29-
sanitize (6.0.1)
51+
sanitize (7.0.0)
3052
crass (~> 1.0.2)
31-
nokogiri (>= 1.12.0)
32-
webrick (1.8.1)
53+
nokogiri (>= 1.16.8)
54+
webrick (1.9.1)
3355

3456
PLATFORMS
35-
arm64-darwin-21
57+
aarch64-linux-gnu
58+
aarch64-linux-musl
59+
arm-linux-gnu
60+
arm-linux-musl
61+
arm64-darwin
62+
x86_64-darwin
63+
x86_64-linux-gnu
64+
x86_64-linux-musl
3665

3766
DEPENDENCIES
3867
flipper
3968
flipper-redis
4069
flipper-ui
4170
rack
71+
rack-session
4272
webrick
4373

4474
BUNDLED WITH
45-
2.3.15
75+
2.6.7

examples/ui-redis/config.ru

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
# https://www.flippercloud.io/docs/ui
44

5+
require 'bundler/setup'
56
require 'flipper-ui'
67
require 'flipper/adapters/redis'
8+
require 'rack/session/cookie'
79

810
options = {}
911

1012
options[:url] = ENV['REDIS_URL']
11-
options[:password] = ENV['REDIS_PASSWORD'] if ENV['REDIS_PASSWORD']
1213
# use below when eg. heroku gives self-signed rediss://
1314
# options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE }
1415

@@ -29,8 +30,8 @@ Flipper::UI.configure do |config|
2930
end
3031

3132
run Flipper::UI.app(fstore) { |builder|
32-
secret = ENV.fetch('SESSION_SECRET') { SecureRandom.hex(20) }
33-
builder.use(Rack::Session::Cookie, secret:)
33+
secret = ENV.fetch('SESSION_SECRET') { SecureRandom.hex(64) }
34+
builder.use Rack::Session::Cookie, secret: secret
3435
builder.use Rack::Auth::Basic do |_username, password|
3536
password == 'secret'
3637
end

examples/ui-redis/start

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
#!/usr/bin/env bash
22

3-
set -o errexit
4-
set -o nounset
5-
set -o pipefail
3+
set -euo pipefail
64
IFS=$'\n\t'
75
if [[ "${TRACE-0}" == "1" ]]; then
8-
set -o xtrace
6+
set -o xtrace
97
fi
108

119
export FLIPPER_BANNER="hyak2 ui-redis example"
1210
export FLIPPER_COLOR="primary"
13-
export REDIS_URL="redis://localhost:6379/1"
14-
export REDIS_PASSWORD="someredispassword"
15-
export SESSION_SECRET=$(head -c20 /dev/urandom | base64)
11+
export PORT="${PORT:-9292}"
1612

17-
(sleep 1; open "http://localhost:9292") & # open web UI 1s after launch
13+
# generate rack session cookie secret
1814

19-
bundle exec rackup config.ru -p 9292
15+
SESSION_SECRET=$(head -c64 /dev/urandom | base64)
16+
export SESSION_SECRET=$SESSION_SECRET
17+
18+
# configure connection to feature store
19+
20+
export REDIS_URL="redis://:someredispassword@localhost:6379/1"
21+
22+
(
23+
sleep 2 # wait for rackup start
24+
open "http://localhost:$PORT"
25+
) &
26+
27+
rackup config.ru -p "$PORT"

0 commit comments

Comments
 (0)