Class: Readiness::SupportSuperFormProcessor::PagerdutyShadowModification

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb

Overview

Defines the class PagerdutyShadowModification within the module Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.42

Class Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Class Method Details

.addedObject

Creates an issue to indicate being added

Author:

  • Jason Colyer

Since:

  • 1.0.42



70
71
72
73
74
75
76
77
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 70

def self.added
  issue = Readiness::GitLab::Issues.new
  issue.title = "Add to Pagerduty Shadow rotation"
  issue.description = added_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.added_messageObject

Since:

  • 1.0.42



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 158

def self.added_message
  <<~STRING
    ## Add to Pagerduty Shadow rotation

    Greetings @#{requester.username} !

    We received a request to add you to a Pagerduty shadow rotation. This is to let you know it has been completed at this time.

    Do note you are at the top of the list, so your oncall for that would start this week.

    /label ~"AutomatedRequests::Pagerduty"

    /assign @#{requester.username}
  STRING
end

.bad_pd_userObject

Creates an issue to indicate the requesterer doesn’t have a PD user

Author:

  • Jason Colyer

Since:

  • 1.0.42



56
57
58
59
60
61
62
63
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 56

def self.bad_pd_user
  issue = Readiness::GitLab::Issues.new
  issue.title = "Invalid request regarding Pagerduty Shadow rotation"
  issue.description = bad_user_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.bad_user_messageObject

Since:

  • 1.0.42



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 138

def self.bad_user_message
  <<~STRING
    ## Invalid request regarding Pagerduty Shadow rotation

    Greetings @#{requester.username} !

    We received a request to add or remove you from a Pagerduty shadow rotation.

    We were unable to proceed as a PD user using your email, #{requester_email}, was not found

    Please double check your request to ensure the email you used matches the email in Pagerduty.

    Once that has been rectified, please submit a new request.

    /label ~"AutomatedRequests::Bad Pagerduty User"

    /assign @#{requester.username}
  STRING
end

.layer_nameObject

Sets the global layer_name

Author:

  • Jason Colyer

Since:

  • 1.0.42



134
135
136
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 134

def self.layer_name
  @layer_name ||= ENV.fetch('PD_SHADOW_LAYER')
end

.process!(gitlab_client, gitlab_admin_client, pagerduty_client) ⇒ Object

Process a Pagerduty Shadow Modification request

Author:

  • Jason Colyer

Since:

  • 1.0.42



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 18

def self.process!(gitlab_client, gitlab_admin_client, pagerduty_client)
  @gitlab_client = gitlab_client
  @gitlab_admin_client = gitlab_admin_client
  @pagerduty_client = pagerduty_client
  requester
  pd_user = Readiness::Pagerduty::Users.find_by_email(@pagerduty_client, requester_email)
  bad_pd_user if pd_user.nil?
  schedule = Readiness::Pagerduty::Schedules.find!(@pagerduty_client, schedule_id)
  layer = schedule.schedule_layers.detect { |l| l['name'] == "Layer #{layer_name}" }
  if layer['users'].detect { |u| u['user']['id'] == pd_user.id }
    type = 'remove'
    if layer['users'].count == 1
      layer['users'] = [{ user: { id: 'PRGFAO1', type: 'user_reference' }}]
    else
      layer['users'].delete_at(layer['users'].find_index { |u| u['user']['id'] == pd_user.id })
    end
  else
    type = 'add'
    if layer['users'].count == 1 && layer['users'].first['user']['id'] == 'PRGFAO1'
      layer['users'] = [{ user: { id: pd_user.id, type: 'user_reference' }}]
    else
      layer['users'].push({ user: { id: pd_user.id, type: 'user_reference' }})
    end
  end
  schedule.schedule_layers.each_with_index do |l, i|
    schedule.schedule_layers[i] = layer if l['name'] == layer['name']
    break if l['name'] == layer['name']
  end
  Readiness::Pagerduty::Schedules.update!(@pagerduty_client, schedule)
  added if type == 'add'
  removed if type == 'remove'
end

.projectObject

Sets the global variable project

Author:

  • Jason Colyer

Since:

  • 1.0.42



116
117
118
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 116

def self.project
  @project ||= Readiness::GitLab::Projects.find!(@gitlab_client, 12811526)
end

.removedObject

Creates an issue to indicate being removed

Author:

  • Jason Colyer

Since:

  • 1.0.42



84
85
86
87
88
89
90
91
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 84

def self.removed
  issue = Readiness::GitLab::Issues.new
  issue.title = "Remove from Pagerduty Shadow rotation"
  issue.description = removed_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.removed_messageObject

Since:

  • 1.0.42



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 174

def self.removed_message
  <<~STRING
    ## Remove from Pagerduty Shadow rotation

    Greetings @#{requester.username} !

    We received a request to remove you from a Pagerduty shadow rotation. This is to let you know it has been completed at this time.

    /label ~"AutomatedRequests::Pagerduty"

    /assign @#{requester.username}
  STRING
end

.requesterObject

Sets the global variable requester

Author:

  • Jason Colyer

Since:

  • 1.0.42



98
99
100
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 98

def self.requester
  @requester ||= Readiness::SupportSuperFormProcessor::Shared.gitlab_user_check(@gitlab_admin_client, requester_email)
end

.requester_emailObject

Sets the global variable requester_email

Author:

  • Jason Colyer

Since:

  • 1.0.42



107
108
109
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 107

def self.requester_email
  @requester_email ||= ENV.fetch('REQUESTER_EMAIL')
end

.schedule_idObject

Sets the global schedule_id

Author:

  • Jason Colyer

Since:

  • 1.0.42



125
126
127
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 125

def self.schedule_id
  @schedule_id ||= ENV.fetch('PD_SHADOW_SCHEDULE')
end