algosec-sdk 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e450cbd6917ee2fd473b32c8bff043daaf1c6787
4
+ data.tar.gz: b9fc293773ea450cf95a3a353c512838b162e80e
5
+ SHA512:
6
+ metadata.gz: 90d0a97ec3223bdb70380907ab873a8c1d58e60e7a6bb78069866d08fe04a414b6610aa8863ef179444ed6e9534783f21cd8bb50bf0c362c7c716d71299bb206
7
+ data.tar.gz: a56dfbe55e022ee3a8a7acfbaac336265dfb1e26634f747fae52be277e90e573483681a2a7cf4a7361ba589313f2895d9ba2aad18ae2afe4c6f29aefb266cfc7
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ Berksfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
24
+ *.sw*
25
+ .idea/
@@ -0,0 +1,68 @@
1
+ # See default at https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+ AllCops:
3
+ TargetRubyVersion: 2.1
4
+
5
+ Metrics/ClassLength:
6
+ Max: 200
7
+
8
+ Metrics/LineLength:
9
+ Max: 120
10
+
11
+ Metrics/ModuleLength:
12
+ Max: 200
13
+
14
+ Metrics/ParameterLists:
15
+ Max: 6
16
+
17
+ Layout/IndentationWidth:
18
+ Width: 2
19
+
20
+ Naming/VariableName:
21
+ EnforcedStyle: snake_case
22
+
23
+ Naming/FileName:
24
+ Exclude:
25
+ - 'lib/algosec-sdk.rb'
26
+
27
+ Layout/AlignParameters:
28
+ Enabled: true
29
+
30
+ Naming/AccessorMethodName:
31
+ Enabled: false
32
+
33
+ Naming/ClassAndModuleCamelCase:
34
+ Enabled: false
35
+
36
+ Metrics/BlockLength:
37
+ Enabled: false
38
+
39
+ Metrics/AbcSize:
40
+ Enabled: false
41
+
42
+ Metrics/CyclomaticComplexity:
43
+ Enabled: false
44
+
45
+ Metrics/MethodLength:
46
+ Enabled: false
47
+
48
+ Metrics/PerceivedComplexity:
49
+ Enabled: false
50
+
51
+ Performance/Casecmp:
52
+ Enabled: false
53
+
54
+ Lint/AmbiguousBlockAssociation:
55
+ Exclude:
56
+ - "spec/**/*"
57
+
58
+ #Style/EmptyLines:
59
+ # Enabled: false
60
+ #
61
+ #Style/RescueModifier:
62
+ # Enabled: false
63
+ #
64
+ #Style/EmptyLinesAroundBlockBody:
65
+ # Enabled: false
66
+ #
67
+ #Style/EmptyLinesAroundClassBody:
68
+ # Enabled: false
@@ -0,0 +1 @@
1
+ algosecsdk
@@ -0,0 +1 @@
1
+ 2.4.1
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ notifications:
3
+ - false
@@ -0,0 +1,5 @@
1
+ ### New (Unreleased)
2
+ - (none)
3
+
4
+ ## v1.0.0
5
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :test do
5
+ gem 'coveralls', require: false
6
+ gem 'pry-byebug'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 AlgoSec Systems Ltd.
2
+ All Rights Reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to
6
+ deal in the Software without restriction, including without limitation the
7
+ rights to use, copy, modify, merge, publish, distribute and/or sublicense,
8
+ and to permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
+ IN THE SOFTWARE.
@@ -0,0 +1,208 @@
1
+ # Ruby SDK for AlgoSec Services
2
+
3
+ [![Coverage Status](https://coveralls.io/repos/github/algosec/algosec-ruby/badge.svg)](https://coveralls.io/github/algosec/algosec-ruby)
4
+ [![Build Status](https://travis-ci.org/algosec/algosec-ruby.svg)](https://travis-ci.org/algosec/algosec-ruby)
5
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/github/algosec/algosec-ruby)
6
+ [![Gem Version](https://badge.fury.io/rb/algosec-sdk.svg)](https://badge.fury.io/rb/algosec-sdk)
7
+
8
+ Software Development Kit for interacting with the AlgoSec services API.
9
+
10
+ ## Installation
11
+
12
+ - Require the gem in your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'algosec-sdk'
16
+ ```
17
+
18
+ Then run `$ bundle install`
19
+ - Or run the command:
20
+
21
+ ```bash
22
+ $ gem install algosec-sdk
23
+ ```
24
+
25
+
26
+ ## Client
27
+
28
+ Everything you do with this API happens through a client object.
29
+ Creating the client object is the first step; then you can perform actions on the client.
30
+
31
+ ```ruby
32
+ require 'algosec-sdk'
33
+ client = ALGOSEC_SDK::Client.new(
34
+ host: 'https://local.algosec.com',
35
+ user: 'admin', # This is the default
36
+ password: 'algosec',
37
+ ssl_enabled: false, # This is the default and strongly encouraged
38
+ logger: Logger.new(STDOUT), # This is the default
39
+ log_level: :info, # This is the default
40
+ disable_proxy: true # Default is false. Set to disable, even if ENV['http_proxy'] is set
41
+ )
42
+ client.login
43
+ ```
44
+
45
+ :lock: Tip: Check the file permissions when storing passwords in clear-text.
46
+
47
+ #### Environment Variables
48
+
49
+ You can also set many client options using environment variables. For bash:
50
+
51
+ ```bash
52
+ export ALGOSEC_HOST='https://oneview.example.com'
53
+ export ALGOSEC_USER='admin'
54
+ export ALGOSEC_PASSWORD='secret123'
55
+ export ALGOSEC_SSL_ENABLED=false # NOTE: Disabling SSL is strongly discouraged.
56
+ ```
57
+
58
+ :lock: Tip: Be sure nobody can access to your environment variables
59
+
60
+ ### Custom logging
61
+
62
+ The default logger is a standard logger to STDOUT, but if you want to specify your own, you can. However, your logger must implement the following methods:
63
+
64
+ ```ruby
65
+ debug(String)
66
+ info(String)
67
+ warn(String)
68
+ error(String)
69
+ level=(symbol, etc.) # The parameter here will be the log_level attribute
70
+ ```
71
+
72
+
73
+ ## Actions
74
+
75
+ Actions are performed on the client, and defined in the [helper modules](lib/algosec-sdk/helpers).
76
+
77
+ #### Business Flow
78
+
79
+ ```ruby
80
+ # Get list of application flows for an application revision id
81
+ client.get_application_flows(app_revision_id)
82
+
83
+ # Delete a specific flow
84
+ client.delete_flow_by_id(app_revision_id, flow_id)
85
+
86
+ # Get connectivity status for a flow
87
+ client.get_flow_connectivity(app_revision_id, flow_id)
88
+
89
+ # Create a flow
90
+ client.create_application_flow(
91
+ app_revision_id,
92
+ flow_name,
93
+ sources,
94
+ destinations,
95
+ network_users,
96
+ network_apps,
97
+ network_services,
98
+ comment,
99
+ )
100
+
101
+ # Fetch an application flow by it's name
102
+ client.get_application_flow_by_name(app_revision_id, flow_name)
103
+
104
+ # Get latest application revision id by application name
105
+ client.get_app_revision_id_by_name(app_name)
106
+
107
+ # Apply application draft
108
+ client.apply_application_draft(app_revision_id)
109
+
110
+ # Create a new network service
111
+ client.create_network_service(service_name, content)
112
+
113
+ # Create a new network object
114
+ client.create_network_object(type, content, name)
115
+
116
+ # defining the complete list of flows for a given app
117
+ flows = client.define_application_flows(
118
+ 'TEST',
119
+ [
120
+ 'flow1' => {
121
+ 'sources' => ['HR Payroll server', '192.168.0.0/16'],
122
+ 'destinations' => ['16.47.71.62'],
123
+ 'services' => ['HTTPS']
124
+ },
125
+ 'flow2' => {
126
+ 'sources' => ['10.0.0.1'],
127
+ 'destinations' => ['10.0.0.2'],
128
+ 'services' => ['udp/501']
129
+ },
130
+ 'flow3' => {
131
+ 'sources' => ['1.2.3.4'],
132
+ 'destinations' => ['3.4.5.6'],
133
+ 'services' => ['SSH']
134
+ }
135
+ ]
136
+ )
137
+
138
+ ```
139
+
140
+ ## Custom requests
141
+
142
+ This gem includes some useful helper methods, but sometimes you need to make your own custom requests to the AlgoSec.
143
+ This project makes it extremely easy to do with some built-in methods for the client object. Here are some examples:
144
+
145
+ ```ruby
146
+ # Get the application object:
147
+ response = client.rest_api(:get, '/BusinessFlow/rest/v1/applications/name/applicationName')
148
+ # or even more simple:
149
+ response = client.rest_get('/BusinessFlow/rest/v1/applications/name/applicationName')
150
+
151
+
152
+ # Then we can validate the response and convert the response body into a hash...
153
+ data = client.response_handler(response)
154
+
155
+ # For creating new BusinessFlow resources, use post:
156
+ options = { some: 'Data' }
157
+ response = client.rest_post('/BusinessFlow/rest/v1/exampleURL', body: options)
158
+ ```
159
+
160
+ These example are about as basic as it gets, but you can make any type of AlgoSec API request.
161
+ If a helper does not do what you need, this will allow you to do it.
162
+ Please refer to the documentation and [code](lib/algosec-sdk/rest.rb) for complete list of methods and information about how to use them.
163
+
164
+
165
+ ## License
166
+
167
+ This project is licensed under the MIT license. Please see [LICENSE](LICENSE) for more info.
168
+
169
+
170
+ ## Contributing and feature requests
171
+
172
+ **Contributing:** You know the drill. Fork it, branch it, change it, commit it, and pull-request it.
173
+ We are passionate about improving this project, and glad to accept help to make it better. However, keep the following in mind:
174
+
175
+ - All pull requests must contain complete test code also. See the testing section below.
176
+ - We reserve the right to reject changes that we feel do not fit the scope of this project, so for feature additions, please open an issue to discuss your ideas before doing the work.
177
+
178
+ **Feature Requests:** If you have a need that is not met by the current implementation, please let us know (via a new issue).
179
+ This feedback is crucial for us to deliver a useful product. Do not assume we have already thought of everything, because we assure you that is not the case.
180
+
181
+ ### Building the Gem
182
+
183
+ First run `$ bundle` (requires the bundler gem), then...
184
+ - To build only, run `$ rake build`.
185
+ - To build and install the gem, run `$ rake install`.
186
+
187
+ #### Pushing the gem to rubygems.org
188
+
189
+ ```bash
190
+ $ rake build
191
+ $ gem push pkg/algosec-sdk-<gem-version>.gem
192
+ ```
193
+
194
+ ### Use Gem from sourcecode
195
+
196
+ Run `pry -Ilib` then follow the README examples above. (don't forget to `require` the Gem)
197
+
198
+ ### Testing
199
+
200
+ - RuboCop: `$ rake rubocop`
201
+ - Unit: `$ rake spec`
202
+ - All test: `$ rake test`
203
+
204
+ Note: run `$ rake -T` to get a list of all the available rake tasks.
205
+
206
+ ## Authors
207
+
208
+ - AlmogCohen - [@AlmogCohen](https://github.com/AlmogCohen)
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+ require 'bundler/setup'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ task default: :test
8
+
9
+ desc 'Run unit tests only'
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ require 'pry-byebug'
12
+ spec.pattern = 'spec/**/*_spec.rb'
13
+ spec.rspec_opts = '--color '
14
+ end
15
+
16
+ RuboCop::RakeTask.new do |task|
17
+ task.options << '--display-cop-names'
18
+ end
19
+
20
+ desc 'Runs rubocop and unit tests'
21
+ task test: %i[rubocop spec]
@@ -0,0 +1,28 @@
1
+ # http://guides.rubygems.org/specification-reference
2
+ require_relative './lib/algosec-sdk/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'algosec-sdk'
6
+ spec.version = ALGOSEC_SDK::VERSION
7
+ spec.authors = ['Almog Cohen']
8
+ spec.email = ['almog.cohen@algosec.com']
9
+ spec.summary = 'Gem to interact with AlgoSec API'
10
+ spec.description = 'Gem to interact with AlgoSec API'
11
+ spec.license = 'MIT'
12
+ spec.homepage = 'https://github.com/algosec/algosec-ruby'
13
+
14
+ all_files = `git ls-files -z`.split("\x0")
15
+ spec.files = all_files.reject { |f| f.match(%r{^(examples\/)|(spec\/)}) }
16
+ spec.executables = all_files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'httpclient'
20
+ spec.add_runtime_dependency 'ipaddress'
21
+
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'rubocop', '> 0.49.0'
27
+ spec.add_development_dependency 'simplecov'
28
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'algosec-sdk/version'
2
+ require_relative 'algosec-sdk/client'
3
+ require_relative 'algosec-sdk/exceptions'
4
+
5
+ # Module for interracting with the AlgoSec API
6
+ module ALGOSEC_SDK
7
+ ENV_VARS = %w[ALGOSEC_HOST ALGOSEC_USER ALGOSEC_PASSWORD ALGOSEC_SSL_ENABLED].freeze
8
+ end
@@ -0,0 +1,69 @@
1
+ require 'logger'
2
+ require_relative 'rest'
3
+ # Load all helpers:
4
+ Dir[File.join(File.dirname(__FILE__), '/helpers/*.rb')].each { |file| require file }
5
+
6
+ module ALGOSEC_SDK
7
+ # The client defines the connection to the AlgoSec and handles communication with it
8
+ class Client
9
+ attr_accessor :http_client, :host, :user, :password, :ssl_enabled, :disable_proxy, :logger, :log_level
10
+
11
+ # Create a client object
12
+ # @param [Hash] options the options to configure the client
13
+ # @option options [String] :host (ENV['ALGOSEC_HOST']) URL, hostname, or IP address of the AlgoSec server
14
+ # @option options [String] :user ('admin') Username to use for authentication with the AlgoSec server
15
+ # @option options [String] :password Password to use for authentication with the AlgoSec server
16
+ # @option options [Logger] :logger (Logger.new(STDOUT)) Logger object to use.
17
+ # Must implement debug(String), info(String), warn(String), error(String), & level=
18
+ # @option options [Symbol] :log_level (:info) Log level.
19
+ # Logger must define a constant with this name. ie Logger::INFO
20
+ # @option options [Boolean] :ssl_enabled (true) Use ssl for requests?
21
+ # @option options [Boolean] :disable_proxy (false) Disable usage of a proxy for requests?
22
+ def initialize(options = {})
23
+ options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
24
+ @logger = options[:logger] || Logger.new(STDOUT)
25
+ %i[debug info warn error level=].each do |m|
26
+ raise "Logger must respond to #{m} method " unless @logger.respond_to?(m)
27
+ end
28
+ @log_level = options[:log_level] || :info
29
+ @logger.level = begin
30
+ @logger.class.const_get(@log_level.upcase)
31
+ rescue StandardError
32
+ @log_level
33
+ end
34
+ @host = options[:host] || ENV['ALGOSEC_HOST']
35
+ raise InvalidClient, 'Must set the host option' unless @host
36
+ @host = 'https://' + @host unless @host.start_with?('http://', 'https://')
37
+ @ssl_enabled = true # Default
38
+ if ENV.key?('ALGOSEC_SSL_ENABLED')
39
+ @ssl_enabled = case ENV['ALGOSEC_SSL_ENABLED']
40
+ when 'true', '1' then true
41
+ when 'false', '0' then false
42
+ else ENV['ALGOSEC_SSL_ENABLED']
43
+ end
44
+ end
45
+ @ssl_enabled = options[:ssl_enabled] unless options[:ssl_enabled].nil?
46
+ unless [true, false].include?(@ssl_enabled)
47
+ raise InvalidClient, "ssl_enabled option must be true or false. Got '#{@ssl_enabled}'"
48
+ end
49
+ unless @ssl_enabled
50
+ @logger.warn "SSL is disabled for all requests to #{@host}!"\
51
+ ' We recommend you import the necessary certificates instead of disabling SSL.'
52
+ end
53
+ @disable_proxy = options[:disable_proxy]
54
+ unless [true, false, nil].include?(@disable_proxy)
55
+ raise InvalidClient, 'disable_proxy option must be true, false, or nil'
56
+ end
57
+ @logger.warn 'User option not set. Using default (admin)' unless options[:user] || ENV['ALGOSEC_USER']
58
+ @user = options[:user] || ENV['ALGOSEC_USER'] || 'admin'
59
+ @password = options[:password] || ENV['ALGOSEC_PASSWORD']
60
+ raise InvalidClient, 'Must set the password option' unless @password
61
+ init_http_client
62
+ end
63
+
64
+ include Rest
65
+
66
+ # Include helper modules:
67
+ include BusinessFlowHelper
68
+ end
69
+ end