skykick 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eafaae81c547995fd55e21844d23699293636cd2fac1d055c921c16308f340ff
4
+ data.tar.gz: e67e661fd6da88eab1204aa4680ad82be1cb67cd43e5d56512bd21419be3bba2
5
+ SHA512:
6
+ metadata.gz: e6066c80ada508164d556034e15c5db6a060393d1363deb112583c34ef19572b0a5c8e6bd1727dd293d406f26f3ba0f8c9498be8f5264d2f77000c30b2adfee1
7
+ data.tar.gz: 85e2993883ad13a33e8d5e90162a61b12e64b346d47f2ea59bb86765cbf61e0ab16e467dc9ea5d3379a384768d8a733993ebfa0ffbd7cc9c3128d363555f2212
data/.env.template ADDED
@@ -0,0 +1,2 @@
1
+ SKYKICK_CLIENT_ID=<SKYKICK_CLIENT_ID>
2
+ SKYKICK_CLIENT_SECRET=<SKYKICK_CLIENT_SECRET>
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-05
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,95 @@
1
+ # Skykick Office365 backup API
2
+
3
+ This is a wrapper for the Skykick Office365 backup API. You can see the API endpoints here https://developers.skykick.com/apis
4
+
5
+ Currently only the GET requests to endpoints /Backup and /Alerts are implemented (readonly).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'skykick'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install skykick
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 'skykick'
29
+
30
+ Skykick.configure do |config|
31
+ config.client_id = ENV["SKYKICK_CLIENT_ID"]
32
+ config.client_secret = ENV["SKYKICK_CLIENT_SECRET"]
33
+ end
34
+ @client = Skykick.client()
35
+ @client.login
36
+
37
+ dc = @client.datacenters
38
+
39
+ dc.each do |t|
40
+ puts "#{t.name}"
41
+ end
42
+ ```
43
+
44
+ ## Resources
45
+ ### Authentication
46
+ ```
47
+ # setup configuration
48
+ #
49
+ client.login
50
+ ```
51
+ |Resource|API endpoint|Description|
52
+ |:--|:--|:--|
53
+ |.auth_token or .login|https://apis.skykick.com/auth/token|
54
+
55
+
56
+ ### Backup
57
+ Endpoint for backup related requests
58
+ ```
59
+ licenses = client.tenant_licenses
60
+ ```
61
+
62
+ |Resource|API endpoint|
63
+ |:--|:--|
64
+ |autodiscover |https://apis.skykick.com/Backup/{id}/autodiscover |
65
+ |datacenters |https://apis.skykick.com/Backup/datacenters |
66
+ |exchange_mailboxe |https://apis.skykick.com/Backup/{id}/mailboxes/{mailboxId} |
67
+ |exchange_mailboxes |https://apis.skykick.com/Backup/{id}/mailboxes |
68
+ |lastsnapshotstats |https://apis.skykick.com/Backup/{backupServiceId}/lastsnapshotstats |
69
+ |retention_periods |https://apis.skykick.com/Backup/{id}/retentionperiod |
70
+ |sharePoint_sites |https://apis.skykick.com/Backup/{id}/sites |
71
+ |sku |https://apis.skykick.com/Backup/{id}/sku |
72
+ |storage_settings |https://apis.skykick.com/Backup/{id}/storagesettings |
73
+ |subscription_settings |https://apis.skykick.com/Backup/{id}/subscriptionsettings |
74
+ |subscriptions |https://apis.skykick.com/Backup/ |
75
+ |partner_subscriptions(partner_id)|https://apis.skykick.com/Backup/{partner_id} |
76
+
77
+
78
+ ### Alerts
79
+ Returns Alerts for a provided Email Migration Order ID or Backup service ID.
80
+ ```
81
+ alerts = client.alerts(subscription_id)
82
+
83
+ ```
84
+
85
+ |Resource|API endpoint|
86
+ |:--|:--|
87
+ |.alerts|/Alerts|
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/integra365.
92
+
93
+ ## License
94
+
95
+ 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]
@@ -0,0 +1,32 @@
1
+ require "wrapi"
2
+ require File.expand_path('connection', __dir__)
3
+ require File.expand_path('authentication', __dir__)
4
+
5
+ module Skykick
6
+ # @private
7
+ class API
8
+ # @private
9
+ attr_accessor *WrAPI::Configuration::VALID_OPTIONS_KEYS
10
+
11
+ # Creates a new API and copies settings from singleton
12
+ def initialize(options = {})
13
+ options = Skykick.options.merge(options)
14
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ def config
20
+ conf = {}
21
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
22
+ conf[key] = send key
23
+ end
24
+ conf
25
+ end
26
+
27
+ include Connection
28
+ include WrAPI::Request
29
+ include WrAPI::Authentication
30
+ include Authentication
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+ require 'uri'
3
+
4
+ module Skykick
5
+ # Deals with authentication flow and stores it within global configuration
6
+ module Authentication
7
+ # Authorize to the Skykick portal and return access_token
8
+ # @see https://developers.skykick.com/Guides/Authentication
9
+ def auth_token(options = {})
10
+ c = connection
11
+ c.basic_auth(client_id, client_secret)
12
+ response = c.post('/auth/token') do |request|
13
+ request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
14
+ request.body = URI.encode_www_form( api_access_token_params )
15
+ end
16
+
17
+ api_process_token(response.body)
18
+ end
19
+ alias login auth_token
20
+
21
+ private
22
+
23
+ def api_access_token_params
24
+ {
25
+ grant_type: 'client_credentials',
26
+ scope: 'Partner'
27
+ }
28
+ end
29
+
30
+ def api_process_token(response)
31
+ at = self.access_token = response['access_token']
32
+ self.token_type = response['token_type']
33
+ self.refresh_token = response['refresh_token']
34
+ self.token_expires = response['expires_in']
35
+ raise StandardError.new 'Could not find valid access_token; response ' + response.to_s if at.nil? || at.empty?
36
+
37
+ at
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ module Skykick
2
+ class Client
3
+
4
+ # All alert related api calls
5
+ # @see https://developers.skykick.com/
6
+ module Alerts
7
+
8
+ # Returns first 500 Alerts for a provided Email Migration Order ID or Backup service ID.
9
+ def alerts(id)
10
+ # This endpoint supports the following OData query parameters: $top
11
+ # $top - default of 25 and max of 500
12
+ # this is not implemented
13
+ get("Alerts/#{id}?$top=500")
14
+ end
15
+
16
+ # Mark an Alert as complete.
17
+ def mark_as_complete(id)
18
+ post("Alerts/#{id}")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,77 @@
1
+ module Skykick
2
+ class Client
3
+
4
+ # All backup related api calls
5
+ # @see https://developers.skykick.com/
6
+ module Backup
7
+
8
+ # Returns a list of supported Azure data centers.
9
+ def datacenters
10
+ get('Backup/datacenters')
11
+ end
12
+
13
+ # Gets a list of placed Backup subscription orders
14
+ def subscriptions()
15
+ get('Backup')
16
+ end
17
+
18
+ # Gets a list of placed Backup subscription orders
19
+ def partner_subscriptions(partner_id)
20
+ get("Backup/#{partner_id}")
21
+ end
22
+
23
+ # Returns Backup subscription settings. Settings include the enabled
24
+ # state for Exchange and SharePoint Backups and total count of enabled
25
+ # Exchange mailboxes and SharePoint sites as well as the state of the subscription.
26
+ def subscription_settings(id)
27
+ get("Backup/#{id}/subscriptionsettings")
28
+ end
29
+
30
+ # Returns storage settings for a Backup subscription.
31
+ def storage_settings(id)
32
+ get("Backup/#{id}/storagesettings")
33
+ end
34
+
35
+ # Gets SKU/promo details for a Backup service.
36
+ def sku(id)
37
+ get("Backup/#{id}/sku")
38
+ end
39
+
40
+ # Returns a list of SharePoint site URLs and statuses (enabled/disabled)
41
+ # for a Backup subscription.
42
+ def sharepoint_sites(id)
43
+ get("Backup/#{id}/sites")
44
+ end
45
+
46
+ # Returns the data retention periods for a Backup subscription. There are different
47
+ # retention periods for Exchange and SharePoint Data.
48
+ #
49
+ # Please Note: We are aware of the spelling error of the word "retention" in the response
50
+ # field ExchangeRentionPeriodInDays. This is not a mistake in the documentation, but has
51
+ # been left this way as not to disrupt any existing integrations with this endpoint.
52
+ def retentionperiod(id)
53
+ get("Backup/#{id}/retentionperiod")
54
+ end
55
+
56
+ # Gets stats for snapshots from SKDataWarehouse for all mailboxes of a given backupServiceId
57
+ def lastsnapshotstats(id)
58
+ get("Backup/#{id}/lastsnapshotstats")
59
+ end
60
+
61
+ # Returns a list of Exchange mailboxes and statuses (enabled/disabled) for a Backup subscription.
62
+ def exchange_mailboxes(id)
63
+ get("Backup/#{id}/mailboxes")
64
+ end
65
+
66
+ # Returns a list of Exchange mailboxes and statuses (enabled/disabled) for a Backup subscription.
67
+ def exchange_mailbox(id, mailbox_id)
68
+ get("Backup/#{id}/mailboxes/#{mailbox_id}")
69
+ end
70
+
71
+ # Returns the Exchange and SharePoint auto-discover states (enabled/disabled) of a Backup subscription.
72
+ def autodiscover(id)
73
+ get("Backup/#{id}/autodiscover")
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,12 @@
1
+ module Skykick
2
+ # Wrapper for the Skykick REST API
3
+ #
4
+ # @note All methods have been separated into modules and follow the same grouping used in api docs
5
+ # @see https://developers.skykick.com/Guides/Authentication
6
+ class Client < API
7
+ Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f }
8
+
9
+ include Skykick::Client::Backup
10
+ include Skykick::Client::Alerts
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ require 'faraday'
2
+
3
+ module Skykick
4
+
5
+ # Create connection including authorization parameters with default Accept format and User-Agent
6
+ # By default
7
+ # - Bearer authorization is access_token is not nil override with @setup_authorization
8
+ # - Headers setup for Ocp-Apim-Subscription-Key when client_id and client_secret are not nil @setup_headers
9
+ # @private
10
+ module Connection
11
+ include WrAPI::Connection
12
+
13
+ # callback method to setup api headers
14
+ def setup_headers(connection)
15
+ connection.headers['Ocp-Apim-Subscription-Key'] = client_secret if client_secret
16
+ end
17
+
18
+ # callback method to setup logger
19
+ def setup_logger_filtering(connection, logger)
20
+ connection.response :logger, logger, { headers: true, bodies: true } do |l|
21
+ # filter json content
22
+ l.filter(/("password":")(.+?)(".*)/, '\1[REMOVED]\3')
23
+ l.filter(/("accessToken":")(.+?)(".*)/, '\1[REMOVED]\3')
24
+ # filter header content
25
+ l.filter(/(client-secret:.)([^&]+)/, '\1[REMOVED]')
26
+ l.filter(/(Authorization:.)([^&]+)/, '\1[REMOVED]')
27
+ # skykick
28
+ l.filter(/(Ocp-Apim-Subscription-Key: ")(.+?)(\")/, '\1[REMOVED]\3')
29
+ l.filter(/("access_token":")(.+?)(".*)/, '\1[REMOVED]\3')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skykick
4
+ VERSION = '0.1.0'
5
+ end
data/lib/skykick.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "wrapi"
2
+ require File.expand_path('skykick/api', __dir__)
3
+ require File.expand_path('skykick/client', __dir__)
4
+ require File.expand_path('skykick/version', __dir__)
5
+
6
+ module Skykick
7
+ extend WrAPI::Configuration
8
+ extend WrAPI::RespondTo
9
+
10
+ DEFAULT_ENDPOINT = 'https://apis.skykick.com'.freeze
11
+ DEFAULT_UA = "Skykick Ruby API wrapper #{Skykick::VERSION}".freeze
12
+
13
+ # Alias for Skykick::Client.new
14
+ #
15
+ # @return [Skykick::Client]
16
+ def self.client(options = {})
17
+ Skykick::Client.new({
18
+ endpoint: DEFAULT_ENDPOINT,
19
+ user_agent: DEFAULT_UA
20
+ }.merge(options))
21
+ end
22
+
23
+ def self.reset
24
+ super
25
+ self.endpoint = DEFAULT_ENDPOINT
26
+ self.user_agent = DEFAULT_UA
27
+ end
28
+ end
data/skykick.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/skykick/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'skykick'
7
+ s.version = Skykick::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 Skykick backup Portal REST APIs (readonly)'
13
+ s.homepage = 'https://rubygems.org/gems/skykick'
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/skykick'
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.1.3"
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,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skykick
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-06 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.1.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.3
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/skykick.rb
96
+ - lib/skykick/api.rb
97
+ - lib/skykick/authentication.rb
98
+ - lib/skykick/client.rb
99
+ - lib/skykick/client/alerts.rb
100
+ - lib/skykick/client/backup.rb
101
+ - lib/skykick/connection.rb
102
+ - lib/skykick/version.rb
103
+ - skykick.gemspec
104
+ homepage: https://rubygems.org/gems/skykick
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ homepage_uri: https://rubygems.org/gems/skykick
109
+ source_code_uri: https://github.com/jancotanis/skykick
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 2.4.0
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.2.12
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Ruby wrapper for the Skykick backup Portal REST APIs (readonly)
129
+ test_files: []