Commit 0bd8669f authored by Z.J. van de Weg's avatar Z.J. van de Weg

Merge branch 'zj-mattermost-slash-config' of gitlab.com:gitlab-org/gitlab-ce...

Merge branch 'zj-mattermost-slash-config' of gitlab.com:gitlab-org/gitlab-ce into zj-mattermost-slash-config
parents 2393d30d dec1e90e
module Mattermost
class Error < StandardError; end
end
...@@ -26,6 +26,8 @@ module Mattermost ...@@ -26,6 +26,8 @@ module Mattermost
include Doorkeeper::Helpers::Controller include Doorkeeper::Helpers::Controller
include HTTParty include HTTParty
LEASE_TIMEOUT = 60
base_uri Settings.mattermost.host base_uri Settings.mattermost.host
attr_accessor :current_resource_owner, :token attr_accessor :current_resource_owner, :token
...@@ -35,6 +37,7 @@ module Mattermost ...@@ -35,6 +37,7 @@ module Mattermost
end end
def with_session def with_session
with_lease do
raise NoSessionError unless create raise NoSessionError unless create
begin begin
...@@ -45,6 +48,7 @@ module Mattermost ...@@ -45,6 +48,7 @@ module Mattermost
destroy destroy
end end
end end
end
# Next methods are needed for Doorkeeper # Next methods are needed for Doorkeeper
def pre_auth def pre_auth
...@@ -130,5 +134,25 @@ module Mattermost ...@@ -130,5 +134,25 @@ module Mattermost
response.headers['token'] response.headers['token']
end end
end end
def with_lease
lease_uuid = lease_try_obtain
raise NoSessionError unless lease_uuid
begin
yield
ensure
Gitlab::ExclusiveLease.cancel(lease_key, lease_uuid)
end
end
def lease_key
"mattermost:session"
end
def lease_try_obtain
lease = ::Gitlab::ExclusiveLease.new(lease_key, timeout: LEASE_TIMEOUT)
lease.try_obtain
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment