Class: RuboCop::Cop::Gemspec::RequireMFA
- Extended by:
- AutoCorrector
- Includes:
- RuboCop::Cop::GemspecHelp
- Defined in:
- lib/rubocop/cop/gemspec/require_mfa.rb
Overview
Requires a gemspec to have ‘rubygems_mfa_required` metadata set.
This setting tells RubyGems that MFA (Multi-Factor Authentication) is required for accounts to be able perform privileged operations, such as (see RubyGems’ documentation for the full list of privileged operations):
-
‘gem push`
-
‘gem yank`
-
‘gem owner –add/remove`
-
adding or removing owners using gem ownership page
This helps make your gem more secure, as users can be more confident that gem updates were pushed by maintainers.
# bad
Gem::Specification.new do |spec|
spec. = {
'rubygems_mfa_required' => 'false'
}
end
# good
Gem::Specification.new do |spec|
spec. = {
'rubygems_mfa_required' => 'true'
}
end
# bad
Gem::Specification.new do |spec|
spec.['rubygems_mfa_required'] = 'false'
end
# good
Gem::Specification.new do |spec|
spec.['rubygems_mfa_required'] = 'true'
end
Constant Summary collapse
- MSG =
"`metadata['rubygems_mfa_required']` must be set to `'true'`."
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #metadata(node) ⇒ Object
-
#on_block(node) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #rubygems_mfa_required(node) ⇒ Object
- #true_string?(node) ⇒ Object
Methods included from AutoCorrector
Methods included from RuboCop::Cop::GemspecHelp
#gem_specification, #gem_specification?
Methods inherited from Base
#add_global_offense, #add_offense, autocorrect_incompatible_with, badge, callbacks_needed, #callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #cop_config, #cop_name, cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_new_investigation, #on_other_file, #parse, #ready, #relevant_file?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#metadata(node) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/rubocop/cop/gemspec/require_mfa.rb', line 70 def_node_matcher :metadata, "`{\n (send _ :metadata= $_)\n (send (send _ :metadata) :[]= (str \"rubygems_mfa_required\") $_)\n}\n" |
#on_block(node) ⇒ Object
rubocop:disable Metrics/MethodLength
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rubocop/cop/gemspec/require_mfa.rb', line 87 def on_block(node) # rubocop:disable Metrics/MethodLength gem_specification(node) do |block_var| = (node) mfa_value = mfa_value() if mfa_value unless true_string?(mfa_value) add_offense(mfa_value) do |corrector| change_value(corrector, mfa_value) end end else add_offense(node) do |corrector| autocorrect(corrector, node, block_var, ) end end end end |
#rubygems_mfa_required(node) ⇒ Object
78 79 80 |
# File 'lib/rubocop/cop/gemspec/require_mfa.rb', line 78 def_node_search :rubygems_mfa_required, "(pair (str \"rubygems_mfa_required\") $_)\n" |
#true_string?(node) ⇒ Object
83 84 85 |
# File 'lib/rubocop/cop/gemspec/require_mfa.rb', line 83 def_node_matcher :true_string?, "(str \"true\")\n" |