require 'erb' module NotificationServices # The triggers you install are actually pretty fixed, and just have the # URL to the server added to them. See the definitions toward the end of the # file (they can get long) class TriggersHelper # The P4 Web API Client handle attr_accessor :client # The URL to the notification services, including any prefix attr_accessor :url # The Perforce login to use for trigger authentication to post to the # notification services endpoint. attr_accessor :user # The Perforce ticket to use for trigger authentication to post to the # notification services endpoint. attr_accessor :ticket # Specify the HTTP client. Currently only :curl is supported. attr_accessor :client_app def initialize(client: nil, url:nil, user:nil, ticket:nil, client_app: :curl) @client = client @url = url @user = user @ticket = ticket @client_app = client_app end # Should fetch the triggers, then return them def execute(triggers) triggers = client.triggers triggers.triggers = remove_triggers(triggers.triggers) triggers.triggers = add_triggers(triggers.triggers) client.update_triggers(triggers) triggers end # Remove any triggers that start with our known prefixes and return the array def remove_triggers(triggers) triggers.reject { |t| t.start_with?('p4_notifications_') } end # Add our notification services triggers def add_triggers(triggers) if client_app == :curl triggers << ERB.new(CHANGE_COMMIT_CURL_ERB).result(self.get_binding) else fail "Can't generate triggers for app #{client_app}" end end def change_commit_url "#{url}/triggers/change-commit" end def get_binding binding() end CHANGE_COMMIT_CURL_ERB =<<-END.gsub(/\s+/, ' ') p4_notifications_change_commit change-commit ... "curl -X POST -H 'application/json' --basic -U '<%= user %>:<%= ticket %>' -d '{ %quote%variables%quote%: { %quote%argc%quote%: %quote%%argc%%quote%, %quote%args%quote%: %quote%%args%%quote%, %quote%argsQuoted%quote%: %quote%%argsQuoted%%quote%, %quote%change%quote%: %quote%%change%%quote%, %quote%changeroot%quote%: %quote%%changeroot%%quote%, %quote%client%quote%: %quote%%client%%quote%, %quote%clientcwd%quote%: %quote%%clientcwd%%quote%, %quote%clienthost%quote%: %quote%%clienthost%%quote%, %quote%clientip%quote%: %quote%%clientip%%quote%, %quote%clientprog%quote%: %quote%%clientprog%%quote%, %quote%clientversion%quote%: %quote%%clientversion%%quote%, %quote%command%quote%: %quote%%command%%quote%, %quote%groups%quote%: %quote%%groups%%quote%, %quote%intermediateService%quote%: %quote%%intermediateService%%quote%, %quote%maxErrorSeverity%quote%: %quote%%maxErrorSeverity%%quote%, %quote%maxErrorText%quote%: %quote%%maxErrorText%%quote%, %quote%maxLockTime%quote%: %quote%%maxLockTime%%quote%, %quote%maxResults%quote%: %quote%%maxLockTime%%quote%, %quote%maxScanRows%quote%, %quote%%maxLockTime%%quote%, %quote%oldchangelist%quote%: %quote%%oldchangelist%%quote%, %quote%peerhost%quote%: %quote%%peerhost%%quote%, %quote%peerip%quote%: %quote%%peerip%%quote%, %quote%serverhost%quote%: %quote%%serverhost%%quote%, %quote%serverpid%quote%: %quote%%serverpid%%quote%, %quote%servername%quote%: %quote%%servername%%quote%, %quote%serverport%quote%: %quote%%serverport%%quote%, %quote%serverroot%quote%: %quote%%serverroot%%quote%, %quote%serverservices%quote%: %quote%%serverservices%%quote%, %quote%serverVersion%quote%: %quote%%serverVersion%%quote%, %quote%submitserverid%quote%: %quote%%submitserverid%%quote%, %quote%terminated%quote%: %quote%%terminated%%quote%, %quote%termType%quote%: %quote%%termType%%quote%, %quote%user%quote%: %quote%%user%%quote% } }' <%= change_commit_url %>" END end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 13675 | tjuricek |
Add notification_services initialization Removing the 'online setup' mode in lieu of doing things during the salt process. Mostly this removes the trigger setup from the main web application. |
||
#1 | 13467 | tjuricek | Add a basic notification_services endpoint that can setup a trigger entry and accept basic POST requests. |