-
Notifications
You must be signed in to change notification settings - Fork 103
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
Migrate eso-client to nexpose-client / CSRF header update #309
Conversation
# @return [Step] Step object corresponding to the given service. | ||
# | ||
def get_step(type_name) | ||
@steps.find do |step| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer detect over find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/eso/workflow.rb
Outdated
@id = id | ||
@name = name | ||
@steps = steps | ||
@timeCreated = timeCreated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use snake_case for variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trust me @houndci-bot I want to. But there is some old code here, notably to_hash
, which is kinda cheating in its parsing and directly converting the JSON from Nexpose (which uses camelCase) directly into the variables for this class. And if I change that, I'd have to refactor a wholllllleeeee lotta code.
This mirrors the changes in rapid7/nexpose-client#309 but limited to discovery connections.
STOPPED = 'stopped' | ||
|
||
# Workflow or an integration option has experienced an error that caused it to stop | ||
ERROR = 'error' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
RETRY = 'retry' | ||
|
||
# Workflow or an integration option is stopped by the user | ||
STOPPED = 'stopped' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
RUNNING = 'running' | ||
|
||
# The workflow or an integration option is running, but is temporarily unsuccessful processing events | ||
RETRY = 'retry' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
READY = 'ready' | ||
|
||
# Workflow or an integration option is processing or has processed events | ||
RUNNING = 'running' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
# Representation of state of a workflow or integration option. Taken from service-orchestration State.java | ||
module State | ||
# Workflow or an integration option is configured and ready to accept events | ||
READY = 'ready' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
hash = { | ||
:typeName => @typeName, | ||
:previousTypeName => @previousTypeName, | ||
:configurationParams => @configurationParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
def to_h | ||
hash = { | ||
:typeName => @typeName, | ||
:previousTypeName => @previousTypeName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
|
||
def to_h | ||
hash = { | ||
:typeName => @typeName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
Use the new Ruby 1.9 hash syntax.
} | ||
else | ||
raise ArgumentError, "Invalid StepConfiguration ConfigurationParameter Property name: #{name}. " + | ||
'Should be one of StepConfiguration::ConfigParamProperties' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align the operands of an expression in an assignment spanning multiple lines.
value: value | ||
} | ||
else | ||
raise ArgumentError, "Invalid StepConfiguration ConfigurationParameter Property name: #{name}. " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use \ instead of + or << to concatenate those strings.
# @return [Hash] Hash interpretation of this IntegrationOption. | ||
def to_hash | ||
hash = {} | ||
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space between { and | missing.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Space missing inside }.
# Grab the Step objects and convert to Hashes | ||
steps = hash['steps'] | ||
hashified_steps = [] | ||
steps.each {|step| hashified_steps << step.to_hash} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space between { and | missing.
Space missing inside }.
module IntegrationOptionTypes | ||
# The IMPORT_TO_SITE Array tracks Integration Options which load Assets into a Site. | ||
IMPORT_TO_SITE = [ | ||
IntegrationOptionNames::IMPORT_AD_ASSETS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is.
# IntegrationOptionTypes is a way to categorize what various Integration Options do. | ||
module IntegrationOptionTypes | ||
# The IMPORT_TO_SITE Array tracks Integration Options which load Assets into a Site. | ||
IMPORT_TO_SITE = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
IMPORT_AD_ASSETS = 'import_ad_assets' | ||
IMPORT_EPO_ASSETS = 'import_epo_assets' | ||
SYNC_AZURE_ASSETS = 'sync_azure_assets' | ||
SYNC_AZURE_ASSETS_WITH_TAGS = 'sync_azure_assets_with_tags' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.
…apid7/nexpose-client into feature/hwilson/new-header-migrate-eso
def self.build_publish_vulnerabilities_option(name:, discovery_conn_id:) | ||
step1 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::NEW_ASSET_VULN) | ||
step2 = Step.new(service_name: ServiceNames::DXL, type_name: StepNames::PUBLISH_VULN_INT_TYPE, previous_type_name: step1.type_name) | ||
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) | ||
step2 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::VULN_DETAILS, previous_type_name: step1.type_name) | ||
step3 = Step.new(service_name: ServiceNames::DXL, type_name: StepNames::VULN_DETAILS_REQUEST, previous_type_name: step2.type_name) | ||
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
|
||
def self.build_find_vuln_details_option(name:, discovery_conn_id:) | ||
step1 = Step.new(service_name: ServiceNames::DXL, type_name: StepNames::VULN_DETAILS_REQUEST) | ||
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
def self.build_export_risk_scores_option(name:, discovery_conn_id:) | ||
step1 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::RISK_SCORE_UPDATED) | ||
step2 = Step.new(service_name: ServiceNames::EPO, type_name: StepNames::PUSH_RISK_SCORE, previous_type_name: step1.type_name) | ||
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.add_property(StepConfiguration::ConfigParamProperties::ONLY_IMPORT_THESE_TAGS, tags) | ||
step2 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::SYNC_EXTERNAL, previous_type_name: step1.type_name) | ||
|
||
#This isn't always known immediately, which is why we have IntegrationOption.site_id= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) | ||
step2 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::SYNC_EXTERNAL, previous_type_name: step1.type_name) | ||
|
||
#This isn't always known immediately, which is why we have IntegrationOption.site_id= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
|
||
def self.build_sync_aws_assets_option(name:, discovery_conn_id:, site_id: nil) | ||
step1 = Step.new(service_name: ServiceNames::AWS, type_name: StepNames::DISCOVER_AWS_ASSETS) | ||
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) | ||
step2 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::IMPORT_EXTERNAL, previous_type_name: step1.type_name) | ||
|
||
#This isn't always known immediately, which is why we have IntegrationOption.site_id= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
|
||
def self.build_import_ad_assets_option(name:, discovery_conn_id:, site_id: nil) | ||
step1 = Step.new(service_name: ServiceNames::ACTIVE_DIRECTORY, type_name: StepNames::DISCOVER_ACTIVE_DIRECTORY) | ||
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.add_property(StepConfiguration::ConfigParamProperties::DISCOVERY_CONFIG_ID, discovery_conn_id) | ||
step2 = Step.new(service_name: ServiceNames::NEXPOSE, type_name: StepNames::IMPORT_EXTERNAL, previous_type_name: step1.type_name) | ||
|
||
#This isn't always known immediately, which is why we have IntegrationOption.site_id= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
} | ||
when *ConfigParamPropertyTypes::STRING | ||
{ | ||
valueClass: Values::STRING, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
valueClass: Values::INTEGER, | ||
value: value | ||
} | ||
when *ConfigParamPropertyTypes::STRING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent when as deep as case.
STOPPED = 'stopped' | ||
|
||
# Workflow or an integration option has experienced an error that caused it to stop | ||
ERROR = 'error' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/MutableConstant: Freeze mutable objects assigned to constants.
RETRY = 'retry' | ||
|
||
# Workflow or an integration option is stopped by the user | ||
STOPPED = 'stopped' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/MutableConstant: Freeze mutable objects assigned to constants.
RUNNING = 'running' | ||
|
||
# The workflow or an integration option is running, but is temporarily unsuccessful processing events | ||
RETRY = 'retry' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/MutableConstant: Freeze mutable objects assigned to constants.
READY = 'ready' | ||
|
||
# Workflow or an integration option is processing or has processed events | ||
RUNNING = 'running' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/MutableConstant: Freeze mutable objects assigned to constants.
# Representation of state of a workflow or integration option. Taken from service-orchestration State.java | ||
module State | ||
# Workflow or an integration option is configured and ready to accept events | ||
READY = 'ready' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/MutableConstant: Freeze mutable objects assigned to constants.
|
||
def to_h | ||
hash = { | ||
:typeName => @typeName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
} | ||
else | ||
raise ArgumentError, "Invalid StepConfiguration ConfigurationParameter Property name: #{name}. " + | ||
'Should be one of StepConfiguration::ConfigParamProperties' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/MultilineOperationIndentation: Align the operands of an expression in an assignment spanning multiple lines.
value: value | ||
} | ||
else | ||
raise ArgumentError, "Invalid StepConfiguration ConfigurationParameter Property name: #{name}. " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.
} | ||
when *ConfigParamPropertyTypes::STRING | ||
{ | ||
valueClass: Values::STRING, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
valueClass: Values::INTEGER, | ||
value: value | ||
} | ||
when *ConfigParamPropertyTypes::STRING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/CaseIndentation: Indent when as deep as case.
…apid7/nexpose-client into feature/hwilson/new-header-migrate-eso
@@ -88,7 +88,14 @@ def to_hash | |||
prop = @property.to_sym | |||
hash = {prop => {}} | |||
hash[prop]['valueClass'] = @value_class | |||
hash[prop]['value'] = @value | |||
if @value_class == Eso::Values::ARRAY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part that was broken when Nexpose cukes tried to use it.
rv = {} | ||
self.properties.each_pair do |key, value| | ||
if value[:properties] | ||
rv[key] = value if value[:properties].has_key?(:operators) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/PreferredHashMethods: Use Hash#key? instead of Hash#has_key?.
def initialize(uuid: nil, service_name:, workflow: nil, type_name:, previous_type_name: StepNames::EMPTY, configuration_params: nil) | ||
@uuid = uuid if uuid | ||
@serviceName = service_name | ||
@stepConfiguration = StepConfiguration.new(type_name, previous_type_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming/VariableName: Use snake_case for variable names.
# | ||
def initialize(uuid: nil, service_name:, workflow: nil, type_name:, previous_type_name: StepNames::EMPTY, configuration_params: nil) | ||
@uuid = uuid if uuid | ||
@serviceName = service_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming/VariableName: Use snake_case for variable names.
@@ -0,0 +1,166 @@ | |||
module Eso |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
} | ||
when *ConfigParamPropertyTypes::INTEGER | ||
{ | ||
valueClass: Values::INTEGER, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
valueClass: Values::BOOLEAN, | ||
value: value | ||
} | ||
when *ConfigParamPropertyTypes::INTEGER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/CaseIndentation: Indent when as deep as case.
case name | ||
when *ConfigParamPropertyTypes::BOOLEAN | ||
{ | ||
valueClass: Values::BOOLEAN, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
def add_property(name, value) | ||
@configurationParams[:properties][name] = | ||
case name | ||
when *ConfigParamPropertyTypes::BOOLEAN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/CaseIndentation: Indent when as deep as case.
# @return [StepConfiguration] Returns this object for chaining. | ||
def add_property(name, value) | ||
@configurationParams[:properties][name] = | ||
case name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentAssignment: Indent the first line of the right-hand-side of a multi-line assignment.
...and continue to feel the pain of creating more build_* methods when I really want to refactor this whole thing
PLEASE DO NOT NITPICK THIS CODE. ITS A COPY/PASTE AND NOT NEW DEVELOPMENT
Description
This is literally a copy/paste of the eso-client gem into nexpose-client. Is it beautiful? No. I wanted to refactor a bunch of things here before we did this. But I don't know when I will have the excuse to be in this code base in the near future.
Motivation and Context
When this is merged, users will be able to do the following:
How Has This Been Tested?
I haven't tested it yet. I ran one test locally and it worked. I want a pipeline to run. Actually I want several to run. So don't merge it.
Types of changes
Checklist:
Need issues for the following, as I won't be able to do them as part of this PR: