pager_judy 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2a39f6c4ca0c4e98eab6314bbe7dd97573fad1ad3334618e25f3c55365818b23
4
+ data.tar.gz: fa1176795618c99b7956142e7df8d9f6103a124cbd2269c0c0743e9dbe1c7f73
5
+ SHA512:
6
+ metadata.gz: 28d39a55ab1bb2a825be3de9bea427d9abdfaaf80c9de892d37c8edc7c98d819afb78614d9c0d8a68174e28b2c0b565202d72132d4c8373522f1efe86370c2d7
7
+ data.tar.gz: 3ed6b757e43ad7e85f0cae3d6d860b15aea45a4f167797b48bf183c50bb40bce5887dfac2584e3ab6da06770888623da5ac6fe2bf6b1c7876cf2e69e53c91203
@@ -0,0 +1,17 @@
1
+ steps:
2
+
3
+ - name: Test
4
+ command: ./auto/test
5
+
6
+ - name: Build
7
+ command: ./auto/build
8
+
9
+ - block: OK release
10
+ branches: master
11
+
12
+ - name: Release
13
+ command: ./auto/release
14
+ branches: master
15
+ artifact_paths: target/docker-image.txt
16
+ agents:
17
+ queue: cpdev:build
@@ -0,0 +1,3 @@
1
+ #!/bin/bash -eu
2
+
3
+ buildkite-agent pipeline upload < $(dirname $0)/pipeline.yml
data/.dockerignore ADDED
@@ -0,0 +1,3 @@
1
+ .git
2
+ target
3
+ tmp
data/.gitignore ADDED
@@ -0,0 +1,53 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ smoke-tests/tmp/
13
+ .DS_STORE
14
+
15
+ # Used by dotenv library to load environment variables.
16
+ # .env
17
+
18
+ ## Specific to RubyMotion:
19
+ .dat*
20
+ .repl_history
21
+ build/
22
+ *.bridgesupport
23
+ build-iPhoneOS/
24
+ build-iPhoneSimulator/
25
+
26
+ ## Specific to RubyMotion (use of CocoaPods):
27
+ #
28
+ # We recommend against adding the Pods directory to your .gitignore. However
29
+ # you should judge for yourself, the pros and cons are mentioned at:
30
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
31
+ #
32
+ # vendor/Pods/
33
+
34
+ ## Documentation cache and generated files:
35
+ /.yardoc/
36
+ /_yardoc/
37
+ /doc/
38
+ /rdoc/
39
+
40
+ ## Environment normalization:
41
+ /.bundle/
42
+ /vendor/bundle
43
+ /lib/bundler/man/
44
+
45
+ # for a library or gem, you might want to ignore these files since the code is
46
+ # intended to run in multiple environments; otherwise, check them in:
47
+ # Gemfile.lock
48
+ # .ruby-version
49
+ # .ruby-gemset
50
+
51
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
52
+ .rvmrc
53
+ test*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,49 @@
1
+ Eval:
2
+ Exclude:
3
+ - "Rakefile"
4
+
5
+ Layout/EmptyLinesAroundBlockBody:
6
+ Enabled: false
7
+
8
+ Layout/EmptyLinesAroundClassBody:
9
+ EnforcedStyle: empty_lines
10
+
11
+ Layout/EmptyLinesAroundModuleBody:
12
+ Enabled: false
13
+
14
+ Metrics/AbcSize:
15
+ Enabled: false
16
+
17
+ Metrics/LineLength:
18
+ Max: 120
19
+
20
+ Metrics/MethodLength:
21
+ Max: 30
22
+
23
+ Style/ClassAndModuleChildren:
24
+ EnforcedStyle: nested
25
+ Exclude:
26
+ - "spec/**/*"
27
+
28
+ Style/ConditionalAssignment:
29
+ Enabled: false
30
+
31
+ Style/Documentation:
32
+ Enabled: false
33
+
34
+ Style/Encoding:
35
+ EnforcedStyle: when_needed
36
+ Enabled: true
37
+
38
+ Style/FileName:
39
+ Exclude:
40
+ - "bin/*"
41
+
42
+ Style/HashSyntax:
43
+ EnforcedStyle: ruby19
44
+
45
+ Style/StringLiterals:
46
+ EnforcedStyle: double_quotes
47
+
48
+ Style/WordArray:
49
+ Enabled: false
data/CHANGES.md ADDED
@@ -0,0 +1,29 @@
1
+ ## PENDING
2
+
3
+ * Add "--include" option for services.
4
+ * Add "vendors".
5
+
6
+ ## 0.1.5 (2017-08-19)
7
+
8
+ * Add service timeouts functionality.
9
+
10
+ ## 0.1.4 (2017-08-18)
11
+
12
+ * Add "--dry-run" option to "configure".
13
+
14
+ ## 0.1.3 (2017-08-17)
15
+
16
+ * Add "users" subcommand.
17
+ * Add "--check" option to "configure".
18
+
19
+ ## 0.1.2 (2017-08-17)
20
+
21
+ * Fix "configure" subcommand.
22
+
23
+ ## 0.1.1 (2017-08-17)
24
+
25
+ * Add "configure" subcommand.
26
+
27
+ ## 0.1.0 (2017-08-17)
28
+
29
+ * Initial release.
data/Dockerfile ADDED
@@ -0,0 +1,22 @@
1
+ FROM ruby:2.5-alpine
2
+
3
+ RUN { echo 'install: --no-document'; echo 'update: --no-document'; } >> /etc/gemrc
4
+
5
+ MAINTAINER Mike Williams <mdub@dogbiscuit.org>
6
+
7
+ RUN apk --no-cache add \
8
+ ca-certificates
9
+
10
+ WORKDIR /app
11
+
12
+ COPY Gemfile /app/Gemfile
13
+ COPY Gemfile.lock /app/Gemfile.lock
14
+ RUN bundle install --without development test
15
+
16
+ COPY bin /app/bin
17
+ COPY lib /app/lib
18
+ COPY README.md /app/
19
+
20
+ WORKDIR /cwd
21
+
22
+ ENTRYPOINT ["/app/bin/pagerjudy"]
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "clamp", "~> 1.3.0"
4
+ gem "config_hound", "~> 1.4", ">= 1.4.1"
5
+ gem "config_mapper", "~> 1.6"
6
+ gem "console_logger", "~> 1.0"
7
+ gem "httpi"
8
+ gem "jmespath"
9
+ gem "multi_json"
10
+
11
+ group "development" do
12
+ gem "pry"
13
+ gem "rack-test"
14
+ gem "rake", "~> 12.0"
15
+ gem "rspec", "~> 3.5"
16
+ gem "rspec-pact-matchers", "~> 0.1"
17
+ gem "rubocop", "~> 0.49"
18
+ gem "sham_rack"
19
+ gem "sinatra"
20
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.4.0)
5
+ awesome_print (1.8.0)
6
+ clamp (1.3.0)
7
+ coderay (1.1.2)
8
+ config_hound (1.4.3)
9
+ dig_rb
10
+ config_mapper (1.7.0)
11
+ console_logger (1.0.0)
12
+ diff-lcs (1.3)
13
+ dig_rb (1.0.1)
14
+ find_a_port (1.0.1)
15
+ httpi (2.4.4)
16
+ rack
17
+ socksify
18
+ jaro_winkler (1.5.1)
19
+ jmespath (1.4.0)
20
+ json (2.1.0)
21
+ method_source (0.9.2)
22
+ multi_json (1.13.1)
23
+ mustermann (1.0.3)
24
+ pact-support (1.8.1)
25
+ awesome_print (~> 1.1)
26
+ find_a_port (~> 1.0.1)
27
+ json
28
+ randexp (~> 0.1.7)
29
+ rspec (>= 2.14)
30
+ term-ansicolor (~> 1.0)
31
+ thor
32
+ parallel (1.12.1)
33
+ parser (2.5.3.0)
34
+ ast (~> 2.4.0)
35
+ powerpack (0.1.2)
36
+ pry (0.12.2)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.9.0)
39
+ rack (2.0.6)
40
+ rack-protection (2.0.5)
41
+ rack
42
+ rack-test (1.1.0)
43
+ rack (>= 1.0, < 3)
44
+ rainbow (3.0.0)
45
+ rake (12.3.2)
46
+ randexp (0.1.7)
47
+ rspec (3.8.0)
48
+ rspec-core (~> 3.8.0)
49
+ rspec-expectations (~> 3.8.0)
50
+ rspec-mocks (~> 3.8.0)
51
+ rspec-core (3.8.0)
52
+ rspec-support (~> 3.8.0)
53
+ rspec-expectations (3.8.2)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.8.0)
56
+ rspec-mocks (3.8.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.8.0)
59
+ rspec-pact-matchers (0.1.0)
60
+ pact-support (>= 1.1.2, < 2.0)
61
+ rspec (~> 3.0)
62
+ term-ansicolor (~> 1.0)
63
+ rspec-support (3.8.0)
64
+ rubocop (0.61.1)
65
+ jaro_winkler (~> 1.5.1)
66
+ parallel (~> 1.10)
67
+ parser (>= 2.5, != 2.5.1.1)
68
+ powerpack (~> 0.1)
69
+ rainbow (>= 2.2.2, < 4.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (~> 1.4.0)
72
+ ruby-progressbar (1.10.0)
73
+ sham_rack (1.4.1)
74
+ rack
75
+ sinatra (2.0.5)
76
+ mustermann (~> 1.0)
77
+ rack (~> 2.0)
78
+ rack-protection (= 2.0.5)
79
+ tilt (~> 2.0)
80
+ socksify (1.7.1)
81
+ term-ansicolor (1.7.0)
82
+ tins (~> 1.0)
83
+ thor (0.20.3)
84
+ tilt (2.0.9)
85
+ tins (1.20.2)
86
+ unicode-display_width (1.4.1)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ clamp (~> 1.3.0)
93
+ config_hound (~> 1.4, >= 1.4.1)
94
+ config_mapper (~> 1.6)
95
+ console_logger (~> 1.0)
96
+ httpi
97
+ jmespath
98
+ multi_json
99
+ pry
100
+ rack-test
101
+ rake (~> 12.0)
102
+ rspec (~> 3.5)
103
+ rspec-pact-matchers (~> 0.1)
104
+ rubocop (~> 0.49)
105
+ sham_rack
106
+ sinatra
107
+
108
+ BUNDLED WITH
109
+ 1.16.2
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # PagerJudy
2
+
3
+ PagerJudy is:
4
+ - a Ruby client for the [PagerDuty API](https://v2.developer.pagerduty.com/v2/page/api-reference)
5
+ - with a handy built-in CLI tool
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler"
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task "default" => "spec"
7
+
8
+ require "rspec/core/rake_task"
9
+ RSpec::Core::RakeTask.new(:spec)
data/auto/build ADDED
@@ -0,0 +1,7 @@
1
+ #! /bin/bash -eu
2
+ #
3
+ # Build Docker image
4
+
5
+ cd $(dirname $0)/..
6
+
7
+ docker build .
@@ -0,0 +1,11 @@
1
+ #! /bin/bash -e
2
+ #
3
+ # Dev environment in a Docker container for local and CI use
4
+
5
+ cd $(dirname $0)/..
6
+
7
+ trap "docker-compose down --volumes" 0
8
+
9
+ docker volume create --name ruby2.4-bundle-cache > /dev/null
10
+ docker-compose run --rm dev sh -c 'bundle check > /dev/null || bundle install'
11
+ docker-compose run --rm dev bundle exec "${@-bash}"
data/auto/test ADDED
@@ -0,0 +1,3 @@
1
+ #! /bin/bash -e
2
+
3
+ $(dirname $0)/dev-environment rake spec
@@ -0,0 +1,16 @@
1
+ version: "2"
2
+
3
+ services:
4
+ dev:
5
+ image: ruby:2.4
6
+ volumes:
7
+ - .:/work
8
+ - ruby2.4-bundle-cache:/usr/local/bundle
9
+ working_dir: /work
10
+ command: ["bash"]
11
+ environment:
12
+ PAGER_DUTY_API_KEY:
13
+
14
+ volumes:
15
+ ruby2.4-bundle-cache:
16
+ external: true
data/exe/pagerjudy ADDED
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path("../../lib", __FILE__)
4
+
5
+ require "pager_judy/cli"
6
+
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ PagerJudy::CLI::MainCommand.run
@@ -0,0 +1,61 @@
1
+ require "pager_judy/api/collection"
2
+ require "pager_judy/api/resource"
3
+ require "uri"
4
+
5
+ module PagerJudy
6
+ module API
7
+
8
+ # Communicate with the PagerDuty API.
9
+ #
10
+ class Client
11
+
12
+ def initialize(api_key, base_uri: "https://api.pagerduty.com/", logger: nil, dry_run: false)
13
+ @root = Resource.new(api_key: api_key, uri: URI(base_uri), logger: logger, dry_run: dry_run)
14
+ end
15
+
16
+ attr_reader :root
17
+
18
+ def collection(type)
19
+ Collection.new(root.subresource(type), type)
20
+ end
21
+
22
+ def escalation_policies
23
+ collection("escalation_policies")
24
+ end
25
+
26
+ def extensions
27
+ collection("extensions")
28
+ end
29
+
30
+ def incidents
31
+ collection("incidents")
32
+ end
33
+
34
+ def notifications
35
+ collection("notifications")
36
+ end
37
+
38
+ def schedules
39
+ collection("schedules")
40
+ end
41
+
42
+ def services
43
+ collection("services")
44
+ end
45
+
46
+ def teams
47
+ collection("teams")
48
+ end
49
+
50
+ def users
51
+ collection("users")
52
+ end
53
+
54
+ def vendors
55
+ collection("vendors")
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,95 @@
1
+ require "pager_judy/api/item"
2
+
3
+ module PagerJudy
4
+ module API
5
+
6
+ # Represents a collection of things, e.g. services, users, ...
7
+ #
8
+ class Collection
9
+
10
+ def initialize(resource, type, criteria = {})
11
+ @resource = resource
12
+ @type = type
13
+ @criteria = criteria
14
+ end
15
+
16
+ attr_reader :resource
17
+ attr_reader :type
18
+ attr_reader :criteria
19
+
20
+ def item_type
21
+ type.sub(/ies$/, "y").chomp("s")
22
+ end
23
+
24
+ include Enumerable
25
+
26
+ def with(more_criteria)
27
+ more_criteria = Hash[more_criteria.select { |_, v| v }]
28
+ Collection.new(resource, type, criteria.merge(more_criteria))
29
+ end
30
+
31
+ def each
32
+ offset = 0
33
+ loop do
34
+ data = resource.get(criteria.merge(offset: offset, limit: 100))
35
+ data.fetch(type).each do |item|
36
+ yield item
37
+ end
38
+ break unless data["more"]
39
+ offset = data.fetch("offset") + data.fetch("limit")
40
+ end
41
+ self
42
+ end
43
+
44
+ def [](id)
45
+ Item.new(resource.subresource(id), item_type, id)
46
+ end
47
+
48
+ def create(data)
49
+ name = data.fetch("name")
50
+ if dry_run?
51
+ result = data.merge("id" => "{#{name}}")
52
+ else
53
+ result = resource.post(item_type => data).fetch(item_type)
54
+ end
55
+ id = result.fetch("id")
56
+ logger.info { "created #{item_type} #{name.inspect} [#{id}]" }
57
+ result
58
+ end
59
+
60
+ def create_or_update(id, data)
61
+ if id.nil?
62
+ create(data)
63
+ else
64
+ self[id].update(data)
65
+ end
66
+ end
67
+
68
+ def id_for_name(name)
69
+ ids_by_name[name]
70
+ end
71
+
72
+ def create_or_update_by_name(name, data)
73
+ create_or_update(id_for_name(name), data.merge("name" => name))
74
+ end
75
+
76
+ private
77
+
78
+ def ids_by_name
79
+ @ids_by_name ||= each_with_object({}) do |item, result|
80
+ result[item.fetch("name")] = item.fetch("id")
81
+ end
82
+ end
83
+
84
+ def logger
85
+ resource.logger
86
+ end
87
+
88
+ def dry_run?
89
+ resource.dry_run?
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,20 @@
1
+ module PagerJudy
2
+ module API
3
+
4
+ # An error from the PagerDuty REST API.
5
+ #
6
+ class HttpError < StandardError
7
+
8
+ def initialize(request, response)
9
+ @request = request
10
+ @response = response
11
+ super(response.headers["Status"])
12
+ end
13
+
14
+ attr_reader :request
15
+ attr_reader :response
16
+
17
+ end
18
+
19
+ end
20
+ end