Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
ea5d36e7
未验证
提交
ea5d36e7
编辑于
1 year ago
作者:
Balasankar "Balu" C
浏览文件
操作
下载
补丁
差异文件
Support specifying TLS settings in resque.yml
Changelog: added Signed-off-by:
Balasankar "Balu" C
<
balasankar@gitlab.com
>
上级
e460fd24
No related branches found
No related tags found
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
config/resque.yml.example
+5
-0
5 个添加, 0 个删除
config/resque.yml.example
lib/gitlab/redis/wrapper.rb
+37
-6
37 个添加, 6 个删除
lib/gitlab/redis/wrapper.rb
spec/support/shared_examples/redis/redis_shared_examples.rb
+84
-0
84 个添加, 0 个删除
spec/support/shared_examples/redis/redis_shared_examples.rb
有
126 个添加
和
6 个删除
config/resque.yml.example
+
5
−
0
浏览文件 @
ea5d36e7
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
#
#
development:
development:
url: redis://localhost:6379
url: redis://localhost:6379
# ssl_params:
# ca_path: "/path/to/dir/with/certs"
# ca_file: "/path/to/ca.crt"
# cert_file: "/path/to/client.crt"
# key_file: "/path/to/client.key"
# sentinels:
# sentinels:
# -
# -
# host: localhost
# host: localhost
...
...
此差异已折叠。
点击以展开。
lib/gitlab/redis/wrapper.rb
+
37
−
6
浏览文件 @
ea5d36e7
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
module
Gitlab
module
Gitlab
module
Redis
module
Redis
class
Wrapper
class
Wrapper
InvalidPathError
=
Class
.
new
(
StandardError
)
class
<<
self
class
<<
self
delegate
:params
,
:url
,
:store
,
to: :new
delegate
:params
,
:url
,
:store
,
to: :new
...
@@ -122,12 +124,14 @@ def redis_store_options
...
@@ -122,12 +124,14 @@ def redis_store_options
config
=
raw_config_hash
config
=
raw_config_hash
config
[
:instrumentation_class
]
||=
self
.
class
.
instrumentation_class
config
[
:instrumentation_class
]
||=
self
.
class
.
instrumentation_class
if
config
[
:cluster
].
present?
result
=
if
config
[
:cluster
].
present?
config
[
:db
]
=
0
# Redis Cluster only supports db 0
config
[
:db
]
=
0
# Redis Cluster only supports db 0
config
config
else
else
parse_redis_url
(
config
)
parse_redis_url
(
config
)
end
end
parse_client_tls_options
(
result
)
end
end
def
parse_redis_url
(
config
)
def
parse_redis_url
(
config
)
...
@@ -153,6 +157,33 @@ def parse_redis_url(config)
...
@@ -153,6 +157,33 @@ def parse_redis_url(config)
end
end
end
end
def
parse_client_tls_options
(
config
)
return
config
unless
config
&
.
key?
(
:ssl_params
)
# Only cert_file and key_file are handled in this method. ca_file and
# ca_path are Strings, so they can be passed as-is. cert_store is not
# currently supported.
cert_file
=
config
[
:ssl_params
].
delete
(
:cert_file
)
key_file
=
config
[
:ssl_params
].
delete
(
:key_file
)
unless
::
File
.
exist?
(
cert_file
)
raise
InvalidPathError
,
"Certificate file
#{
cert_file
}
specified in in `resque.yml` does not exist."
end
config
[
:ssl_params
][
:cert
]
=
OpenSSL
::
X509
::
Certificate
.
new
(
File
.
read
(
cert_file
))
unless
::
File
.
exist?
(
key_file
)
raise
InvalidPathError
,
"Key file
#{
key_file
}
specified in in `resque.yml` does not exist."
end
config
[
:ssl_params
][
:key
]
=
OpenSSL
::
PKey
.
read
(
File
.
read
(
key_file
))
config
end
def
raw_config_hash
def
raw_config_hash
config_data
=
fetch_config
config_data
=
fetch_config
...
...
此差异已折叠。
点击以展开。
spec/support/shared_examples/redis/redis_shared_examples.rb
+
84
−
0
浏览文件 @
ea5d36e7
...
@@ -365,6 +365,90 @@
...
@@ -365,6 +365,90 @@
end
end
end
end
describe
"#parse_client_tls_options"
do
let
(
:dummy_certificate
)
{
OpenSSL
::
X509
::
Certificate
.
new
}
let
(
:dummy_key
)
{
OpenSSL
::
PKey
::
RSA
.
new
}
let
(
:resque_yaml_config_without_tls
)
{
{
url:
'redis://localhost:6379'
}
}
let
(
:resque_yaml_config_with_tls
)
do
{
url:
'rediss://localhost:6380'
,
ssl_params:
{
cert_file:
'/tmp/client.crt'
,
key_file:
'/tmp/client.key'
}
}
end
let
(
:parsed_config_with_tls
)
do
{
url:
'rediss://localhost:6380'
,
ssl_params:
{
cert:
dummy_certificate
,
key:
dummy_key
}
}
end
before
do
allow
(
::
File
).
to
receive
(
:exist?
).
and_call_original
allow
(
::
File
).
to
receive
(
:read
).
and_call_original
end
context
'when configuration does not have TLS related options'
do
it
'returns the coniguration as-is'
do
expect
(
subject
.
send
(
:parse_client_tls_options
,
resque_yaml_config_without_tls
)).
to
eq
(
resque_yaml_config_without_tls
)
end
end
context
'when specified certificate file does not exist'
do
before
do
allow
(
::
File
).
to
receive
(
:exist?
).
with
(
"/tmp/client.crt"
).
and_return
(
false
)
allow
(
::
File
).
to
receive
(
:exist?
).
with
(
"/tmp/client.key"
).
and_return
(
true
)
end
it
'raises error about missing certificate file'
do
expect
do
subject
.
send
(
:parse_client_tls_options
,
resque_yaml_config_with_tls
)
end
.
to
raise_error
(
Gitlab
::
Redis
::
Wrapper
::
InvalidPathError
,
"Certificate file /tmp/client.crt specified in in `resque.yml` does not exist."
)
end
end
context
'when specified key file does not exist'
do
before
do
allow
(
::
File
).
to
receive
(
:exist?
).
with
(
"/tmp/client.crt"
).
and_return
(
true
)
allow
(
::
File
).
to
receive
(
:read
).
with
(
"/tmp/client.crt"
).
and_return
(
"DUMMY_CERTIFICATE"
)
allow
(
OpenSSL
::
X509
::
Certificate
).
to
receive
(
:new
).
with
(
"DUMMY_CERTIFICATE"
).
and_return
(
dummy_certificate
)
allow
(
::
File
).
to
receive
(
:exist?
).
with
(
"/tmp/client.key"
).
and_return
(
false
)
end
it
'raises error about missing key file'
do
expect
do
subject
.
send
(
:parse_client_tls_options
,
resque_yaml_config_with_tls
)
end
.
to
raise_error
(
Gitlab
::
Redis
::
Wrapper
::
InvalidPathError
,
"Key file /tmp/client.key specified in in `resque.yml` does not exist."
)
end
end
context
'when configuration valid TLS related options'
do
before
do
allow
(
::
File
).
to
receive
(
:exist?
).
with
(
"/tmp/client.crt"
).
and_return
(
true
)
allow
(
::
File
).
to
receive
(
:exist?
).
with
(
"/tmp/client.key"
).
and_return
(
true
)
allow
(
::
File
).
to
receive
(
:read
).
with
(
"/tmp/client.crt"
).
and_return
(
"DUMMY_CERTIFICATE"
)
allow
(
::
File
).
to
receive
(
:read
).
with
(
"/tmp/client.key"
).
and_return
(
"DUMMY_KEY"
)
allow
(
OpenSSL
::
X509
::
Certificate
).
to
receive
(
:new
).
with
(
"DUMMY_CERTIFICATE"
).
and_return
(
dummy_certificate
)
allow
(
OpenSSL
::
PKey
).
to
receive
(
:read
).
with
(
"DUMMY_KEY"
).
and_return
(
dummy_key
)
end
it
"converts cert_file and key_file appropriately"
do
expect
(
subject
.
send
(
:parse_client_tls_options
,
resque_yaml_config_with_tls
)).
to
eq
(
parsed_config_with_tls
)
end
end
end
describe
'#fetch_config'
do
describe
'#fetch_config'
do
before
do
before
do
FileUtils
.
mkdir_p
(
File
.
join
(
rails_root
,
'config'
))
FileUtils
.
mkdir_p
(
File
.
join
(
rails_root
,
'config'
))
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录