Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3c26b1e3
Commit
3c26b1e3
authored
Jul 13, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PagerDuty token generator to settings
parent
d4182274
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
app/models/incident_management/project_incident_management_setting.rb
...ncident_management/project_incident_management_setting.rb
+19
-0
spec/models/incident_management/project_incident_management_setting_spec.rb
...nt_management/project_incident_management_setting_spec.rb
+38
-0
No files found.
app/models/incident_management/project_incident_management_setting.rb
View file @
3c26b1e3
...
...
@@ -8,6 +8,15 @@ module IncidentManagement
validate
:issue_template_exists
,
if: :create_issue?
before_validation
:ensure_pagerduty_token
attr_encrypted
:pagerduty_token
,
mode: :per_attribute_iv
,
key:
Settings
.
attr_encrypted_db_key_base_truncated
,
algorithm:
'aes-256-gcm'
,
encode:
false
,
# No need to encode for binary column https://github.com/attr-encrypted/attr_encrypted#the-encode-encode_iv-encode_salt-and-default_encoding-options
encode_iv:
false
def
available_issue_templates
Gitlab
::
Template
::
IssueTemplate
.
all
(
project
)
end
...
...
@@ -30,5 +39,15 @@ module IncidentManagement
Gitlab
::
Template
::
IssueTemplate
.
find
(
issue_template_key
,
project
)
rescue
Gitlab
::
Template
::
Finders
::
RepoTemplateFinder
::
FileNotFoundError
end
def
ensure_pagerduty_token
return
unless
pagerduty_active
self
.
pagerduty_token
||=
generate_pagerduty_token
end
def
generate_pagerduty_token
SecureRandom
.
hex
end
end
end
spec/models/incident_management/project_incident_management_setting_spec.rb
View file @
3c26b1e3
...
...
@@ -108,4 +108,42 @@ RSpec.describe IncidentManagement::ProjectIncidentManagementSetting do
it_behaves_like
'no content'
end
end
describe
'#pagerduty_token'
do
let
(
:active
)
{
true
}
subject
do
create
(
:project_incident_management_setting
,
project:
project
,
pagerduty_active:
active
,
pagerduty_token:
token
)
end
context
'when token already set'
do
let
(
:token
)
{
SecureRandom
.
hex
}
it
'reads the token'
do
expect
(
subject
.
pagerduty_token
).
to
eq
(
token
)
expect
(
subject
.
encrypted_pagerduty_token
).
not_to
be_nil
expect
(
subject
.
encrypted_pagerduty_token_iv
).
not_to
be_nil
end
end
context
'when not set'
do
let
(
:token
)
{
nil
}
context
'when PagerDuty webhook is active'
do
it
'generates a token before validation'
do
expect
(
subject
).
to
be_valid
expect
(
subject
.
pagerduty_token
).
to
match
(
/\A\h{32}\z/
)
end
end
context
'when PagerDuty webhook is not active'
do
let
(
:active
)
{
false
}
it
'does not generate a token before validation'
do
expect
(
subject
).
to
be_valid
expect
(
subject
.
pagerduty_token
).
to
be_nil
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment