veeam 0.1.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: 6163d719d045dea4a72b05a6dae5b14d6f8c65c09bd7e83ab6cf8143c862092a
4
+ data.tar.gz: 45176225fcaa997c0fefc7718340b91f0c3f2d8fea6599d150d8bfe12421c451
5
+ SHA512:
6
+ metadata.gz: d2ea1e16122625bfe8611a76d2262976ffa19e387341de4345949c0fea9712ab77bec345958a135fa7b75f84d780dbed96c1d536a7e6e74c2888eeea9838cb4b
7
+ data.tar.gz: ee02233ed031debcb7bc6e1e50aef7ddb154e21f333dec7442ed10df9731d46211fe83fc2df7da2fa555d0d79b8003b1f8a576af7efb6030a94e7fdc1b15a17f
data/.env.template ADDED
@@ -0,0 +1,2 @@
1
+ VEEAM_API_HOST=<your veeam api host>
2
+ VEEAM_API_KEY=<api-key>
data/.gitignore ADDED
@@ -0,0 +1,44 @@
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
+ /data/
13
+ *.log
14
+ *.txt
15
+ *.json
16
+ *.yml
17
+
18
+ # Used by dotenv library to load environment variables.
19
+ .env
20
+
21
+
22
+ ## Documentation cache and generated files:
23
+ /.yardoc/
24
+ /_yardoc/
25
+ /doc/
26
+ /rdoc/
27
+
28
+ ## Environment normalization:
29
+ /.bundle/
30
+ /vendor/bundle
31
+ /lib/bundler/man/
32
+
33
+ # for a library or gem, you might want to ignore these files since the code is
34
+ # intended to run in multiple environments; otherwise, check them in:
35
+ # Gemfile.lock
36
+ # .ruby-version
37
+ # .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
41
+
42
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
43
+ # .rubocop-https?--*
44
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-07
4
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in cloudally.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rubocop', '~> 1.7'
10
+ gem 'wrapi'
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Veeam backup API
2
+
3
+ This is a wrapper for the Veeam Service Provider Console rest API. You can see the API endpoints here https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html
4
+
5
+ Currently only the GET requests to get a list of tenants and backup job reports are implemented.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'veeam'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install veeam
22
+
23
+ ## Usage
24
+
25
+ Before you start making the requests to API provide the client id and client secret and email/password using the configuration wrapping.
26
+
27
+ ```
28
+ require 'veeam'
29
+
30
+ # use do block
31
+ Veeam.configure do |config|
32
+ config.endpoint = ENV["VEEAM_API_HOST"]
33
+ config.access_token = ENV["VEEAM_API_KEY"]
34
+ config.page_size = 100
35
+ end
36
+
37
+ # or configure with options hash
38
+ @client = Veeam.client({ logger: Logger.new(CLIENT_LOGGER) })
39
+
40
+ client = Veeam.client
41
+ client.login
42
+
43
+ companies = client.companies
44
+ companies.each do |t|
45
+ puts "#{t.name}"
46
+ end
47
+ ```
48
+
49
+ ## Resources
50
+ ### Authentication
51
+ ```
52
+ # setup configuration
53
+ #
54
+ client.login
55
+ ```
56
+ |Resource|API endpoint|Description|
57
+ |:--|:--|:--|
58
+ |.login|uses /api/v3/about to chek if creentials are correct|
59
+
60
+
61
+ ### About
62
+ Endpoint returns general information about the currently installed version of Veeam Service Provider Console.
63
+ ```
64
+ puts client.about.serverVersion
65
+ ```
66
+
67
+ |Resource|API endpoint|
68
+ |:--|:--|
69
+ |.about|/api/v3/about|
70
+
71
+ ### Companies
72
+ Endpoint for companies related requests
73
+ ```
74
+ companies = client.companies
75
+ ```
76
+
77
+ |Resource|API endpoint|
78
+ |:--|:--|
79
+ |.companies|/api/v3/organizations/companies|
80
+ |.company|/api/v3/organizations/companies/{id}|
81
+ |TODO other endpoints|...|
82
+
83
+ ### Infrastructure
84
+ Get list of backup servers
85
+ ```
86
+ server = client.backup_server(id)
87
+
88
+ ```
89
+
90
+ |Resource|API endpoint|
91
+ |:--|:--|
92
+ |.backup_servers|/api/v3/backupServers|
93
+ |.backup_server|/api/v3/backupServers/{id}|
94
+ |TODO other endpoints|...|
95
+
96
+ ### Alarms
97
+ This resource collection represents Veeam Service Provider Console alarms.
98
+ ```
99
+ client.active_alarms.each do |alarm|
100
+ if alarms.alarmTemplateUid.eql? "templateUid>"
101
+ :
102
+ end
103
+ end
104
+
105
+ ```
106
+
107
+ |Resource|API endpoint|
108
+ |:--|:--|
109
+ |.all_triggered_alarms .active_alarms|/api/v3/alarms/active|
110
+ |.triggered_alarm .active_alarm|/api/v3/alarms/active/#{alarm_id}|
111
+ |.triggered_alarm_history .alarm_history|/api/v3/alarms/active#{alarm_id}/history|
112
+ |.all_alarm_templates .alarm_templates|/api/v3/alarms/templates|
113
+ |.alarm_template|/api/v3/alarms/templates/#{template_id}|
114
+ |.alarm_status_changes .alarm_template_events|/api/v3/alarms/templates/#{template_id}/events|
115
+
116
+ ## Contributing
117
+
118
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/veeam.
119
+
120
+ ## License
121
+
122
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ require 'rubocop/rake_task'
13
+ RuboCop::RakeTask.new
14
+ task default: %i[test rubocop]
data/lib/veeam/api.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "wrapi"
2
+ require File.expand_path('authentication', __dir__)
3
+
4
+ module Veeam
5
+ # @private
6
+ class API
7
+ # @private
8
+ attr_accessor *WrAPI::Configuration::VALID_OPTIONS_KEYS
9
+
10
+ # Creates a new API and copies settings from singleton
11
+ def initialize(options = {})
12
+ options = Veeam.options.merge(options)
13
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", options[key])
15
+ end
16
+ end
17
+
18
+ def config
19
+ conf = {}
20
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
21
+ conf[key] = send key
22
+ end
23
+ conf
24
+ end
25
+
26
+ include WrAPI::Connection
27
+ include WrAPI::Request
28
+ include WrAPI::Authentication
29
+ include Authentication
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Veeam
3
+ # Deals with authentication flow and stores it within global configuration
4
+ module Authentication
5
+
6
+ # https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html?ver=80#tag/Authentication
7
+ # Authorize to the Veeam portal and return access_token
8
+ def login(options = {})
9
+ raise ArgumentError, "Accesstoken/api-key not set" unless access_token
10
+ # only bearer token needed
11
+ # will do sanitty check if token if valid
12
+ get("/api/v3/about")
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Veeam
2
+ class Client
3
+
4
+ # Defines methods related to About resource
5
+ # @see https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html?ver=80#tag/About/operation/GetAboutInformation
6
+ module About
7
+ # Get all backupjob reports
8
+ def about
9
+ get('/api/v3/about')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ module Veeam
2
+ class Client
3
+
4
+ # Defines methods related to alarm resources
5
+ # @see https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html?ver=80#tag/Alarms/operation/GetAlarms
6
+ module Alarms
7
+ # Returns collection resource representation of all Veeam Service Provider Console triggered alarms.
8
+ def active_alarms
9
+ get_paged('/api/v3/alarms/active')
10
+ end
11
+ alias all_triggered_alarms active_alarms
12
+
13
+ # Returns a resource representation of a triggered alarm with the specified UID.
14
+ def active_alarm(alarm_id)
15
+ get("/api/v3/alarms/active/#{alarm_id}")
16
+ end
17
+ alias triggered_alarm active_alarm
18
+
19
+ # Returns a collection resource representation of all status changes of a triggered alarm with the
20
+ # specified UID in chronological order.
21
+ def alarm_history(alarm_id)
22
+ get_paged("/api/v3/alarms/active#{alarm_id}/history")
23
+ end
24
+ alias triggered_alarm_history alarm_history
25
+
26
+ # Returns a collection resource representation of all Veeam Service Provider Console alarm templates.
27
+ def alarm_templates
28
+ get_paged('/api/v3/alarms/templates')
29
+ end
30
+ alias all_alarm_templates alarm_templates
31
+
32
+ # Returns a resource representation of a triggered alarm with the specified UID.
33
+ def alarm_template(template_id)
34
+ get("/api/v3/alarms/templates/#{template_id}")
35
+ end
36
+
37
+ # Returns all status changes of a triggered alarm with the specified template UID.
38
+ def alarm_template_events(template_id)
39
+ get_paged("/api/v3/alarms/templates/#{template_id}/events")
40
+ end
41
+ alias alarm_status_changes alarm_template_events
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ module Veeam
2
+ class Client
3
+
4
+ # Defines methods related to companies resource
5
+ # @see https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html?ver=80#tag/Companies/operation/GetCompanies
6
+ module Companies
7
+ # Get all backupjob reports
8
+ def companies
9
+ get_paged('/api/v3/organizations/companies')
10
+ end
11
+
12
+ def company(company_id)
13
+ get("/api/v3/organizations/companies/#{company_id}")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Veeam
2
+ class Client
3
+
4
+ # Defines methods related to infrastructure resources
5
+ # @see https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html?ver=80#tag/Backup-Servers/operation/GetBackupServers
6
+ module Infrastructure
7
+ # Get all backupjob reports
8
+ def backup_servers
9
+ get_paged('/api/v3/infrastructure/backupServers')
10
+ end
11
+
12
+ def backup_server(backup_id)
13
+ get("/api/v3/infrastructure/backupServers/#{backup_id}")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Veeam
2
+ # Wrapper for the Veeam REST API
3
+ #
4
+ # @note All methods have been separated into modules and follow the same grouping used in api docs
5
+ # @see https://helpcenter.veeam.com/docs/vac/rest/reference/vspc-rest.html
6
+ class Client < API
7
+ Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f }
8
+
9
+ include Veeam::Client::About
10
+ include Veeam::Client::Companies
11
+ include Veeam::Client::Infrastructure
12
+ include Veeam::Client::Alarms
13
+
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ require 'uri'
2
+ require 'json'
3
+
4
+ module Veeam
5
+ # Defines HTTP request methods
6
+ # required attributes format
7
+ module RequestPagination
8
+
9
+ class PagingInfoPager
10
+ attr_reader :offset, :limit, :total
11
+ def initialize(page_size)
12
+ @offset = 0
13
+ @limit = page_size
14
+ # we halways have a first page
15
+ @total = @offset + 1
16
+ end
17
+ def page_options
18
+ { limit: @limit, offset: @offset }
19
+ end
20
+ def next_page!(data)
21
+ @offset += @limit
22
+ meta = page_info(data)
23
+ if meta
24
+ @total = meta['total'].to_i
25
+ end
26
+ end
27
+
28
+ def more_pages?
29
+ @offset < @total
30
+ end
31
+
32
+ def page_info(body)
33
+ body['meta']['pagingInfo'] if body['meta'] && body['meta']['pagingInfo']
34
+ end
35
+
36
+ def self.data(body)
37
+ body['data'] ? body['data'] : body
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veeam
4
+ VERSION = '0.1.0'
5
+ end
data/lib/veeam.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "wrapi"
2
+ require File.expand_path('veeam/version', __dir__)
3
+ require File.expand_path('veeam/pagination', __dir__)
4
+ require File.expand_path('veeam/api', __dir__)
5
+ require File.expand_path('veeam/client', __dir__)
6
+
7
+ module Veeam
8
+ extend WrAPI::Configuration
9
+ extend WrAPI::RespondTo
10
+
11
+ DEFAULT_UA = "Veeam Ruby API wrapper #{Veeam::VERSION}".freeze
12
+ # default options to remove Accept header from WrAPI
13
+ DEFAULT_OPTIONS = { headers:{ 'User-Agent': DEFAULT_UA } }
14
+ DEFAULT_PAGINATION = RequestPagination::PagingInfoPager
15
+ # Alias for Veeam::Client.new
16
+ #
17
+ # @return [Veeam::Client]
18
+ def self.client(options = {})
19
+ Veeam::Client.new({
20
+ connection_options: DEFAULT_OPTIONS,
21
+ user_agent: DEFAULT_UA,
22
+ pagination_class: DEFAULT_PAGINATION
23
+ }.merge(options))
24
+ end
25
+
26
+ def self.reset
27
+ super
28
+ self.endpoint = nil
29
+ self.user_agent = DEFAULT_UA
30
+ self.connection_options = DEFAULT_OPTIONS
31
+ self.pagination_class = DEFAULT_PAGINATION
32
+ end
33
+ end
data/veeam.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/veeam/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'veeam'
7
+ s.version = Veeam::VERSION
8
+ s.authors = ['Janco Tanis']
9
+ s.email = 'gems@jancology.com'
10
+ s.license = 'MIT'
11
+
12
+ s.summary = 'A Ruby wrapper for the Veeam backup Portal REST APIs (readonly)'
13
+ s.homepage = 'https://rubygems.org/gems/veeam'
14
+
15
+ s.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
16
+
17
+ s.metadata['homepage_uri'] = s.homepage
18
+ s.metadata['source_code_uri'] = 'https://github.com/jancotanis/veeam'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ s.bindir = 'exe'
26
+ s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ s.require_paths = ['lib']
28
+
29
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
+ s.platform = Gem::Platform::RUBY
31
+ s.add_runtime_dependency 'faraday'
32
+ s.add_runtime_dependency 'wrapi', ">= 0.2.0"
33
+ s.add_development_dependency 'dotenv'
34
+ s.add_development_dependency 'minitest'
35
+ s.add_development_dependency 'rubocop'
36
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: veeam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Janco Tanis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: wrapi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email: gems@jancology.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".env.template"
90
+ - ".gitignore"
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - lib/veeam.rb
96
+ - lib/veeam/api.rb
97
+ - lib/veeam/authentication.rb
98
+ - lib/veeam/client.rb
99
+ - lib/veeam/client/about.rb
100
+ - lib/veeam/client/alarms.rb
101
+ - lib/veeam/client/companies.rb
102
+ - lib/veeam/client/infrastructure.rb
103
+ - lib/veeam/pagination.rb
104
+ - lib/veeam/version.rb
105
+ - veeam.gemspec
106
+ homepage: https://rubygems.org/gems/veeam
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://rubygems.org/gems/veeam
111
+ source_code_uri: https://github.com/jancotanis/veeam
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.4.0
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.2.12
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A Ruby wrapper for the Veeam backup Portal REST APIs (readonly)
131
+ test_files: []