Module: PactBroker::Api::PactBrokerUrls

Constant Summary

Constants included from Pacts::Metadata

Pacts::Metadata::MAPPINGS

Instance Method Summary collapse

Methods included from Logging

included, #log_error

Methods included from Pacts::Metadata

#build_metadata_for_latest_pact, #build_metadata_for_pact_for_verification, #build_metadata_for_webhook_triggered_by_pact_publication, #parse_hash, #parse_metadata, #parse_object

Instance Method Details

#append_query_if_present(url, query) ⇒ Object



318
319
320
321
322
323
324
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 318

def append_query_if_present(url, query)
  if query && query.size > 0
    url + "?#{query}"
  else
    url
  end
end

#badge_url_for_latest_pact(pact, base_url = '') ⇒ Object



271
272
273
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 271

def badge_url_for_latest_pact pact, base_url = ''
  "#{latest_pact_url(base_url, pact)}/badge.svg"
end

#consumer_webhooks_url(consumer, base_url = '') ⇒ Object



247
248
249
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 247

def consumer_webhooks_url consumer, base_url = ''
  "#{base_url}/webhooks/consumer/#{url_encode(consumer.name)}"
end

#dashboard_url_for_integration(consumer_name, provider_name, base_url = "") ⇒ Object



127
128
129
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 127

def dashboard_url_for_integration consumer_name, provider_name, base_url = ""
  "#{base_url}/dashboard/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
end

#decode_pact_metadata(metadata) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 79

def ()
  if  &&  != ''
    begin
      Rack::Utils.parse_nested_query(Base64.strict_decode64())
    rescue StandardError => e
      logger.warn("Exception parsing webhook metadata: #{}", e)
      {}
    end
  else
    {}
  end
end

#encode_metadata(metadata) ⇒ Object



75
76
77
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 75

def ()
  Base64.strict_encode64(Rack::Utils.build_nested_query())
end

#group_url(pacticipant_name, base_url = '') ⇒ Object



306
307
308
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 306

def group_url(pacticipant_name, base_url = '')
  "#{base_url}/groups/#{url_encode(pacticipant_name)}"
end

#hal_browser_url(target_url, base_url = '') ⇒ Object



310
311
312
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 310

def hal_browser_url target_url, base_url = ''
  "#{base_url}/hal-browser/browser.html#" + target_url
end

#integration_url(consumer_name, provider_name, base_url = "") ⇒ Object



123
124
125
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 123

def integration_url consumer_name, provider_name, base_url = ""
  "#{base_url}/integrations/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
end

#label_url(label, base_url) ⇒ Object



223
224
225
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 223

def label_url label, base_url
  "#{labels_url(label.pacticipant, base_url)}/#{url_encode(label.name)}"
end

#labels_url(pacticipant, base_url) ⇒ Object



227
228
229
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 227

def labels_url pacticipant, base_url
  "#{pacticipant_url(base_url, pacticipant)}/labels"
end

#latest_pact_url(base_url, pact) ⇒ Object



99
100
101
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 99

def latest_pact_url base_url, pact
  "#{pactigration_base_url(base_url, pact)}/latest"
end

#latest_pacts_url(base_url) ⇒ Object



111
112
113
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 111

def latest_pacts_url base_url
  "#{base_url}/pacts/latest"
end

#latest_tagged_pact_url(pact, tag_name, base_url) ⇒ Object



107
108
109
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 107

def latest_tagged_pact_url pact, tag_name, base_url
  "#{latest_pact_url(base_url, pact)}/#{url_encode(tag_name)}"
end

#latest_untagged_pact_url(pact, base_url) ⇒ Object



103
104
105
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 103

def latest_untagged_pact_url pact, base_url
  "#{pactigration_base_url(base_url, pact)}/latest-untagged"
end

#latest_verification_for_pact_url(pact, base_url, permalink = true) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 178

def latest_verification_for_pact_url pact, base_url, permalink = true
  if permalink
    verification_url_from_params(
      {
        provider_name: provider_name(pact),
        consumer_name: consumer_name(pact),
        pact_version_sha: pact.pact_version_sha,
        verification_number: 'latest'
      },
      base_url
    )
  else
    pact_url(base_url, pact) + "/verification-results/latest"
  end
end

#latest_verifications_for_consumer_version_url(version, base_url) ⇒ Object



174
175
176
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 174

def latest_verifications_for_consumer_version_url version, base_url
  "#{base_url}/verification-results/consumer/#{url_encode(version.pacticipant.name)}/version/#{url_encode(version.number)}/latest"
end

#latest_version_url(base_url, pacticipant) ⇒ Object



33
34
35
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 33

def latest_version_url base_url, pacticipant
  "#{pacticipant_url(base_url, pacticipant)}/versions/latest"
end

#matrix_badge_url_for_selectors(consumer_selector, provider_selector, base_url = '') ⇒ Object



279
280
281
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 279

def matrix_badge_url_for_selectors consumer_selector, provider_selector, base_url = ''
  "#{base_url}/matrix/provider/#{url_encode(provider_selector.pacticipant_name)}/latest/#{url_encode(provider_selector.tag)}/consumer/#{url_encode(consumer_selector.pacticipant_name)}/latest/#{url_encode(consumer_selector.tag)}/badge.svg"
end

#matrix_for_pact_url(pact, base_url = '') ⇒ Object



291
292
293
294
295
296
297
298
299
300
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 291

def matrix_for_pact_url(pact, base_url = '')
  query = {
    q: [
      { pacticipant: pact.consumer_name, version: pact.consumer_version_number },
      { pacticipant: pact.provider_name, latest: true }
    ],
    latestby: 'cvpv'
  }
  "#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}"
end

#matrix_for_pacticipant_version_url(version, base_url = '') ⇒ Object



283
284
285
286
287
288
289
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 283

def matrix_for_pacticipant_version_url(version, base_url = '')
  query = {
    q: [{ pacticipant: version.pacticipant.name, version: version.number }],
    latestby: 'cvpv'
  }
  "#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}"
end

#matrix_url(consumer_name, provider_name, base_url = '') ⇒ Object



275
276
277
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 275

def matrix_url consumer_name, provider_name, base_url = ''
  "/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
end

#matrix_url_from_params(params, base_url = '') ⇒ Object



302
303
304
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 302

def matrix_url_from_params params, base_url = ''
  matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url)
end

#new_verification_url(pact, number, base_url) ⇒ Object



147
148
149
150
151
152
153
154
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 147

def new_verification_url pact, number, base_url
  [ base_url, 'pacts',
    'provider', url_encode(pact.provider_name),
    'consumer', url_encode(pact.consumer_name),
    'pact-version', pact.pact_version_sha,
    'verification-results', number
  ].join('/')
end

#pact_triggered_webhooks_url(pact, base_url = '') ⇒ Object



263
264
265
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 263

def pact_triggered_webhooks_url pact, base_url = ''
  "#{pact_url(base_url, pact)}/triggered-webhooks"
end

#pact_url(base_url, pact) ⇒ Object



55
56
57
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 55

def pact_url base_url, pact
  "#{pactigration_base_url(base_url, pact)}/version/#{url_encode(pact.consumer_version_number)}"
end

#pact_url_from_params(base_url, params) ⇒ Object



92
93
94
95
96
97
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 92

def pact_url_from_params base_url, params
  [ base_url, 'pacts',
    'provider', url_encode(params[:provider_name]),
    'consumer', url_encode(params[:consumer_name]),
    'version', url_encode(params[:consumer_version_number]) ].join('/')
end

#pact_version_url(pact, base_url = '') ⇒ Object



59
60
61
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 59

def pact_version_url pact, base_url = ''
  "#{pactigration_base_url(base_url, pact)}/pact-version/#{pact.pact_version_sha}"
end

#pact_version_url_with_metadata(pact, metadata, base_url = '') ⇒ Object



63
64
65
66
67
68
69
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 63

def  pact, , base_url = ''
  if  && .any?
    "#{pact_version_url(pact, base_url)}/metadata/#{()}"
  else
    pact_version_url(pact, base_url)
  end
end

#pact_version_url_with_webhook_metadata(pact, base_url = '') ⇒ Object



71
72
73
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 71

def  pact, base_url = ''
  (pact, (pact), base_url)
end

#pact_versions_url(consumer_name, provider_name, base_url = "") ⇒ Object



115
116
117
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 115

def pact_versions_url consumer_name, provider_name, base_url = ""
  "#{base_url}/pacts/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}/versions"
end

#pacticipant_url(base_url, pacticipant) ⇒ Object



21
22
23
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 21

def pacticipant_url base_url, pacticipant
  "#{pacticipants_url(base_url)}/#{url_encode(pacticipant.name)}"
end

#pacticipant_url_from_params(params, base_url = '') ⇒ Object



25
26
27
28
29
30
31
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 25

def pacticipant_url_from_params params, base_url = ''
  [
    base_url,
    'pacticipants',
    url_encode(params.fetch(:pacticipant_name))
  ].join("/")
end

#pacticipants_url(base_url) ⇒ Object



17
18
19
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 17

def pacticipants_url base_url
  "#{base_url}/pacticipants"
end

#previous_distinct_diff_url(pact, base_url) ⇒ Object



131
132
133
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 131

def previous_distinct_diff_url pact, base_url
  pact_url(base_url, pact) + "/diff/previous-distinct"
end

#previous_distinct_pact_version_url(pact, base_url) ⇒ Object



139
140
141
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 139

def previous_distinct_pact_version_url pact, base_url
  pact_url(base_url, pact) + "/previous-distinct"
end

#provider_webhooks_url(provider, base_url = '') ⇒ Object



251
252
253
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 251

def provider_webhooks_url provider, base_url = ''
  "#{base_url}/webhooks/provider/#{url_encode(provider.name)}"
end

#tag_url(base_url, tag) ⇒ Object



203
204
205
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 203

def tag_url base_url, tag
  "#{tags_url(base_url, tag.version)}/#{url_encode(tag.name)}"
end

#tagged_pact_versions_url(consumer_name, provider_name, tag, base_url = "") ⇒ Object



119
120
121
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 119

def tagged_pact_versions_url consumer_name, provider_name, tag, base_url = ""
  "#{base_url}/pacts/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}/tag/#{url_encode(tag)}"
end

#tags_url(base_url, version) ⇒ Object



143
144
145
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 143

def tags_url base_url, version
  "#{version_url(base_url, version)}/tags"
end

#templated_can_i_deploy_badge_url(pacticipant_name, base_url = "") ⇒ Object



219
220
221
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 219

def templated_can_i_deploy_badge_url pacticipant_name, base_url = ""
  templated_can_i_deploy_url(pacticipant_name, base_url) + "/badge"
end

#templated_can_i_deploy_url(pacticipant_name, base_url = "") ⇒ Object



215
216
217
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 215

def templated_can_i_deploy_url pacticipant_name, base_url = ""
  pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/latest-version/{tag}/can-i-deploy/to/{environmentTag}"
end

#templated_diff_url(pact, base_url = '') ⇒ Object



135
136
137
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 135

def templated_diff_url pact, base_url = ''
  pact_version_url(pact, base_url) + "/diff/pact-version/{pactVersion}"
end

#templated_label_url_for_pacticipant(pacticipant_name, base_url = "") ⇒ Object



211
212
213
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 211

def templated_label_url_for_pacticipant pacticipant_name, base_url = ""
  pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/labels/{label}"
end

#templated_tag_url_for_pacticipant(pacticipant_name, base_url = "") ⇒ Object



207
208
209
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 207

def templated_tag_url_for_pacticipant pacticipant_name, base_url = ""
  pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}/tags/{tag}"
end

#triggered_webhook_logs_url(triggered_webhook, base_url) ⇒ Object



267
268
269
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 267

def triggered_webhook_logs_url triggered_webhook, base_url
  "#{base_url}/webhooks/#{triggered_webhook.webhook_uuid}/trigger/#{triggered_webhook.trigger_uuid}/logs"
end

#url_encode(param) ⇒ Object



314
315
316
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 314

def url_encode param
  ERB::Util.url_encode param
end

#verification_publication_url(pact, base_url, metadata = "") ⇒ Object



198
199
200
201
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 198

def verification_publication_url pact, base_url,  = ""
   =  ? "/metadata/#{}" : ""
  "#{pactigration_base_url(base_url, pact)}/pact-version/#{pact.pact_version_sha}#{}/verification-results"
end

#verification_triggered_webhooks_url(verification, base_url = '') ⇒ Object



194
195
196
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 194

def verification_triggered_webhooks_url verification, base_url = ''
  "#{verification_url(verification, base_url)}/triggered-webhooks"
end

#verification_url(verification, base_url = '') ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 156

def verification_url verification, base_url = ''
  [ base_url, 'pacts',
    'provider', url_encode(verification.provider_name),
    'consumer', url_encode(verification.consumer_name),
    'pact-version', verification.pact_version_sha,
    'verification-results', verification.number
  ].join('/')
end

#verification_url_from_params(params, base_url = '') ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 165

def verification_url_from_params params, base_url = ''
  [ base_url, 'pacts',
    'provider', url_encode(params.fetch(:provider_name)),
    'consumer', url_encode(params.fetch(:consumer_name)),
    'pact-version', params.fetch(:pact_version_sha),
    'verification-results', params.fetch(:verification_number)
  ].join('/')
end

#version_url(base_url, version) ⇒ Object



41
42
43
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 41

def version_url base_url, version
  "#{pacticipant_url(base_url, version.pacticipant)}/versions/#{url_encode(version.number)}"
end

#version_url_from_params(params, base_url = '') ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 45

def version_url_from_params params, base_url = ''
  [
    base_url,
    'pacticipants',
    url_encode(params.fetch(:pacticipant_name)),
    'versions',
    url_encode(params.fetch(:version_number)),
  ].join("/")
end

#versions_url(base_url, pacticipant) ⇒ Object



37
38
39
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 37

def versions_url base_url, pacticipant
  "#{pacticipant_url(base_url, pacticipant)}/versions"
end

#webhook_execution_url(webhook, base_url) ⇒ Object



239
240
241
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 239

def webhook_execution_url webhook, base_url
  "#{base_url}/webhooks/#{webhook.uuid}/execute"
end

#webhook_url(uuid, base_url) ⇒ Object



235
236
237
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 235

def webhook_url uuid, base_url
  "#{base_url}/webhooks/#{uuid}"
end

#webhooks_for_consumer_and_provider_url(consumer, provider, base_url = '') ⇒ Object



243
244
245
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 243

def webhooks_for_consumer_and_provider_url consumer, provider, base_url = ''
  "#{base_url}/webhooks/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}"
end

#webhooks_for_pact_url(consumer, provider, base_url = '') ⇒ Object



255
256
257
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 255

def webhooks_for_pact_url consumer, provider, base_url = ''
  "#{base_url}/pacts/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}/webhooks"
end

#webhooks_status_url(consumer, provider, base_url = '') ⇒ Object



259
260
261
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 259

def webhooks_status_url consumer, provider, base_url = ''
  "#{webhooks_for_pact_url(consumer, provider, base_url)}/status"
end

#webhooks_url(base_url) ⇒ Object



231
232
233
# File 'lib/pact_broker/api/pact_broker_urls.rb', line 231

def webhooks_url base_url
  "#{base_url}/webhooks"
end