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

[capistrano] Add ability to use etc.getpwuid instead of etc.getlogin to get the user name #146

Merged
merged 4 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-01-13 15:42:46 -0500 using RuboCop version 0.49.1.
# on 2020-01-30 14:50:03 +0100 using RuboCop version 0.49.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -42,14 +42,17 @@ Layout/EmptyLineAfterMagicComment:
Exclude:
- 'dogapi.gemspec'

# Offense count: 2
# Offense count: 16
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'config/deploy.rb'
- 'config/deploy/production.rb'
- 'config/deploy/staging.rb'
- 'lib/capistrano/datadog/v2.rb'
- 'lib/dogapi/facade.rb'

# Offense count: 89
# Offense count: 92
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Expand Down Expand Up @@ -129,7 +132,6 @@ Layout/SpaceAroundEqualsInParameterDefault:
- 'lib/dogapi/common.rb'
- 'lib/dogapi/event.rb'
- 'lib/dogapi/facade.rb'
- 'lib/dogapi/v1/dash.rb'
- 'lib/dogapi/v1/embed.rb'
- 'lib/dogapi/v1/event.rb'
- 'lib/dogapi/v1/metric.rb'
Expand Down Expand Up @@ -201,9 +203,9 @@ Lint/UselessAssignment:

# Offense count: 12
Metrics/AbcSize:
Max: 51
Max: 53

# Offense count: 28
# Offense count: 29
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 123
Expand All @@ -215,23 +217,23 @@ Metrics/ClassLength:

# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 8
Max: 9

# Offense count: 16
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 34

# Offense count: 5
# Offense count: 7
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 7

# Offense count: 2
Metrics/PerceivedComplexity:
Max: 9
Max: 10

# Offense count: 13
# Offense count: 19
Style/AccessorMethodName:
Exclude:
- 'lib/dogapi/facade.rb'
Expand All @@ -240,8 +242,8 @@ Style/AccessorMethodName:
- 'lib/dogapi/v1/dashboard.rb'
- 'lib/dogapi/v1/embed.rb'
- 'lib/dogapi/v1/screenboard.rb'
- 'lib/dogapi/v1/user.rb'
- 'lib/dogapi/v1/synthetics.rb'
- 'lib/dogapi/v1/user.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand Down Expand Up @@ -279,7 +281,7 @@ Style/ClassCheck:
- 'lib/dogapi/facade.rb'
- 'lib/dogapi/v1/event.rb'

# Offense count: 2
# Offense count: 3
# Cop supports --auto-correct.
Style/ClassMethods:
Exclude:
Expand All @@ -297,14 +299,6 @@ Style/ColonMethodCall:
- 'lib/capistrano/datadog.rb'
- 'lib/capistrano/datadog/v2.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerBackticks.
# SupportedStyles: backticks, percent_x, mixed
Style/CommandLiteral:
Exclude:
- 'lib/dogapi/common.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
Expand All @@ -313,7 +307,7 @@ Style/ConditionalAssignment:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 21
# Offense count: 20
# Cop supports --auto-correct.
Style/DefWithParentheses:
Exclude:
Expand All @@ -340,7 +334,7 @@ Style/GuardClause:
- 'lib/capistrano/datadog.rb'
- 'lib/dogapi/facade.rb'

# Offense count: 86
# Offense count: 88
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Expand All @@ -361,7 +355,7 @@ Style/HashSyntax:
- 'lib/dogapi/v1/snapshot.rb'
- 'lib/dogapi/v1/tag.rb'

# Offense count: 15
# Offense count: 16
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Expand All @@ -381,7 +375,7 @@ Style/LineEndConcatenation:
Exclude:
- 'dogapi.gemspec'

# Offense count: 18
# Offense count: 21
# Cop supports --auto-correct.
Style/MethodCallWithoutArgsParentheses:
Exclude:
Expand All @@ -396,7 +390,7 @@ Style/MultilineIfThen:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 33
# Offense count: 37
# Cop supports --auto-correct.
Style/MutableConstant:
Enabled: false
Expand All @@ -416,12 +410,11 @@ Style/Not:
Exclude:
- 'lib/dogapi/v1/metric.rb'

# Offense count: 4
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'lib/dogapi/common.rb'
- 'spec/integration/event_spec.rb'
- 'spec/integration/monitor_spec.rb'

Expand Down Expand Up @@ -477,14 +470,17 @@ Style/SpecialGlobalVars:
Exclude:
- 'dogapi.gemspec'

# Offense count: 25
# Offense count: 35
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'Capfile'
- 'Gemfile'
- 'Rakefile'
- 'config/deploy.rb'
- 'config/deploy/staging.rb'
- 'dogapi.gemspec'
- 'examples/Capfile'
- 'examples/custom_event.rb'
Expand Down
8 changes: 4 additions & 4 deletions lib/capistrano/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def self.cap_version()
@cap_version
end

def self.submit(api_key)
def self.submit(api_key, use_getlogin=true)
begin
if api_key
dog = Dogapi::Client.new(api_key)
reporter.report.each do |event, hosts|
reporter.report(use_getlogin).each do |event, hosts|
if hosts.size > 0
hosts.each do |host|
dog.emit_event event, host: host
Expand Down Expand Up @@ -93,9 +93,9 @@ def record_hostname(hostname)
end
end

def report()
def report(use_getlogin=true)
hostname = Dogapi.find_localhost
user = Etc.getlogin
user = use_getlogin ? Etc.getlogin : Etc.getpwuid.name

# Lazy randomness
aggregation_key = Digest::MD5.hexdigest "#{Time.new}|#{rand}"
Expand Down
6 changes: 5 additions & 1 deletion lib/capistrano/datadog/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def puts(message)
namespace :datadog do
desc 'Submit the tasks that have run to Datadog as events'
task :submit do |ns|
Capistrano::Datadog.submit variables[:datadog_api_key]
if variables[:use_getlogin].nil?
Capistrano::Datadog.submit variables[:datadog_api_key]
else
Capistrano::Datadog.submit variables[:datadog_api_key], variables[:use_getlogin]
end
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/capistrano/datadog/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,10 @@ def initialize(oio)

at_exit do
api_key = Capistrano::Configuration.env.fetch :datadog_api_key
Capistrano::Datadog.submit api_key
use_getlogin = Capistrano::Configuration.env.fetch :use_getlogin
if use_getlogin.nil?
Capistrano::Datadog.submit api_key
else
Capistrano::Datadog.submit api_key, use_getlogin
end
end