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

Adds the ability to send to a different account id's queue. #30

Closed
wants to merge 4 commits into from

Conversation

matthoey-okta
Copy link
Contributor

I'm in no way, shape, or form a coder. I did my best to add a test but
failed to get the tests to run. Please feel free to fix any mistakes I
might have made. Looking forward to any feedback/help to get this
through.

Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/

I'm in no way, shape, or form a coder. I did my best to add a test but
failed to get the tests to run. Please feel free to fix any mistakes I
might have made. Looking forward to any feedback/help to get this
through.
@robbavey robbavey self-assigned this May 29, 2018
Copy link
Contributor

@robbavey robbavey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution - just a couple of minor suggestions, but nothing major

* There is no default value for this setting.

The owning account id of the target SQS queue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth adding a note that the queue owner must grant permissions to access this queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was a good call because I discovered both accounts need to grant permissions for this to work and that's not immediately obvious if you aren't familiar with cross account IAM permissions.

@logger.debug('Connecting to SQS queue', :queue => @queue, :region => region)
@queue_url = @sqs.get_queue_url(:queue_name => @queue)[:queue_url]
@logger.info('Connected to SQS queue successfully', :queue => @queue, :region => region)
@logger.debug('Connecting to SQS queue', :queue => @queue, :region => region, :queue_owner_aws_account_id => @queue_owner_aws_account_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice if the queue_owner_aws_account_id property only shows up if it has been explicitly set - otherwise this shows up in the logs as queue_owner_aws_account_id => nil

Copy link

@NaomiAmethyst NaomiAmethyst May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that would require either moving the logging inside the if statement:

if @queue_owner_aws_account_id
  @logger.debug('Connecting to cross-account SQS queue', :queue => @queue, :region => region, :queue_owner_aws_account_id => @queue_owner_aws_account_id)
  @queue_url = @sqs.get_queue_url(:queue_name => @queue, :queue_owner_aws_account_id => @queue_owner_aws_account_id)[:queue_url]
  @logger.info('Connected to cross-account SQS queue successfully', :queue => @queue, :region => region, :queue_owner_aws_account_id => @queue_owner_aws_account_id)
else
  @logger.debug('Connecting to SQS queue', :queue => @queue, :region => region)
  @queue_url = @sqs.get_queue_url(:queue_name => @queue)[:queue_url]
  @logger.info('Connected to SQS queue successfully', :queue => @queue, :region => region)
end

which seems a bit duplicative.

Or perhaps some form of hash manipulation:

queue_merger = @queue_owner_aws_account_id ? {:queue_owner_aws_account_id => @queue_owner_aws_account_id} : {}
@logger.debug('Connecting to SQS queue', {:queue => @queue, :region => region}.merge(queue_merger))
@queue_url = @sqs.get_queue_url({:queue_name => @queue}.merge(queue_merger))[:queue_url]
@logger.info('Connected to SQS queue successfully', {:queue => @queue, :region => region}.merge(queue_merger))

which is convoluted and messy.

Maybe a hybrid approach?

logger_params = { :queue => @queue, :region => region }
logger_params[:queue_owner_aws_account_id] = @queue_owner_aws_account_id if @queue_owner_aws_account_id
@logger.debug('Connecting to SQS queue', logger_params)
@queue_url = if @queue_owner_aws_account_id
  @sqs.get_queue_url(:queue_name => @queue, :queue_owner_aws_account_id => @queue_owner_aws_account_id)[:queue_url]
else
  @sqs.get_queue_url(:queue_name => @queue)[:queue_url]
end
@logger.info('Connected to SQS queue successfully', logger_params)

Any which way you slice it, it seems unnecessarily messy in the code for the value added in the logs.

Copy link

@chrissivanich-okta chrissivanich-okta May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since :region isn't passed to sqs.get_queue_url couldn't @Cobi 's hybrid approach be used, but with passing the prepared hash into all called methods?

params = { queue: @queue }
params[:queue_owner_aws_account_id] = @queue_owner_aws_account_id if @queue_owner_aws_account_id
@logger.debug('Connecting to SQS queue', params)
@queue_url = @sqs.get_queue_url(params)
@logger.info('Connected to SQS queue successfully', params)

@logger.debug('Connecting to SQS queue', :queue => @queue, :region => region)
@queue_url = @sqs.get_queue_url(:queue_name => @queue)[:queue_url]
@logger.info('Connected to SQS queue successfully', :queue => @queue, :region => region)
params = { queue_name: @queue }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this closely resembles Chris' suggestion, but I felt it was a good balance of simplicity and fulfilling requirements. Note I did change the logging message to match the exact AWS attribute "queue_name" over the previously used "queue".

@robbavey
Copy link
Contributor

robbavey commented Jun 4, 2018

@matthoey-okta Looks good to me! I will merge these changes shortly - thanks for the contribution

@elasticsearch-bot
Copy link

Rob Bavey merged this into the following branches!

Branch Commits
master f5db4c4, 984690b, 45b71ae, fc6e648

elasticsearch-bot pushed a commit that referenced this pull request Jun 4, 2018
Fixes #30
elasticsearch-bot pushed a commit that referenced this pull request Jun 4, 2018
elasticsearch-bot pushed a commit that referenced this pull request Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants