Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support additional ABF application APIs #3

Merged
merged 4 commits into from Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .rubocop.yml
@@ -1,6 +1,6 @@
# See default at https://github.com/bbatsov/rubocop/blob/master/config/default.yml
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.2

Metrics/ClassLength:
Max: 200
Expand All @@ -9,7 +9,7 @@ Metrics/LineLength:
Max: 120

Metrics/ModuleLength:
Max: 200
Max: 220

Metrics/ParameterLists:
Max: 6
Expand Down
51 changes: 43 additions & 8 deletions lib/algosec-sdk/helpers/business_flow_helper.rb
Expand Up @@ -6,19 +6,19 @@

module ALGOSEC_SDK
module NetworkObjectType
HOST = 'Host'
RANGE = 'Range'
GROUP = 'Group'
ABSTRACT = 'Abstract'
HOST = 'Host'.freeze
RANGE = 'Range'.freeze
GROUP = 'Group'.freeze
ABSTRACT = 'Abstract'.freeze
end
end

module ALGOSEC_SDK
module NetworkObjectSearchType
INTERSECT = 'INTERSECT'
CONTAINED = 'CONTAINED'
CONTAINING = 'CONTAINING'
EXACT = 'EXACT'
INTERSECT = 'INTERSECT'.freeze
CONTAINED = 'CONTAINED'.freeze
CONTAINING = 'CONTAINING'.freeze
EXACT = 'EXACT'.freeze
end
end

Expand All @@ -32,6 +32,41 @@ def login
response_handler(rest_post('/BusinessFlow/rest/v1/login'))
end

# Create an application
# @param [String] name The application's name.
# @param [Array<String>] custom_fields Existing custom fields to assign to the application.
# @param [Array<String>] contacts Existing contacts to assign to the application.
# @param [Array<String>] labels Existing labels to assign to the application.
# @param [Array<String>] flows The flows to add to the application upon creation.
# @raise [RuntimeError] if the request failed
# @return Newly created Application object
def create_application(
name,
custom_fields = [],
contacts = [],
labels = [],
flows = []
)
new_application = {
name: name,
custom_fields: custom_fields,
contacts: contacts,
labels: labels,
flows: flows
}
response = rest_post('/BusinessFlow/rest/v1/applications/new', body: new_application)
response_handler(response)
end

# Decommission an application
# @param [String] app_revision_id
# @raise [RuntimeError] if the request failed
# @return true
def decommission_application(app_revision_id)
response = rest_post("/BusinessFlow/rest/v1/applications/#{app_revision_id}/decommission")
response_handler(response)
end

# Get list of application flows for an application revision id
# @param [String, Symbol] app_revision_id
# @raise [RuntimeError] if the request failed
Expand Down
2 changes: 1 addition & 1 deletion lib/algosec-sdk/version.rb
Expand Up @@ -2,5 +2,5 @@

# Gem version defined here
module ALGOSEC_SDK
VERSION = '1.1.0'
VERSION = '1.1.0'.freeze
end
6 changes: 3 additions & 3 deletions rakelib/end-to-end-integration.rake
Expand Up @@ -18,9 +18,9 @@ task :e2e, %i[app host user password] => [] do |_t, args|
client = ALGOSEC_SDK::Client.new(options)
client.login

NEW_FLOW_NAME = 'test-flow-name'
NETWORK_OBJECT_IP = '192.168.123.124'
NETWORK_SERVICE_NAME = 'TCP/202'
NEW_FLOW_NAME = 'test-flow-name'.freeze
NETWORK_OBJECT_IP = '192.168.123.124'.freeze
NETWORK_SERVICE_NAME = 'TCP/202'.freeze
NETWORK_SERVICE_DEFINITION = [%w[tcp 202]].freeze

puts '### END-TO-END INTEGRATION STARTED ###'
Expand Down
54 changes: 54 additions & 0 deletions spec/unit/helpers/business_flow_helper_spec.rb
Expand Up @@ -12,6 +12,60 @@
@client.login
end
end
describe '#create_application#' do
it 'makes a POST rest call' do
new_app = {
name: 'application-name',
custom_fields: [{ name: 'field1', value: 'value1' }, { name: 'field2', value: 'value2' }],
contacts: [{ email: 'email1', role: 'role1' }, { email: 'email2', role: 'role2' }],
labels: %w[label1 label2],
flows: [{ name: 'flow-name1' }, { name: 'flow-name2' }]
}
fake_response = FakeResponse.new(new_app)
expect(@client).to receive(:rest_post).with(
'/BusinessFlow/rest/v1/applications/new',
body: new_app
).and_return(fake_response)
ret_val = @client.create_application(
'application-name',
[{ name: 'field1', value: 'value1' }, { name: 'field2', value: 'value2' }],
[{ email: 'email1', role: 'role1' }, { email: 'email2', role: 'role2' }],
%w[label1 label2],
[{ name: 'flow-name1' }, { name: 'flow-name2' }]
)
expect(ret_val.to_json).to eq(new_app.to_json)
end
it 'makes a POST call with default values' do
new_app = {
name: 'application-name',
custom_fields: [],
contacts: [],
labels: [],
flows: []
}
fake_response = FakeResponse.new(new_app)
expect(@client).to receive(:rest_post).with(
'/BusinessFlow/rest/v1/applications/new',
body: new_app
).and_return(fake_response)
ret_val = @client.create_application('application-name')
expect(ret_val.to_json).to eq(new_app.to_json)
end
end
describe '#delete_application_flow#' do
it 'makes a POST rest call' do
change_application_response = {
Application: 'application-obj',
ChangeRequest: 'change-request-object'
}
fake_response = FakeResponse.new(change_application_response)
expect(@client).to receive(:rest_post).with(
'/BusinessFlow/rest/v1/applications/application-id/decommission'
).and_return(fake_response)
ret_val = @client.decommission_application('application-id')
expect(ret_val.to_json).to eq(change_application_response.to_json)
end
end
describe '#get_application_flows#' do
it 'makes a GET rest call' do
# rubocop:disable Style/NumericLiterals
Expand Down