id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
11,400
castwide/solargraph
lib/solargraph/source.rb
Solargraph.Source.location
def location st = Position.new(0, 0) en = Position.from_offset(code, code.length) range = Range.new(st, en) Location.new(filename, range) end
ruby
def location st = Position.new(0, 0) en = Position.from_offset(code, code.length) range = Range.new(st, en) Location.new(filename, range) end
[ "def", "location", "st", "=", "Position", ".", "new", "(", "0", ",", "0", ")", "en", "=", "Position", ".", "from_offset", "(", "code", ",", "code", ".", "length", ")", "range", "=", "Range", ".", "new", "(", "st", ",", "en", ")", "Location", ".", "new", "(", "filename", ",", "range", ")", "end" ]
A location representing the file in its entirety. @return [Location]
[ "A", "location", "representing", "the", "file", "in", "its", "entirety", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/source.rb#L255-L260
11,401
castwide/solargraph
lib/solargraph/source.rb
Solargraph.Source.associated_comments
def associated_comments @associated_comments ||= begin result = {} Parser::Source::Comment.associate_locations(node, comments).each_pair do |loc, all| block = all #.select{ |l| l.document? || code.lines[l.loc.line].strip.start_with?('#')} next if block.empty? result[loc.line] ||= [] result[loc.line].concat block end result end end
ruby
def associated_comments @associated_comments ||= begin result = {} Parser::Source::Comment.associate_locations(node, comments).each_pair do |loc, all| block = all #.select{ |l| l.document? || code.lines[l.loc.line].strip.start_with?('#')} next if block.empty? result[loc.line] ||= [] result[loc.line].concat block end result end end
[ "def", "associated_comments", "@associated_comments", "||=", "begin", "result", "=", "{", "}", "Parser", "::", "Source", "::", "Comment", ".", "associate_locations", "(", "node", ",", "comments", ")", ".", "each_pair", "do", "|", "loc", ",", "all", "|", "block", "=", "all", "#.select{ |l| l.document? || code.lines[l.loc.line].strip.start_with?('#')}", "next", "if", "block", ".", "empty?", "result", "[", "loc", ".", "line", "]", "||=", "[", "]", "result", "[", "loc", ".", "line", "]", ".", "concat", "block", "end", "result", "end", "end" ]
Get a hash of comments grouped by the line numbers of the associated code. @return [Hash{Integer => Array<Parser::Source::Comment>}]
[ "Get", "a", "hash", "of", "comments", "grouped", "by", "the", "line", "numbers", "of", "the", "associated", "code", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/source.rb#L289-L300
11,402
castwide/solargraph
lib/solargraph/source.rb
Solargraph.Source.stringify_comment_array
def stringify_comment_array comments ctxt = '' num = nil started = false last_line = nil comments.each { |l| # Trim the comment and minimum leading whitespace p = l.text.gsub(/^#+/, '') if num.nil? and !p.strip.empty? num = p.index(/[^ ]/) started = true elsif started and !p.strip.empty? cur = p.index(/[^ ]/) num = cur if cur < num end # Include blank lines between comments ctxt += ("\n" * (l.loc.first_line - last_line - 1)) unless last_line.nil? || l.loc.first_line - last_line <= 0 ctxt += "#{p[num..-1]}\n" if started last_line = l.loc.last_line if last_line.nil? || l.loc.last_line > last_line } ctxt end
ruby
def stringify_comment_array comments ctxt = '' num = nil started = false last_line = nil comments.each { |l| # Trim the comment and minimum leading whitespace p = l.text.gsub(/^#+/, '') if num.nil? and !p.strip.empty? num = p.index(/[^ ]/) started = true elsif started and !p.strip.empty? cur = p.index(/[^ ]/) num = cur if cur < num end # Include blank lines between comments ctxt += ("\n" * (l.loc.first_line - last_line - 1)) unless last_line.nil? || l.loc.first_line - last_line <= 0 ctxt += "#{p[num..-1]}\n" if started last_line = l.loc.last_line if last_line.nil? || l.loc.last_line > last_line } ctxt end
[ "def", "stringify_comment_array", "comments", "ctxt", "=", "''", "num", "=", "nil", "started", "=", "false", "last_line", "=", "nil", "comments", ".", "each", "{", "|", "l", "|", "# Trim the comment and minimum leading whitespace", "p", "=", "l", ".", "text", ".", "gsub", "(", "/", "/", ",", "''", ")", "if", "num", ".", "nil?", "and", "!", "p", ".", "strip", ".", "empty?", "num", "=", "p", ".", "index", "(", "/", "/", ")", "started", "=", "true", "elsif", "started", "and", "!", "p", ".", "strip", ".", "empty?", "cur", "=", "p", ".", "index", "(", "/", "/", ")", "num", "=", "cur", "if", "cur", "<", "num", "end", "# Include blank lines between comments", "ctxt", "+=", "(", "\"\\n\"", "*", "(", "l", ".", "loc", ".", "first_line", "-", "last_line", "-", "1", ")", ")", "unless", "last_line", ".", "nil?", "||", "l", ".", "loc", ".", "first_line", "-", "last_line", "<=", "0", "ctxt", "+=", "\"#{p[num..-1]}\\n\"", "if", "started", "last_line", "=", "l", ".", "loc", ".", "last_line", "if", "last_line", ".", "nil?", "||", "l", ".", "loc", ".", "last_line", ">", "last_line", "}", "ctxt", "end" ]
Get a string representation of an array of comments. @param comments [Array<Parser::Source::Comment>] @return [String]
[ "Get", "a", "string", "representation", "of", "an", "array", "of", "comments", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/source.rb#L324-L345
11,403
castwide/solargraph
lib/solargraph/source.rb
Solargraph.Source.foldable_comment_block_ranges
def foldable_comment_block_ranges return [] unless synchronized? result = [] grouped = [] # @param cmnt [Parser::Source::Comment] @comments.each do |cmnt| if cmnt.document? result.push Range.from_expr(cmnt.loc.expression) elsif code.lines[cmnt.loc.expression.line].strip.start_with?('#') if grouped.empty? || cmnt.loc.expression.line == grouped.last.loc.expression.line + 1 grouped.push cmnt else result.push Range.from_to(grouped.first.loc.expression.line, 0, grouped.last.loc.expression.line, 0) unless grouped.length < 3 grouped = [cmnt] end else unless grouped.length < 3 result.push Range.from_to(grouped.first.loc.expression.line, 0, grouped.last.loc.expression.line, 0) end grouped.clear end end result.push Range.from_to(grouped.first.loc.expression.line, 0, grouped.last.loc.expression.line, 0) unless grouped.length < 3 result end
ruby
def foldable_comment_block_ranges return [] unless synchronized? result = [] grouped = [] # @param cmnt [Parser::Source::Comment] @comments.each do |cmnt| if cmnt.document? result.push Range.from_expr(cmnt.loc.expression) elsif code.lines[cmnt.loc.expression.line].strip.start_with?('#') if grouped.empty? || cmnt.loc.expression.line == grouped.last.loc.expression.line + 1 grouped.push cmnt else result.push Range.from_to(grouped.first.loc.expression.line, 0, grouped.last.loc.expression.line, 0) unless grouped.length < 3 grouped = [cmnt] end else unless grouped.length < 3 result.push Range.from_to(grouped.first.loc.expression.line, 0, grouped.last.loc.expression.line, 0) end grouped.clear end end result.push Range.from_to(grouped.first.loc.expression.line, 0, grouped.last.loc.expression.line, 0) unless grouped.length < 3 result end
[ "def", "foldable_comment_block_ranges", "return", "[", "]", "unless", "synchronized?", "result", "=", "[", "]", "grouped", "=", "[", "]", "# @param cmnt [Parser::Source::Comment]", "@comments", ".", "each", "do", "|", "cmnt", "|", "if", "cmnt", ".", "document?", "result", ".", "push", "Range", ".", "from_expr", "(", "cmnt", ".", "loc", ".", "expression", ")", "elsif", "code", ".", "lines", "[", "cmnt", ".", "loc", ".", "expression", ".", "line", "]", ".", "strip", ".", "start_with?", "(", "'#'", ")", "if", "grouped", ".", "empty?", "||", "cmnt", ".", "loc", ".", "expression", ".", "line", "==", "grouped", ".", "last", ".", "loc", ".", "expression", ".", "line", "+", "1", "grouped", ".", "push", "cmnt", "else", "result", ".", "push", "Range", ".", "from_to", "(", "grouped", ".", "first", ".", "loc", ".", "expression", ".", "line", ",", "0", ",", "grouped", ".", "last", ".", "loc", ".", "expression", ".", "line", ",", "0", ")", "unless", "grouped", ".", "length", "<", "3", "grouped", "=", "[", "cmnt", "]", "end", "else", "unless", "grouped", ".", "length", "<", "3", "result", ".", "push", "Range", ".", "from_to", "(", "grouped", ".", "first", ".", "loc", ".", "expression", ".", "line", ",", "0", ",", "grouped", ".", "last", ".", "loc", ".", "expression", ".", "line", ",", "0", ")", "end", "grouped", ".", "clear", "end", "end", "result", ".", "push", "Range", ".", "from_to", "(", "grouped", ".", "first", ".", "loc", ".", "expression", ".", "line", ",", "0", ",", "grouped", ".", "last", ".", "loc", ".", "expression", ".", "line", ",", "0", ")", "unless", "grouped", ".", "length", "<", "3", "result", "end" ]
Get an array of foldable comment block ranges. Blocks are excluded if they are less than 3 lines long. @return [Array<Range>]
[ "Get", "an", "array", "of", "foldable", "comment", "block", "ranges", ".", "Blocks", "are", "excluded", "if", "they", "are", "less", "than", "3", "lines", "long", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/source.rb#L370-L394
11,404
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.merge
def merge source unless directory == '*' || source_hash.key?(source.filename) # Reload the config to determine if a new source should be included @config = Solargraph::Workspace::Config.new(directory) return false unless config.calculated.include?(source.filename) end source_hash[source.filename] = source true end
ruby
def merge source unless directory == '*' || source_hash.key?(source.filename) # Reload the config to determine if a new source should be included @config = Solargraph::Workspace::Config.new(directory) return false unless config.calculated.include?(source.filename) end source_hash[source.filename] = source true end
[ "def", "merge", "source", "unless", "directory", "==", "'*'", "||", "source_hash", ".", "key?", "(", "source", ".", "filename", ")", "# Reload the config to determine if a new source should be included", "@config", "=", "Solargraph", "::", "Workspace", "::", "Config", ".", "new", "(", "directory", ")", "return", "false", "unless", "config", ".", "calculated", ".", "include?", "(", "source", ".", "filename", ")", "end", "source_hash", "[", "source", ".", "filename", "]", "=", "source", "true", "end" ]
Merge the source. A merge will update the existing source for the file or add it to the sources if the workspace is configured to include it. The source is ignored if the configuration excludes it. @param source [Solargraph::Source] @return [Boolean] True if the source was added to the workspace
[ "Merge", "the", "source", ".", "A", "merge", "will", "update", "the", "existing", "source", "for", "the", "file", "or", "add", "it", "to", "the", "sources", "if", "the", "workspace", "is", "configured", "to", "include", "it", ".", "The", "source", "is", "ignored", "if", "the", "configuration", "excludes", "it", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L31-L39
11,405
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.would_merge?
def would_merge? filename return true if directory == '*' || source_hash.include?(filename) @config = Solargraph::Workspace::Config.new(directory) config.calculated.include?(filename) end
ruby
def would_merge? filename return true if directory == '*' || source_hash.include?(filename) @config = Solargraph::Workspace::Config.new(directory) config.calculated.include?(filename) end
[ "def", "would_merge?", "filename", "return", "true", "if", "directory", "==", "'*'", "||", "source_hash", ".", "include?", "(", "filename", ")", "@config", "=", "Solargraph", "::", "Workspace", "::", "Config", ".", "new", "(", "directory", ")", "config", ".", "calculated", ".", "include?", "(", "filename", ")", "end" ]
Determine whether a file would be merged into the workspace. @param filename [String] @return [Boolean]
[ "Determine", "whether", "a", "file", "would", "be", "merged", "into", "the", "workspace", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L45-L49
11,406
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.remove
def remove filename return false unless source_hash.key?(filename) source_hash.delete filename true end
ruby
def remove filename return false unless source_hash.key?(filename) source_hash.delete filename true end
[ "def", "remove", "filename", "return", "false", "unless", "source_hash", ".", "key?", "(", "filename", ")", "source_hash", ".", "delete", "filename", "true", "end" ]
Remove a source from the workspace. The source will not be removed if its file exists and the workspace is configured to include it. @param filename [String] @return [Boolean] True if the source was removed from the workspace
[ "Remove", "a", "source", "from", "the", "workspace", ".", "The", "source", "will", "not", "be", "removed", "if", "its", "file", "exists", "and", "the", "workspace", "is", "configured", "to", "include", "it", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L56-L60
11,407
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.would_require?
def would_require? path require_paths.each do |rp| return true if File.exist?(File.join(rp, "#{path}.rb")) end false end
ruby
def would_require? path require_paths.each do |rp| return true if File.exist?(File.join(rp, "#{path}.rb")) end false end
[ "def", "would_require?", "path", "require_paths", ".", "each", "do", "|", "rp", "|", "return", "true", "if", "File", ".", "exist?", "(", "File", ".", "join", "(", "rp", ",", "\"#{path}.rb\"", ")", ")", "end", "false", "end" ]
True if the path resolves to a file in the workspace's require paths. @param path [String] @return [Boolean]
[ "True", "if", "the", "path", "resolves", "to", "a", "file", "in", "the", "workspace", "s", "require", "paths", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L97-L102
11,408
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.synchronize!
def synchronize! updater source_hash[updater.filename] = source_hash[updater.filename].synchronize(updater) end
ruby
def synchronize! updater source_hash[updater.filename] = source_hash[updater.filename].synchronize(updater) end
[ "def", "synchronize!", "updater", "source_hash", "[", "updater", ".", "filename", "]", "=", "source_hash", "[", "updater", ".", "filename", "]", ".", "synchronize", "(", "updater", ")", "end" ]
Synchronize the workspace from the provided updater. @param updater [Source::Updater] @return [void]
[ "Synchronize", "the", "workspace", "from", "the", "provided", "updater", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L123-L125
11,409
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.generate_require_paths
def generate_require_paths return configured_require_paths unless gemspec? result = [] gemspecs.each do |file| base = File.dirname(file) # @todo Evaluating gemspec files violates the goal of not running # workspace code, but this is how Gem::Specification.load does it # anyway. begin spec = eval(File.read(file), binding, file) next unless Gem::Specification === spec result.concat(spec.require_paths.map { |path| File.join(base, path) }) rescue Exception => e # Don't die if we have an error during eval-ing a gem spec. # Concat the default lib directory instead. Solargraph.logger.warn "Error reading #{file}: [#{e.class}] #{e.message}" result.push File.join(base, 'lib') end end result.concat config.require_paths result.push File.join(directory, 'lib') if result.empty? result end
ruby
def generate_require_paths return configured_require_paths unless gemspec? result = [] gemspecs.each do |file| base = File.dirname(file) # @todo Evaluating gemspec files violates the goal of not running # workspace code, but this is how Gem::Specification.load does it # anyway. begin spec = eval(File.read(file), binding, file) next unless Gem::Specification === spec result.concat(spec.require_paths.map { |path| File.join(base, path) }) rescue Exception => e # Don't die if we have an error during eval-ing a gem spec. # Concat the default lib directory instead. Solargraph.logger.warn "Error reading #{file}: [#{e.class}] #{e.message}" result.push File.join(base, 'lib') end end result.concat config.require_paths result.push File.join(directory, 'lib') if result.empty? result end
[ "def", "generate_require_paths", "return", "configured_require_paths", "unless", "gemspec?", "result", "=", "[", "]", "gemspecs", ".", "each", "do", "|", "file", "|", "base", "=", "File", ".", "dirname", "(", "file", ")", "# @todo Evaluating gemspec files violates the goal of not running", "# workspace code, but this is how Gem::Specification.load does it", "# anyway.", "begin", "spec", "=", "eval", "(", "File", ".", "read", "(", "file", ")", ",", "binding", ",", "file", ")", "next", "unless", "Gem", "::", "Specification", "===", "spec", "result", ".", "concat", "(", "spec", ".", "require_paths", ".", "map", "{", "|", "path", "|", "File", ".", "join", "(", "base", ",", "path", ")", "}", ")", "rescue", "Exception", "=>", "e", "# Don't die if we have an error during eval-ing a gem spec.", "# Concat the default lib directory instead.", "Solargraph", ".", "logger", ".", "warn", "\"Error reading #{file}: [#{e.class}] #{e.message}\"", "result", ".", "push", "File", ".", "join", "(", "base", ",", "'lib'", ")", "end", "end", "result", ".", "concat", "config", ".", "require_paths", "result", ".", "push", "File", ".", "join", "(", "directory", ",", "'lib'", ")", "if", "result", ".", "empty?", "result", "end" ]
Generate require paths from gemspecs if they exist or assume the default lib directory. @return [Array<String>]
[ "Generate", "require", "paths", "from", "gemspecs", "if", "they", "exist", "or", "assume", "the", "default", "lib", "directory", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L150-L172
11,410
castwide/solargraph
lib/solargraph/workspace.rb
Solargraph.Workspace.configured_require_paths
def configured_require_paths return ['lib'] if directory.empty? return [File.join(directory, 'lib')] if config.require_paths.empty? config.require_paths.map{|p| File.join(directory, p)} end
ruby
def configured_require_paths return ['lib'] if directory.empty? return [File.join(directory, 'lib')] if config.require_paths.empty? config.require_paths.map{|p| File.join(directory, p)} end
[ "def", "configured_require_paths", "return", "[", "'lib'", "]", "if", "directory", ".", "empty?", "return", "[", "File", ".", "join", "(", "directory", ",", "'lib'", ")", "]", "if", "config", ".", "require_paths", ".", "empty?", "config", ".", "require_paths", ".", "map", "{", "|", "p", "|", "File", ".", "join", "(", "directory", ",", "p", ")", "}", "end" ]
Get additional require paths defined in the configuration. @return [Array<String>]
[ "Get", "additional", "require", "paths", "defined", "in", "the", "configuration", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/workspace.rb#L177-L181
11,411
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.create
def create filename, text result = false mutex.synchronize do next unless contain?(filename) || open?(filename) || workspace.would_merge?(filename) @synchronized = false source = Solargraph::Source.load_string(text, filename) workspace.merge(source) result = true end result end
ruby
def create filename, text result = false mutex.synchronize do next unless contain?(filename) || open?(filename) || workspace.would_merge?(filename) @synchronized = false source = Solargraph::Source.load_string(text, filename) workspace.merge(source) result = true end result end
[ "def", "create", "filename", ",", "text", "result", "=", "false", "mutex", ".", "synchronize", "do", "next", "unless", "contain?", "(", "filename", ")", "||", "open?", "(", "filename", ")", "||", "workspace", ".", "would_merge?", "(", "filename", ")", "@synchronized", "=", "false", "source", "=", "Solargraph", "::", "Source", ".", "load_string", "(", "text", ",", "filename", ")", "workspace", ".", "merge", "(", "source", ")", "result", "=", "true", "end", "result", "end" ]
Create a source to be added to the workspace. The file is ignored if it is neither open in the library nor included in the workspace. @param filename [String] @param text [String] The contents of the file @return [Boolean] True if the file was added to the workspace.
[ "Create", "a", "source", "to", "be", "added", "to", "the", "workspace", ".", "The", "file", "is", "ignored", "if", "it", "is", "neither", "open", "in", "the", "library", "nor", "included", "in", "the", "workspace", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L94-L104
11,412
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.create_from_disk
def create_from_disk filename result = false mutex.synchronize do next if File.directory?(filename) || !File.exist?(filename) next unless contain?(filename) || open?(filename) || workspace.would_merge?(filename) @synchronized = false source = Solargraph::Source.load_string(File.read(filename), filename) workspace.merge(source) result = true end result end
ruby
def create_from_disk filename result = false mutex.synchronize do next if File.directory?(filename) || !File.exist?(filename) next unless contain?(filename) || open?(filename) || workspace.would_merge?(filename) @synchronized = false source = Solargraph::Source.load_string(File.read(filename), filename) workspace.merge(source) result = true end result end
[ "def", "create_from_disk", "filename", "result", "=", "false", "mutex", ".", "synchronize", "do", "next", "if", "File", ".", "directory?", "(", "filename", ")", "||", "!", "File", ".", "exist?", "(", "filename", ")", "next", "unless", "contain?", "(", "filename", ")", "||", "open?", "(", "filename", ")", "||", "workspace", ".", "would_merge?", "(", "filename", ")", "@synchronized", "=", "false", "source", "=", "Solargraph", "::", "Source", ".", "load_string", "(", "File", ".", "read", "(", "filename", ")", ",", "filename", ")", "workspace", ".", "merge", "(", "source", ")", "result", "=", "true", "end", "result", "end" ]
Create a file source from a file on disk. The file is ignored if it is neither open in the library nor included in the workspace. @param filename [String] @return [Boolean] True if the file was added to the workspace.
[ "Create", "a", "file", "source", "from", "a", "file", "on", "disk", ".", "The", "file", "is", "ignored", "if", "it", "is", "neither", "open", "in", "the", "library", "nor", "included", "in", "the", "workspace", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L111-L122
11,413
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.delete
def delete filename detach filename result = false mutex.synchronize do result = workspace.remove(filename) @synchronized = !result if synchronized? end result end
ruby
def delete filename detach filename result = false mutex.synchronize do result = workspace.remove(filename) @synchronized = !result if synchronized? end result end
[ "def", "delete", "filename", "detach", "filename", "result", "=", "false", "mutex", ".", "synchronize", "do", "result", "=", "workspace", ".", "remove", "(", "filename", ")", "@synchronized", "=", "!", "result", "if", "synchronized?", "end", "result", "end" ]
Delete a file from the library. Deleting a file will make it unavailable for checkout and optionally remove it from the workspace unless the workspace configuration determines that it should still exist. @param filename [String] @return [Boolean] True if the file was deleted
[ "Delete", "a", "file", "from", "the", "library", ".", "Deleting", "a", "file", "will", "make", "it", "unavailable", "for", "checkout", "and", "optionally", "remove", "it", "from", "the", "workspace", "unless", "the", "workspace", "configuration", "determines", "that", "it", "should", "still", "exist", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L130-L138
11,414
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.completions_at
def completions_at filename, line, column position = Position.new(line, column) cursor = Source::Cursor.new(checkout(filename), position) api_map.clip(cursor).complete end
ruby
def completions_at filename, line, column position = Position.new(line, column) cursor = Source::Cursor.new(checkout(filename), position) api_map.clip(cursor).complete end
[ "def", "completions_at", "filename", ",", "line", ",", "column", "position", "=", "Position", ".", "new", "(", "line", ",", "column", ")", "cursor", "=", "Source", "::", "Cursor", ".", "new", "(", "checkout", "(", "filename", ")", ",", "position", ")", "api_map", ".", "clip", "(", "cursor", ")", ".", "complete", "end" ]
Get completion suggestions at the specified file and location. @param filename [String] The file to analyze @param line [Integer] The zero-based line number @param column [Integer] The zero-based column number @return [SourceMap::Completion] @todo Take a Location instead of filename/line/column
[ "Get", "completion", "suggestions", "at", "the", "specified", "file", "and", "location", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L160-L164
11,415
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.definitions_at
def definitions_at filename, line, column position = Position.new(line, column) cursor = Source::Cursor.new(checkout(filename), position) api_map.clip(cursor).define end
ruby
def definitions_at filename, line, column position = Position.new(line, column) cursor = Source::Cursor.new(checkout(filename), position) api_map.clip(cursor).define end
[ "def", "definitions_at", "filename", ",", "line", ",", "column", "position", "=", "Position", ".", "new", "(", "line", ",", "column", ")", "cursor", "=", "Source", "::", "Cursor", ".", "new", "(", "checkout", "(", "filename", ")", ",", "position", ")", "api_map", ".", "clip", "(", "cursor", ")", ".", "define", "end" ]
Get definition suggestions for the expression at the specified file and location. @param filename [String] The file to analyze @param line [Integer] The zero-based line number @param column [Integer] The zero-based column number @return [Array<Solargraph::Pin::Base>] @todo Take filename/position instead of filename/line/column
[ "Get", "definition", "suggestions", "for", "the", "expression", "at", "the", "specified", "file", "and", "location", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L174-L178
11,416
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.signatures_at
def signatures_at filename, line, column position = Position.new(line, column) cursor = Source::Cursor.new(checkout(filename), position) api_map.clip(cursor).signify end
ruby
def signatures_at filename, line, column position = Position.new(line, column) cursor = Source::Cursor.new(checkout(filename), position) api_map.clip(cursor).signify end
[ "def", "signatures_at", "filename", ",", "line", ",", "column", "position", "=", "Position", ".", "new", "(", "line", ",", "column", ")", "cursor", "=", "Source", "::", "Cursor", ".", "new", "(", "checkout", "(", "filename", ")", ",", "position", ")", "api_map", ".", "clip", "(", "cursor", ")", ".", "signify", "end" ]
Get signature suggestions for the method at the specified file and location. @param filename [String] The file to analyze @param line [Integer] The zero-based line number @param column [Integer] The zero-based column number @return [Array<Solargraph::Pin::Base>] @todo Take filename/position instead of filename/line/column
[ "Get", "signature", "suggestions", "for", "the", "method", "at", "the", "specified", "file", "and", "location", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L188-L192
11,417
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.diagnose
def diagnose filename # @todo Only open files get diagnosed. Determine whether anything or # everything in the workspace should get diagnosed, or if there should # be an option to do so. # return [] unless open?(filename) catalog result = [] source = read(filename) workspace.config.reporters.each do |name| reporter = Diagnostics.reporter(name) raise DiagnosticsError, "Diagnostics reporter #{name} does not exist" if reporter.nil? result.concat reporter.new.diagnose(source, api_map) end result end
ruby
def diagnose filename # @todo Only open files get diagnosed. Determine whether anything or # everything in the workspace should get diagnosed, or if there should # be an option to do so. # return [] unless open?(filename) catalog result = [] source = read(filename) workspace.config.reporters.each do |name| reporter = Diagnostics.reporter(name) raise DiagnosticsError, "Diagnostics reporter #{name} does not exist" if reporter.nil? result.concat reporter.new.diagnose(source, api_map) end result end
[ "def", "diagnose", "filename", "# @todo Only open files get diagnosed. Determine whether anything or", "# everything in the workspace should get diagnosed, or if there should", "# be an option to do so.", "#", "return", "[", "]", "unless", "open?", "(", "filename", ")", "catalog", "result", "=", "[", "]", "source", "=", "read", "(", "filename", ")", "workspace", ".", "config", ".", "reporters", ".", "each", "do", "|", "name", "|", "reporter", "=", "Diagnostics", ".", "reporter", "(", "name", ")", "raise", "DiagnosticsError", ",", "\"Diagnostics reporter #{name} does not exist\"", "if", "reporter", ".", "nil?", "result", ".", "concat", "reporter", ".", "new", ".", "diagnose", "(", "source", ",", "api_map", ")", "end", "result", "end" ]
Get diagnostics about a file. @param filename [String] @return [Array<Hash>]
[ "Get", "diagnostics", "about", "a", "file", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L323-L338
11,418
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.catalog
def catalog @catalog_mutex.synchronize do break if synchronized? logger.info "Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}" api_map.catalog bundle @synchronized = true logger.info "Catalog complete (#{api_map.pins.length} pins)" end end
ruby
def catalog @catalog_mutex.synchronize do break if synchronized? logger.info "Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}" api_map.catalog bundle @synchronized = true logger.info "Catalog complete (#{api_map.pins.length} pins)" end end
[ "def", "catalog", "@catalog_mutex", ".", "synchronize", "do", "break", "if", "synchronized?", "logger", ".", "info", "\"Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}\"", "api_map", ".", "catalog", "bundle", "@synchronized", "=", "true", "logger", ".", "info", "\"Catalog complete (#{api_map.pins.length} pins)\"", "end", "end" ]
Update the ApiMap from the library's workspace and open files. @return [void]
[ "Update", "the", "ApiMap", "from", "the", "library", "s", "workspace", "and", "open", "files", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L343-L351
11,419
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.merge
def merge source result = nil mutex.synchronize do result = workspace.merge(source) @synchronized = !result if synchronized? end result end
ruby
def merge source result = nil mutex.synchronize do result = workspace.merge(source) @synchronized = !result if synchronized? end result end
[ "def", "merge", "source", "result", "=", "nil", "mutex", ".", "synchronize", "do", "result", "=", "workspace", ".", "merge", "(", "source", ")", "@synchronized", "=", "!", "result", "if", "synchronized?", "end", "result", "end" ]
Try to merge a source into the library's workspace. If the workspace is not configured to include the source, it gets ignored. @param source [Source] @return [Boolean] True if the source was merged into the workspace.
[ "Try", "to", "merge", "a", "source", "into", "the", "library", "s", "workspace", ".", "If", "the", "workspace", "is", "not", "configured", "to", "include", "the", "source", "it", "gets", "ignored", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L378-L385
11,420
castwide/solargraph
lib/solargraph/library.rb
Solargraph.Library.read
def read filename return @current if @current && @current.filename == filename raise FileNotFoundError, "File not found: #{filename}" unless workspace.has_file?(filename) workspace.source(filename) end
ruby
def read filename return @current if @current && @current.filename == filename raise FileNotFoundError, "File not found: #{filename}" unless workspace.has_file?(filename) workspace.source(filename) end
[ "def", "read", "filename", "return", "@current", "if", "@current", "&&", "@current", ".", "filename", "==", "filename", "raise", "FileNotFoundError", ",", "\"File not found: #{filename}\"", "unless", "workspace", ".", "has_file?", "(", "filename", ")", "workspace", ".", "source", "(", "filename", ")", "end" ]
Get the source for an open file or create a new source if the file exists on disk. Sources created from disk are not added to the open workspace files, i.e., the version on disk remains the authoritative version. @raise [FileNotFoundError] if the file does not exist @param filename [String] @return [Solargraph::Source]
[ "Get", "the", "source", "for", "an", "open", "file", "or", "create", "a", "new", "source", "if", "the", "file", "exists", "on", "disk", ".", "Sources", "created", "from", "disk", "are", "not", "added", "to", "the", "open", "workspace", "files", "i", ".", "e", ".", "the", "version", "on", "disk", "remains", "the", "authoritative", "version", "." ]
47badb5d151aca775ccbe6c470236089eae7839d
https://github.com/castwide/solargraph/blob/47badb5d151aca775ccbe6c470236089eae7839d/lib/solargraph/library.rb#L415-L419
11,421
hashicorp/vault-ruby
lib/vault/request.rb
Vault.Request.extract_headers!
def extract_headers!(options = {}) extract = { wrap_ttl: Vault::Client::WRAP_TTL_HEADER, } {}.tap do |h| extract.each do |k,v| if options[k] h[v] = options.delete(k) end end end end
ruby
def extract_headers!(options = {}) extract = { wrap_ttl: Vault::Client::WRAP_TTL_HEADER, } {}.tap do |h| extract.each do |k,v| if options[k] h[v] = options.delete(k) end end end end
[ "def", "extract_headers!", "(", "options", "=", "{", "}", ")", "extract", "=", "{", "wrap_ttl", ":", "Vault", "::", "Client", "::", "WRAP_TTL_HEADER", ",", "}", "{", "}", ".", "tap", "do", "|", "h", "|", "extract", ".", "each", "do", "|", "k", ",", "v", "|", "if", "options", "[", "k", "]", "h", "[", "v", "]", "=", "options", ".", "delete", "(", "k", ")", "end", "end", "end", "end" ]
Removes the given header fields from options and returns the result. This modifies the given options in place. @param [Hash] options @return [Hash]
[ "Removes", "the", "given", "header", "fields", "from", "options", "and", "returns", "the", "result", ".", "This", "modifies", "the", "given", "options", "in", "place", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/request.rb#L29-L41
11,422
hashicorp/vault-ruby
lib/vault/api/sys/seal.rb
Vault.Sys.unseal
def unseal(shard) json = client.put("/v1/sys/unseal", JSON.fast_generate( key: shard, )) return SealStatus.decode(json) end
ruby
def unseal(shard) json = client.put("/v1/sys/unseal", JSON.fast_generate( key: shard, )) return SealStatus.decode(json) end
[ "def", "unseal", "(", "shard", ")", "json", "=", "client", ".", "put", "(", "\"/v1/sys/unseal\"", ",", "JSON", ".", "fast_generate", "(", "key", ":", "shard", ",", ")", ")", "return", "SealStatus", ".", "decode", "(", "json", ")", "end" ]
Unseal the vault with the given shard. @example Vault.sys.unseal("abcd-1234") #=> #<Vault::SealStatus sealed=true, t=3, n=5, progress=1> @param [String] shard the key to use @return [SealStatus]
[ "Unseal", "the", "vault", "with", "the", "given", "shard", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/seal.rb#L74-L79
11,423
hashicorp/vault-ruby
lib/vault/api/logical.rb
Vault.Logical.list
def list(path, options = {}) headers = extract_headers!(options) json = client.list("/v1/#{encode_path(path)}", {}, headers) json[:data][:keys] || [] rescue HTTPError => e return [] if e.code == 404 raise end
ruby
def list(path, options = {}) headers = extract_headers!(options) json = client.list("/v1/#{encode_path(path)}", {}, headers) json[:data][:keys] || [] rescue HTTPError => e return [] if e.code == 404 raise end
[ "def", "list", "(", "path", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "list", "(", "\"/v1/#{encode_path(path)}\"", ",", "{", "}", ",", "headers", ")", "json", "[", ":data", "]", "[", ":keys", "]", "||", "[", "]", "rescue", "HTTPError", "=>", "e", "return", "[", "]", "if", "e", ".", "code", "==", "404", "raise", "end" ]
List the secrets at the given path, if the path supports listing. If the the path does not exist, an exception will be raised. @example Vault.logical.list("secret") #=> [#<Vault::Secret>, #<Vault::Secret>, ...] @param [String] path the path to list @return [Array<String>]
[ "List", "the", "secrets", "at", "the", "given", "path", "if", "the", "path", "supports", "listing", ".", "If", "the", "the", "path", "does", "not", "exist", "an", "exception", "will", "be", "raised", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/logical.rb#L26-L33
11,424
hashicorp/vault-ruby
lib/vault/api/logical.rb
Vault.Logical.read
def read(path, options = {}) headers = extract_headers!(options) json = client.get("/v1/#{encode_path(path)}", {}, headers) return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
ruby
def read(path, options = {}) headers = extract_headers!(options) json = client.get("/v1/#{encode_path(path)}", {}, headers) return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
[ "def", "read", "(", "path", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "get", "(", "\"/v1/#{encode_path(path)}\"", ",", "{", "}", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Read the secret at the given path. If the secret does not exist, +nil+ will be returned. @example Vault.logical.read("secret/password") #=> #<Vault::Secret lease_id=""> @param [String] path the path to read @return [Secret, nil]
[ "Read", "the", "secret", "at", "the", "given", "path", ".", "If", "the", "secret", "does", "not", "exist", "+", "nil", "+", "will", "be", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/logical.rb#L45-L52
11,425
hashicorp/vault-ruby
lib/vault/api/logical.rb
Vault.Logical.unwrap
def unwrap(wrapper) client.with_token(wrapper) do |client| json = client.get("/v1/cubbyhole/response") secret = Secret.decode(json) # If there is nothing in the cubbyhole, return early. if secret.nil? || secret.data.nil? || secret.data[:response].nil? return nil end # Extract the response and parse it into a new secret. json = JSON.parse(secret.data[:response], symbolize_names: true) secret = Secret.decode(json) return secret end rescue HTTPError => e return nil if e.code == 404 raise end
ruby
def unwrap(wrapper) client.with_token(wrapper) do |client| json = client.get("/v1/cubbyhole/response") secret = Secret.decode(json) # If there is nothing in the cubbyhole, return early. if secret.nil? || secret.data.nil? || secret.data[:response].nil? return nil end # Extract the response and parse it into a new secret. json = JSON.parse(secret.data[:response], symbolize_names: true) secret = Secret.decode(json) return secret end rescue HTTPError => e return nil if e.code == 404 raise end
[ "def", "unwrap", "(", "wrapper", ")", "client", ".", "with_token", "(", "wrapper", ")", "do", "|", "client", "|", "json", "=", "client", ".", "get", "(", "\"/v1/cubbyhole/response\"", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "# If there is nothing in the cubbyhole, return early.", "if", "secret", ".", "nil?", "||", "secret", ".", "data", ".", "nil?", "||", "secret", ".", "data", "[", ":response", "]", ".", "nil?", "return", "nil", "end", "# Extract the response and parse it into a new secret.", "json", "=", "JSON", ".", "parse", "(", "secret", ".", "data", "[", ":response", "]", ",", "symbolize_names", ":", "true", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "return", "secret", "end", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Unwrap the data stored against the given token. If the secret does not exist, `nil` will be returned. @example Vault.logical.unwrap("f363dba8-25a7-08c5-430c-00b2367124e6") #=> #<Vault::Secret lease_id=""> @param [String] wrapper the token to use when unwrapping the value @return [Secret, nil]
[ "Unwrap", "the", "data", "stored", "against", "the", "given", "token", ".", "If", "the", "secret", "does", "not", "exist", "nil", "will", "be", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/logical.rb#L101-L119
11,426
hashicorp/vault-ruby
lib/vault/api/logical.rb
Vault.Logical.unwrap_token
def unwrap_token(wrapper) # If provided a secret, grab the token. This is really just to make the # API a bit nicer. if wrapper.is_a?(Secret) wrapper = wrapper.wrap_info.token end # Unwrap response = unwrap(wrapper) # If nothing was there, return nil if response.nil? || response.auth.nil? return nil end return response.auth.client_token rescue HTTPError => e raise end
ruby
def unwrap_token(wrapper) # If provided a secret, grab the token. This is really just to make the # API a bit nicer. if wrapper.is_a?(Secret) wrapper = wrapper.wrap_info.token end # Unwrap response = unwrap(wrapper) # If nothing was there, return nil if response.nil? || response.auth.nil? return nil end return response.auth.client_token rescue HTTPError => e raise end
[ "def", "unwrap_token", "(", "wrapper", ")", "# If provided a secret, grab the token. This is really just to make the", "# API a bit nicer.", "if", "wrapper", ".", "is_a?", "(", "Secret", ")", "wrapper", "=", "wrapper", ".", "wrap_info", ".", "token", "end", "# Unwrap", "response", "=", "unwrap", "(", "wrapper", ")", "# If nothing was there, return nil", "if", "response", ".", "nil?", "||", "response", ".", "auth", ".", "nil?", "return", "nil", "end", "return", "response", ".", "auth", ".", "client_token", "rescue", "HTTPError", "=>", "e", "raise", "end" ]
Unwrap a token in a wrapped response given the temporary token. @example Vault.logical.unwrap("f363dba8-25a7-08c5-430c-00b2367124e6") #=> "0f0f40fd-06ce-4af1-61cb-cdc12796f42b" @param [String, Secret] wrapper the token to unwrap @return [String, nil]
[ "Unwrap", "a", "token", "in", "a", "wrapped", "response", "given", "the", "temporary", "token", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/logical.rb#L130-L148
11,427
hashicorp/vault-ruby
lib/vault/api/sys/auth.rb
Vault.Sys.auths
def auths json = client.get("/v1/sys/auth") json = json[:data] if json[:data] return Hash[*json.map do |k,v| [k.to_s.chomp("/").to_sym, Auth.decode(v)] end.flatten] end
ruby
def auths json = client.get("/v1/sys/auth") json = json[:data] if json[:data] return Hash[*json.map do |k,v| [k.to_s.chomp("/").to_sym, Auth.decode(v)] end.flatten] end
[ "def", "auths", "json", "=", "client", ".", "get", "(", "\"/v1/sys/auth\"", ")", "json", "=", "json", "[", ":data", "]", "if", "json", "[", ":data", "]", "return", "Hash", "[", "json", ".", "map", "do", "|", "k", ",", "v", "|", "[", "k", ".", "to_s", ".", "chomp", "(", "\"/\"", ")", ".", "to_sym", ",", "Auth", ".", "decode", "(", "v", ")", "]", "end", ".", "flatten", "]", "end" ]
List all auths in Vault. @example Vault.sys.auths #=> {:token => #<Vault::Auth type="token", description="token based credentials">} @return [Hash<Symbol, Auth>]
[ "List", "all", "auths", "in", "Vault", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/auth.rb#L35-L41
11,428
hashicorp/vault-ruby
lib/vault/api/sys/auth.rb
Vault.Sys.enable_auth
def enable_auth(path, type, description = nil) payload = { type: type } payload[:description] = description if !description.nil? client.post("/v1/sys/auth/#{encode_path(path)}", JSON.fast_generate(payload)) return true end
ruby
def enable_auth(path, type, description = nil) payload = { type: type } payload[:description] = description if !description.nil? client.post("/v1/sys/auth/#{encode_path(path)}", JSON.fast_generate(payload)) return true end
[ "def", "enable_auth", "(", "path", ",", "type", ",", "description", "=", "nil", ")", "payload", "=", "{", "type", ":", "type", "}", "payload", "[", ":description", "]", "=", "description", "if", "!", "description", ".", "nil?", "client", ".", "post", "(", "\"/v1/sys/auth/#{encode_path(path)}\"", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "return", "true", "end" ]
Enable a particular authentication at the given path. @example Vault.sys.enable_auth("github", "github") #=> true @param [String] path the path to mount the auth @param [String] type the type of authentication @param [String] description a human-friendly description (optional) @return [true]
[ "Enable", "a", "particular", "authentication", "at", "the", "given", "path", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/auth.rb#L56-L62
11,429
hashicorp/vault-ruby
lib/vault/api/sys/auth.rb
Vault.Sys.auth_tune
def auth_tune(path) json = client.get("/v1/sys/auth/#{encode_path(path)}/tune") return AuthConfig.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
ruby
def auth_tune(path) json = client.get("/v1/sys/auth/#{encode_path(path)}/tune") return AuthConfig.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
[ "def", "auth_tune", "(", "path", ")", "json", "=", "client", ".", "get", "(", "\"/v1/sys/auth/#{encode_path(path)}/tune\"", ")", "return", "AuthConfig", ".", "decode", "(", "json", ")", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Read the given auth path's configuration. @example Vault.sys.auth_tune("github") #=> #<Vault::AuthConfig "default_lease_ttl"=3600, "max_lease_ttl"=7200> @param [String] path the path to retrieve configuration for @return [AuthConfig] configuration of the given auth path
[ "Read", "the", "given", "auth", "path", "s", "configuration", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/auth.rb#L89-L95
11,430
hashicorp/vault-ruby
lib/vault/api/sys/auth.rb
Vault.Sys.put_auth_tune
def put_auth_tune(path, config = {}) json = client.put("/v1/sys/auth/#{encode_path(path)}/tune", JSON.fast_generate(config)) if json.nil? return true else return Secret.decode(json) end end
ruby
def put_auth_tune(path, config = {}) json = client.put("/v1/sys/auth/#{encode_path(path)}/tune", JSON.fast_generate(config)) if json.nil? return true else return Secret.decode(json) end end
[ "def", "put_auth_tune", "(", "path", ",", "config", "=", "{", "}", ")", "json", "=", "client", ".", "put", "(", "\"/v1/sys/auth/#{encode_path(path)}/tune\"", ",", "JSON", ".", "fast_generate", "(", "config", ")", ")", "if", "json", ".", "nil?", "return", "true", "else", "return", "Secret", ".", "decode", "(", "json", ")", "end", "end" ]
Write the given auth path's configuration. @example Vault.sys.auth_tune("github", "default_lease_ttl" => 600, "max_lease_ttl" => 1200 ) #=> true @param [String] path the path to retrieve configuration for @return [AuthConfig] configuration of the given auth path
[ "Write", "the", "given", "auth", "path", "s", "configuration", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/auth.rb#L107-L114
11,431
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.expired?
def expired? connection return true if @max_requests && connection.requests >= @max_requests return false unless @idle_timeout return true if @idle_timeout.zero? Time.now - connection.last_use > @idle_timeout end
ruby
def expired? connection return true if @max_requests && connection.requests >= @max_requests return false unless @idle_timeout return true if @idle_timeout.zero? Time.now - connection.last_use > @idle_timeout end
[ "def", "expired?", "connection", "return", "true", "if", "@max_requests", "&&", "connection", ".", "requests", ">=", "@max_requests", "return", "false", "unless", "@idle_timeout", "return", "true", "if", "@idle_timeout", ".", "zero?", "Time", ".", "now", "-", "connection", ".", "last_use", ">", "@idle_timeout", "end" ]
Returns true if the connection should be reset due to an idle timeout, or maximum request count, false otherwise.
[ "Returns", "true", "if", "the", "connection", "should", "be", "reset", "due", "to", "an", "idle", "timeout", "or", "maximum", "request", "count", "false", "otherwise", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L683-L689
11,432
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.idempotent?
def idempotent? req case req when Net::HTTP::Delete, Net::HTTP::Get, Net::HTTP::Head, Net::HTTP::Options, Net::HTTP::Put, Net::HTTP::Trace then true end end
ruby
def idempotent? req case req when Net::HTTP::Delete, Net::HTTP::Get, Net::HTTP::Head, Net::HTTP::Options, Net::HTTP::Put, Net::HTTP::Trace then true end end
[ "def", "idempotent?", "req", "case", "req", "when", "Net", "::", "HTTP", "::", "Delete", ",", "Net", "::", "HTTP", "::", "Get", ",", "Net", "::", "HTTP", "::", "Head", ",", "Net", "::", "HTTP", "::", "Options", ",", "Net", "::", "HTTP", "::", "Put", ",", "Net", "::", "HTTP", "::", "Trace", "then", "true", "end", "end" ]
Is +req+ idempotent according to RFC 2616?
[ "Is", "+", "req", "+", "idempotent", "according", "to", "RFC", "2616?" ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L729-L735
11,433
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.pipeline
def pipeline uri, requests, &block # :yields: responses connection_for uri do |connection| connection.http.pipeline requests, &block end end
ruby
def pipeline uri, requests, &block # :yields: responses connection_for uri do |connection| connection.http.pipeline requests, &block end end
[ "def", "pipeline", "uri", ",", "requests", ",", "&", "block", "# :yields: responses", "connection_for", "uri", "do", "|", "connection", "|", "connection", ".", "http", ".", "pipeline", "requests", ",", "block", "end", "end" ]
Pipelines +requests+ to the HTTP server at +uri+ yielding responses if a block is given. Returns all responses recieved. See Net::HTTP::Pipeline[http://docs.seattlerb.org/net-http-pipeline/Net/HTTP/Pipeline.html] for further details. Only if <tt>net-http-pipeline</tt> was required before <tt>net-http-persistent</tt> #pipeline will be present.
[ "Pipelines", "+", "requests", "+", "to", "the", "HTTP", "server", "at", "+", "uri", "+", "yielding", "responses", "if", "a", "block", "is", "given", ".", "Returns", "all", "responses", "recieved", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L762-L766
11,434
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.proxy_from_env
def proxy_from_env env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] return nil if env_proxy.nil? or env_proxy.empty? uri = URI normalize_uri env_proxy env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY'] # '*' is special case for always bypass return nil if env_no_proxy == '*' if env_no_proxy then uri.query = "no_proxy=#{escape(env_no_proxy)}" end unless uri.user or uri.password then uri.user = escape ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER'] uri.password = escape ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS'] end uri end
ruby
def proxy_from_env env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] return nil if env_proxy.nil? or env_proxy.empty? uri = URI normalize_uri env_proxy env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY'] # '*' is special case for always bypass return nil if env_no_proxy == '*' if env_no_proxy then uri.query = "no_proxy=#{escape(env_no_proxy)}" end unless uri.user or uri.password then uri.user = escape ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER'] uri.password = escape ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS'] end uri end
[ "def", "proxy_from_env", "env_proxy", "=", "ENV", "[", "'http_proxy'", "]", "||", "ENV", "[", "'HTTP_PROXY'", "]", "return", "nil", "if", "env_proxy", ".", "nil?", "or", "env_proxy", ".", "empty?", "uri", "=", "URI", "normalize_uri", "env_proxy", "env_no_proxy", "=", "ENV", "[", "'no_proxy'", "]", "||", "ENV", "[", "'NO_PROXY'", "]", "# '*' is special case for always bypass", "return", "nil", "if", "env_no_proxy", "==", "'*'", "if", "env_no_proxy", "then", "uri", ".", "query", "=", "\"no_proxy=#{escape(env_no_proxy)}\"", "end", "unless", "uri", ".", "user", "or", "uri", ".", "password", "then", "uri", ".", "user", "=", "escape", "ENV", "[", "'http_proxy_user'", "]", "||", "ENV", "[", "'HTTP_PROXY_USER'", "]", "uri", ".", "password", "=", "escape", "ENV", "[", "'http_proxy_pass'", "]", "||", "ENV", "[", "'HTTP_PROXY_PASS'", "]", "end", "uri", "end" ]
Creates a URI for an HTTP proxy server from ENV variables. If +HTTP_PROXY+ is set a proxy will be returned. If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the URI is given the indicated user and password unless HTTP_PROXY contains either of these in the URI. The +NO_PROXY+ ENV variable can be used to specify hosts which shouldn't be reached via proxy; if set it should be a comma separated list of hostname suffixes, optionally with +:port+ appended, for example <tt>example.com,some.host:8080</tt>. When set to <tt>*</tt> no proxy will be returned. For Windows users, lowercase ENV variables are preferred over uppercase ENV variables.
[ "Creates", "a", "URI", "for", "an", "HTTP", "proxy", "server", "from", "ENV", "variables", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L841-L863
11,435
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.proxy_bypass?
def proxy_bypass? host, port host = host.downcase host_port = [host, port].join ':' @no_proxy.each do |name| return true if host[-name.length, name.length] == name or host_port[-name.length, name.length] == name end false end
ruby
def proxy_bypass? host, port host = host.downcase host_port = [host, port].join ':' @no_proxy.each do |name| return true if host[-name.length, name.length] == name or host_port[-name.length, name.length] == name end false end
[ "def", "proxy_bypass?", "host", ",", "port", "host", "=", "host", ".", "downcase", "host_port", "=", "[", "host", ",", "port", "]", ".", "join", "':'", "@no_proxy", ".", "each", "do", "|", "name", "|", "return", "true", "if", "host", "[", "-", "name", ".", "length", ",", "name", ".", "length", "]", "==", "name", "or", "host_port", "[", "-", "name", ".", "length", ",", "name", ".", "length", "]", "==", "name", "end", "false", "end" ]
Returns true when proxy should by bypassed for host.
[ "Returns", "true", "when", "proxy", "should", "by", "bypassed", "for", "host", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L868-L878
11,436
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.request_failed
def request_failed exception, req, connection # :nodoc: due_to = "(due to #{exception.message} - #{exception.class})" message = "too many connection resets #{due_to} #{error_message connection}" finish connection raise Error, message, exception.backtrace end
ruby
def request_failed exception, req, connection # :nodoc: due_to = "(due to #{exception.message} - #{exception.class})" message = "too many connection resets #{due_to} #{error_message connection}" finish connection raise Error, message, exception.backtrace end
[ "def", "request_failed", "exception", ",", "req", ",", "connection", "# :nodoc:", "due_to", "=", "\"(due to #{exception.message} - #{exception.class})\"", "message", "=", "\"too many connection resets #{due_to} #{error_message connection}\"", "finish", "connection", "raise", "Error", ",", "message", ",", "exception", ".", "backtrace", "end" ]
Raises an Error for +exception+ which resulted from attempting the request +req+ on the +connection+. Finishes the +connection+.
[ "Raises", "an", "Error", "for", "+", "exception", "+", "which", "resulted", "from", "attempting", "the", "request", "+", "req", "+", "on", "the", "+", "connection", "+", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L992-L999
11,437
hashicorp/vault-ruby
lib/vault/persistent.rb
Vault.PersistentHTTP.request_setup
def request_setup req_or_uri # :nodoc: req = if URI === req_or_uri then Net::HTTP::Get.new req_or_uri.request_uri else req_or_uri end @headers.each do |pair| req.add_field(*pair) end @override_headers.each do |name, value| req[name] = value end unless req['Connection'] then req.add_field 'Connection', 'keep-alive' req.add_field 'Keep-Alive', @keep_alive end req end
ruby
def request_setup req_or_uri # :nodoc: req = if URI === req_or_uri then Net::HTTP::Get.new req_or_uri.request_uri else req_or_uri end @headers.each do |pair| req.add_field(*pair) end @override_headers.each do |name, value| req[name] = value end unless req['Connection'] then req.add_field 'Connection', 'keep-alive' req.add_field 'Keep-Alive', @keep_alive end req end
[ "def", "request_setup", "req_or_uri", "# :nodoc:", "req", "=", "if", "URI", "===", "req_or_uri", "then", "Net", "::", "HTTP", "::", "Get", ".", "new", "req_or_uri", ".", "request_uri", "else", "req_or_uri", "end", "@headers", ".", "each", "do", "|", "pair", "|", "req", ".", "add_field", "(", "pair", ")", "end", "@override_headers", ".", "each", "do", "|", "name", ",", "value", "|", "req", "[", "name", "]", "=", "value", "end", "unless", "req", "[", "'Connection'", "]", "then", "req", ".", "add_field", "'Connection'", ",", "'keep-alive'", "req", ".", "add_field", "'Keep-Alive'", ",", "@keep_alive", "end", "req", "end" ]
Creates a GET request if +req_or_uri+ is a URI and adds headers to the request. Returns the request.
[ "Creates", "a", "GET", "request", "if", "+", "req_or_uri", "+", "is", "a", "URI", "and", "adds", "headers", "to", "the", "request", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/persistent.rb#L1007-L1028
11,438
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.token
def token(new_token) old_token = client.token client.token = new_token json = client.get("/v1/auth/token/lookup-self") secret = Secret.decode(json) return secret rescue client.token = old_token raise end
ruby
def token(new_token) old_token = client.token client.token = new_token json = client.get("/v1/auth/token/lookup-self") secret = Secret.decode(json) return secret rescue client.token = old_token raise end
[ "def", "token", "(", "new_token", ")", "old_token", "=", "client", ".", "token", "client", ".", "token", "=", "new_token", "json", "=", "client", ".", "get", "(", "\"/v1/auth/token/lookup-self\"", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "return", "secret", "rescue", "client", ".", "token", "=", "old_token", "raise", "end" ]
Authenticate via the "token" authentication method. This authentication method is a bit bizarre because you already have a token, but hey, whatever floats your boat. This method hits the `/v1/auth/token/lookup-self` endpoint after setting the Vault client's token to the given token parameter. If the self lookup succeeds, the token is persisted onto the client for future requests. If the lookup fails, the old token (which could be unset) is restored on the client. @example Vault.auth.token("6440e1bd-ba22-716a-887d-e133944d22bd") #=> #<Vault::Secret lease_id=""> Vault.token #=> "6440e1bd-ba22-716a-887d-e133944d22bd" @param [String] new_token the new token to try to authenticate and store on the client @return [Secret]
[ "Authenticate", "via", "the", "token", "authentication", "method", ".", "This", "authentication", "method", "is", "a", "bit", "bizarre", "because", "you", "already", "have", "a", "token", "but", "hey", "whatever", "floats", "your", "boat", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L34-L43
11,439
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.app_id
def app_id(app_id, user_id, options = {}) payload = { app_id: app_id, user_id: user_id }.merge(options) json = client.post("/v1/auth/app-id/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def app_id(app_id, user_id, options = {}) payload = { app_id: app_id, user_id: user_id }.merge(options) json = client.post("/v1/auth/app-id/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "app_id", "(", "app_id", ",", "user_id", ",", "options", "=", "{", "}", ")", "payload", "=", "{", "app_id", ":", "app_id", ",", "user_id", ":", "user_id", "}", ".", "merge", "(", "options", ")", "json", "=", "client", ".", "post", "(", "\"/v1/auth/app-id/login\"", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via the "app-id" authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Vault.auth.app_id( "aeece56e-3f9b-40c3-8f85-781d3e9a8f68", "3b87be76-95cf-493a-a61b-7d5fc70870ad", ) #=> #<Vault::Secret lease_id=""> @example with a custom mount point Vault.auth.app_id( "aeece56e-3f9b-40c3-8f85-781d3e9a8f68", "3b87be76-95cf-493a-a61b-7d5fc70870ad", mount: "new-app-id", ) @param [String] app_id @param [String] user_id @param [Hash] options additional options to pass to the authentication call, such as a custom mount point @return [Secret]
[ "Authenticate", "via", "the", "app", "-", "id", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L69-L75
11,440
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.approle
def approle(role_id, secret_id=nil) payload = { role_id: role_id } payload[:secret_id] = secret_id if secret_id json = client.post("/v1/auth/approle/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def approle(role_id, secret_id=nil) payload = { role_id: role_id } payload[:secret_id] = secret_id if secret_id json = client.post("/v1/auth/approle/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "approle", "(", "role_id", ",", "secret_id", "=", "nil", ")", "payload", "=", "{", "role_id", ":", "role_id", "}", "payload", "[", ":secret_id", "]", "=", "secret_id", "if", "secret_id", "json", "=", "client", ".", "post", "(", "\"/v1/auth/approle/login\"", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via the "approle" authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Vault.auth.approle( "db02de05-fa39-4855-059b-67221c5c2f63", "6a174c20-f6de-a53c-74d2-6018fcceff64", ) #=> #<Vault::Secret lease_id=""> @param [String] role_id @param [String] secret_id (default: nil) It is required when `bind_secret_id` is enabled for the specified role_id @return [Secret]
[ "Authenticate", "via", "the", "approle", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L92-L99
11,441
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.userpass
def userpass(username, password, options = {}) payload = { password: password }.merge(options) json = client.post("/v1/auth/userpass/login/#{encode_path(username)}", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def userpass(username, password, options = {}) payload = { password: password }.merge(options) json = client.post("/v1/auth/userpass/login/#{encode_path(username)}", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "userpass", "(", "username", ",", "password", ",", "options", "=", "{", "}", ")", "payload", "=", "{", "password", ":", "password", "}", ".", "merge", "(", "options", ")", "json", "=", "client", ".", "post", "(", "\"/v1/auth/userpass/login/#{encode_path(username)}\"", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via the "userpass" authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Vault.auth.userpass("sethvargo", "s3kr3t") #=> #<Vault::Secret lease_id=""> @example with a custom mount point Vault.auth.userpass("sethvargo", "s3kr3t", mount: "admin-login") #=> #<Vault::Secret lease_id=""> @param [String] username @param [String] password @param [Hash] options additional options to pass to the authentication call, such as a custom mount point @return [Secret]
[ "Authenticate", "via", "the", "userpass", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L118-L124
11,442
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.github
def github(github_token, path="/v1/auth/github/login") payload = {token: github_token} json = client.post(path, JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def github(github_token, path="/v1/auth/github/login") payload = {token: github_token} json = client.post(path, JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "github", "(", "github_token", ",", "path", "=", "\"/v1/auth/github/login\"", ")", "payload", "=", "{", "token", ":", "github_token", "}", "json", "=", "client", ".", "post", "(", "path", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via the GitHub authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Vault.auth.github("mypersonalgithubtoken") #=> #<Vault::Secret lease_id=""> @param [String] github_token @return [Secret]
[ "Authenticate", "via", "the", "GitHub", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L158-L164
11,443
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.aws_ec2
def aws_ec2(role, pkcs7, nonce = nil, route = nil) route ||= '/v1/auth/aws-ec2/login' payload = { role: role, pkcs7: pkcs7 } # Set a custom nonce if client is providing one payload[:nonce] = nonce if nonce json = client.post(route, JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def aws_ec2(role, pkcs7, nonce = nil, route = nil) route ||= '/v1/auth/aws-ec2/login' payload = { role: role, pkcs7: pkcs7 } # Set a custom nonce if client is providing one payload[:nonce] = nonce if nonce json = client.post(route, JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "aws_ec2", "(", "role", ",", "pkcs7", ",", "nonce", "=", "nil", ",", "route", "=", "nil", ")", "route", "||=", "'/v1/auth/aws-ec2/login'", "payload", "=", "{", "role", ":", "role", ",", "pkcs7", ":", "pkcs7", "}", "# Set a custom nonce if client is providing one", "payload", "[", ":nonce", "]", "=", "nonce", "if", "nonce", "json", "=", "client", ".", "post", "(", "route", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via the AWS EC2 authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Vault.auth.aws_ec2("read-only", "pkcs7", "vault-nonce") #=> #<Vault::Secret lease_id=""> @param [String] role @param [String] pkcs7 pkcs7 returned by the instance identity document (with line breaks removed) @param [String] nonce optional @param [String] route optional @return [Secret]
[ "Authenticate", "via", "the", "AWS", "EC2", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L180-L189
11,444
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.gcp
def gcp(role, jwt, path = 'gcp') payload = { role: role, jwt: jwt } json = client.post("/v1/auth/#{CGI.escape(path)}/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def gcp(role, jwt, path = 'gcp') payload = { role: role, jwt: jwt } json = client.post("/v1/auth/#{CGI.escape(path)}/login", JSON.fast_generate(payload)) secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "gcp", "(", "role", ",", "jwt", ",", "path", "=", "'gcp'", ")", "payload", "=", "{", "role", ":", "role", ",", "jwt", ":", "jwt", "}", "json", "=", "client", ".", "post", "(", "\"/v1/auth/#{CGI.escape(path)}/login\"", ",", "JSON", ".", "fast_generate", "(", "payload", ")", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via the GCP authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Vault.auth.gcp("read-only", "jwt", "gcp") #=> #<Vault::Secret lease_id=""> @param [String] role @param [String] jwt jwt returned by the instance identity metadata, or iam api @param [String] path optional the path were the gcp auth backend is mounted @return [Secret]
[ "Authenticate", "via", "the", "GCP", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L262-L268
11,445
hashicorp/vault-ruby
lib/vault/api/auth.rb
Vault.Authenticate.tls
def tls(pem = nil, path = 'cert') new_client = client.dup new_client.ssl_pem_contents = pem if !pem.nil? json = new_client.post("/v1/auth/#{CGI.escape(path)}/login") secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
ruby
def tls(pem = nil, path = 'cert') new_client = client.dup new_client.ssl_pem_contents = pem if !pem.nil? json = new_client.post("/v1/auth/#{CGI.escape(path)}/login") secret = Secret.decode(json) client.token = secret.auth.client_token return secret end
[ "def", "tls", "(", "pem", "=", "nil", ",", "path", "=", "'cert'", ")", "new_client", "=", "client", ".", "dup", "new_client", ".", "ssl_pem_contents", "=", "pem", "if", "!", "pem", ".", "nil?", "json", "=", "new_client", ".", "post", "(", "\"/v1/auth/#{CGI.escape(path)}/login\"", ")", "secret", "=", "Secret", ".", "decode", "(", "json", ")", "client", ".", "token", "=", "secret", ".", "auth", ".", "client_token", "return", "secret", "end" ]
Authenticate via a TLS authentication method. If authentication is successful, the resulting token will be stored on the client and used for future requests. @example Sending raw pem contents Vault.auth.tls(pem_contents) #=> #<Vault::Secret lease_id=""> @example Reading a pem from disk Vault.auth.tls(File.read("/path/to/my/certificate.pem")) #=> #<Vault::Secret lease_id=""> @example Sending to a cert authentication backend mounted at a custom location Vault.auth.tls(pem_contents, 'custom/location') #=> #<Vault::Secret lease_id=""> @param [String] pem (default: the configured SSL pem file or contents) The raw pem contents to use for the login procedure. @param [String] path (default: 'cert') The path to the auth backend to use for the login procedure. @return [Secret]
[ "Authenticate", "via", "a", "TLS", "authentication", "method", ".", "If", "authentication", "is", "successful", "the", "resulting", "token", "will", "be", "stored", "on", "the", "client", "and", "used", "for", "future", "requests", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth.rb#L290-L298
11,446
hashicorp/vault-ruby
lib/vault/api/sys/policy.rb
Vault.Sys.policy
def policy(name) json = client.get("/v1/sys/policy/#{encode_path(name)}") return Policy.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
ruby
def policy(name) json = client.get("/v1/sys/policy/#{encode_path(name)}") return Policy.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
[ "def", "policy", "(", "name", ")", "json", "=", "client", ".", "get", "(", "\"/v1/sys/policy/#{encode_path(name)}\"", ")", "return", "Policy", ".", "decode", "(", "json", ")", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Get the policy by the given name. If a policy does not exist by that name, +nil+ is returned. @example Vault.sys.policy("root") #=> #<Vault::Policy rules=""> @return [Policy, nil]
[ "Get", "the", "policy", "by", "the", "given", "name", ".", "If", "a", "policy", "does", "not", "exist", "by", "that", "name", "+", "nil", "+", "is", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/policy.rb#L42-L48
11,447
hashicorp/vault-ruby
lib/vault/api/sys/policy.rb
Vault.Sys.put_policy
def put_policy(name, rules) client.put("/v1/sys/policy/#{encode_path(name)}", JSON.fast_generate( rules: rules, )) return true end
ruby
def put_policy(name, rules) client.put("/v1/sys/policy/#{encode_path(name)}", JSON.fast_generate( rules: rules, )) return true end
[ "def", "put_policy", "(", "name", ",", "rules", ")", "client", ".", "put", "(", "\"/v1/sys/policy/#{encode_path(name)}\"", ",", "JSON", ".", "fast_generate", "(", "rules", ":", "rules", ",", ")", ")", "return", "true", "end" ]
Create a new policy with the given name and rules. @example policy = <<-EOH path "sys" { policy = "deny" } EOH Vault.sys.put_policy("dev", policy) #=> true It is recommend that you load policy rules from a file: @example policy = File.read("/path/to/my/policy.hcl") Vault.sys.put_policy("dev", policy) @param [String] name the name of the policy @param [String] rules the policy rules @return [true]
[ "Create", "a", "new", "policy", "with", "the", "given", "name", "and", "rules", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/policy.rb#L72-L77
11,448
hashicorp/vault-ruby
lib/vault/api/sys/audit.rb
Vault.Sys.audits
def audits json = client.get("/v1/sys/audit") json = json[:data] if json[:data] return Hash[*json.map do |k,v| [k.to_s.chomp("/").to_sym, Audit.decode(v)] end.flatten] end
ruby
def audits json = client.get("/v1/sys/audit") json = json[:data] if json[:data] return Hash[*json.map do |k,v| [k.to_s.chomp("/").to_sym, Audit.decode(v)] end.flatten] end
[ "def", "audits", "json", "=", "client", ".", "get", "(", "\"/v1/sys/audit\"", ")", "json", "=", "json", "[", ":data", "]", "if", "json", "[", ":data", "]", "return", "Hash", "[", "json", ".", "map", "do", "|", "k", ",", "v", "|", "[", "k", ".", "to_s", ".", "chomp", "(", "\"/\"", ")", ".", "to_sym", ",", "Audit", ".", "decode", "(", "v", ")", "]", "end", ".", "flatten", "]", "end" ]
List all audits for the vault. @example Vault.sys.audits #=> { :file => #<Audit> } @return [Hash<Symbol, Audit>]
[ "List", "all", "audits", "for", "the", "vault", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/audit.rb#L28-L34
11,449
hashicorp/vault-ruby
lib/vault/api/sys/audit.rb
Vault.Sys.audit_hash
def audit_hash(path, input) json = client.post("/v1/sys/audit-hash/#{encode_path(path)}", JSON.fast_generate(input: input)) json = json[:data] if json[:data] json[:hash] end
ruby
def audit_hash(path, input) json = client.post("/v1/sys/audit-hash/#{encode_path(path)}", JSON.fast_generate(input: input)) json = json[:data] if json[:data] json[:hash] end
[ "def", "audit_hash", "(", "path", ",", "input", ")", "json", "=", "client", ".", "post", "(", "\"/v1/sys/audit-hash/#{encode_path(path)}\"", ",", "JSON", ".", "fast_generate", "(", "input", ":", "input", ")", ")", "json", "=", "json", "[", ":data", "]", "if", "json", "[", ":data", "]", "json", "[", ":hash", "]", "end" ]
Generates a HMAC verifier for a given input. @example Vault.sys.audit_hash("file-audit", "my input") #=> "hmac-sha256:30aa7de18a5e90bbc1063db91e7c387b32b9fa895977eb8c177bbc91e7d7c542" @param [String] path the path of the audit backend @param [String] input the input to generate a HMAC for @return [String]
[ "Generates", "a", "HMAC", "verifier", "for", "a", "given", "input", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/audit.rb#L85-L89
11,450
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.accessors
def accessors(options = {}) headers = extract_headers!(options) json = client.list("/v1/auth/token/accessors", options, headers) return Secret.decode(json) end
ruby
def accessors(options = {}) headers = extract_headers!(options) json = client.list("/v1/auth/token/accessors", options, headers) return Secret.decode(json) end
[ "def", "accessors", "(", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "list", "(", "\"/v1/auth/token/accessors\"", ",", "options", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Lists all token accessors. @example Listing token accessors result = Vault.auth_token.accessors #=> #<Vault::Secret> result.data[:keys] #=> ["476ea048-ded5-4d07-eeea-938c6b4e43ec", "bb00c093-b7d3-b0e9-69cc-c4d85081165b"] @return [Array<Secret>]
[ "Lists", "all", "token", "accessors", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L25-L29
11,451
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.create
def create(options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/create", JSON.fast_generate(options), headers) return Secret.decode(json) end
ruby
def create(options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/create", JSON.fast_generate(options), headers) return Secret.decode(json) end
[ "def", "create", "(", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "post", "(", "\"/v1/auth/token/create\"", ",", "JSON", ".", "fast_generate", "(", "options", ")", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Create an authentication token. Note that the parameters specified below are not validated and passed directly to the Vault server. Depending on the version of Vault in operation, some of these options may not work, and newer options may be available that are not listed here. @example Creating a token Vault.auth_token.create #=> #<Vault::Secret lease_id=""> @example Creating a token assigned to policies with a wrap TTL Vault.auth_token.create( policies: ["myapp"], wrap_ttl: 500, ) @param [Hash] options @option options [String] :id The ID of the client token - this can only be specified for root tokens @option options [Array<String>] :policies List of policies to apply to the token @option options [Fixnum, String] :wrap_ttl The number of seconds or a golang-formatted timestamp like "5s" or "10m" for the TTL on the wrapped response @option options [Hash<String, String>] :meta A map of metadata that is passed to audit backends @option options [Boolean] :no_parent Create a token without a parent - see also {#create_orphan} @option options [Boolean] :no_default_policy Create a token without the default policy attached @option options [Boolean] :renewable Set whether this token is renewable or not @option options [String] :display_name Name of the token @option options [Fixnum] :num_uses Maximum number of uses for the token @return [Secret]
[ "Create", "an", "authentication", "token", ".", "Note", "that", "the", "parameters", "specified", "below", "are", "not", "validated", "and", "passed", "directly", "to", "the", "Vault", "server", ".", "Depending", "on", "the", "version", "of", "Vault", "in", "operation", "some", "of", "these", "options", "may", "not", "work", "and", "newer", "options", "may", "be", "available", "that", "are", "not", "listed", "here", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L67-L71
11,452
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.create_with_role
def create_with_role(name, options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/create/#{encode_path(name)}", JSON.fast_generate(options), headers) return Secret.decode(json) end
ruby
def create_with_role(name, options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/create/#{encode_path(name)}", JSON.fast_generate(options), headers) return Secret.decode(json) end
[ "def", "create_with_role", "(", "name", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "post", "(", "\"/v1/auth/token/create/#{encode_path(name)}\"", ",", "JSON", ".", "fast_generate", "(", "options", ")", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Create an orphaned authentication token. @example Vault.auth_token.create_with_role("developer") #=> #<Vault::Secret lease_id=""> @param [Hash] options @return [Secret]
[ "Create", "an", "orphaned", "authentication", "token", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L96-L100
11,453
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.lookup
def lookup(token, options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/lookup", JSON.fast_generate( token: token, ), headers) return Secret.decode(json) end
ruby
def lookup(token, options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/lookup", JSON.fast_generate( token: token, ), headers) return Secret.decode(json) end
[ "def", "lookup", "(", "token", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "post", "(", "\"/v1/auth/token/lookup\"", ",", "JSON", ".", "fast_generate", "(", "token", ":", "token", ",", ")", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Lookup information about the current token. @example Vault.auth_token.lookup("abcd-...") #=> #<Vault::Secret lease_id=""> @param [String] token @param [Hash] options @return [Secret]
[ "Lookup", "information", "about", "the", "current", "token", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L111-L117
11,454
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.lookup_accessor
def lookup_accessor(accessor, options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/lookup-accessor", JSON.fast_generate( accessor: accessor, ), headers) return Secret.decode(json) end
ruby
def lookup_accessor(accessor, options = {}) headers = extract_headers!(options) json = client.post("/v1/auth/token/lookup-accessor", JSON.fast_generate( accessor: accessor, ), headers) return Secret.decode(json) end
[ "def", "lookup_accessor", "(", "accessor", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "post", "(", "\"/v1/auth/token/lookup-accessor\"", ",", "JSON", ".", "fast_generate", "(", "accessor", ":", "accessor", ",", ")", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Lookup information about the given token accessor. @example Vault.auth_token.lookup_accessor("acbd-...") #=> #<Vault::Secret lease_id=""> @param [String] accessor @param [Hash] options
[ "Lookup", "information", "about", "the", "given", "token", "accessor", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L126-L132
11,455
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.renew
def renew(token, increment = 0, options = {}) headers = extract_headers!(options) json = client.put("/v1/auth/token/renew", JSON.fast_generate( token: token, increment: increment, ), headers) return Secret.decode(json) end
ruby
def renew(token, increment = 0, options = {}) headers = extract_headers!(options) json = client.put("/v1/auth/token/renew", JSON.fast_generate( token: token, increment: increment, ), headers) return Secret.decode(json) end
[ "def", "renew", "(", "token", ",", "increment", "=", "0", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "put", "(", "\"/v1/auth/token/renew\"", ",", "JSON", ".", "fast_generate", "(", "token", ":", "token", ",", "increment", ":", "increment", ",", ")", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Renew the given authentication token. @example Vault.auth_token.renew("abcd-1234") #=> #<Vault::Secret lease_id=""> @param [String] token the auth token @param [Fixnum] increment @return [Secret]
[ "Renew", "the", "given", "authentication", "token", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L155-L162
11,456
hashicorp/vault-ruby
lib/vault/api/auth_token.rb
Vault.AuthToken.renew_self
def renew_self(increment = 0, options = {}) headers = extract_headers!(options) json = client.put("/v1/auth/token/renew-self", JSON.fast_generate( increment: increment, ), headers) return Secret.decode(json) end
ruby
def renew_self(increment = 0, options = {}) headers = extract_headers!(options) json = client.put("/v1/auth/token/renew-self", JSON.fast_generate( increment: increment, ), headers) return Secret.decode(json) end
[ "def", "renew_self", "(", "increment", "=", "0", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "put", "(", "\"/v1/auth/token/renew-self\"", ",", "JSON", ".", "fast_generate", "(", "increment", ":", "increment", ",", ")", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Renews a lease associated with the calling token. @example Vault.auth_token.renew_self #=> #<Vault::Secret lease_id=""> @param [Fixnum] increment @return [Secret]
[ "Renews", "a", "lease", "associated", "with", "the", "calling", "token", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/auth_token.rb#L172-L178
11,457
hashicorp/vault-ruby
lib/vault/client.rb
Vault.Client.pool
def pool @lock.synchronize do return @nhp if @nhp @nhp = PersistentHTTP.new("vault-ruby", nil, pool_size) if proxy_address proxy_uri = URI.parse "http://#{proxy_address}" proxy_uri.port = proxy_port if proxy_port if proxy_username proxy_uri.user = proxy_username proxy_uri.password = proxy_password end @nhp.proxy = proxy_uri end # Use a custom open timeout if open_timeout || timeout @nhp.open_timeout = (open_timeout || timeout).to_i end # Use a custom read timeout if read_timeout || timeout @nhp.read_timeout = (read_timeout || timeout).to_i end @nhp.verify_mode = OpenSSL::SSL::VERIFY_PEER # Vault requires TLS1.2 @nhp.ssl_version = "TLSv1_2" # Only use secure ciphers @nhp.ciphers = ssl_ciphers # Custom pem files, no problem! pem = ssl_pem_contents || (ssl_pem_file ? File.read(ssl_pem_file) : nil) if pem @nhp.cert = OpenSSL::X509::Certificate.new(pem) @nhp.key = OpenSSL::PKey::RSA.new(pem, ssl_pem_passphrase) end # Use custom CA cert for verification if ssl_ca_cert @nhp.ca_file = ssl_ca_cert end # Use custom CA path that contains CA certs if ssl_ca_path @nhp.ca_path = ssl_ca_path end if ssl_cert_store @nhp.cert_store = ssl_cert_store end # Naughty, naughty, naughty! Don't blame me when someone hops in # and executes a MITM attack! if !ssl_verify @nhp.verify_mode = OpenSSL::SSL::VERIFY_NONE end # Use custom timeout for connecting and verifying via SSL if ssl_timeout || timeout @nhp.ssl_timeout = (ssl_timeout || timeout).to_i end @nhp end end
ruby
def pool @lock.synchronize do return @nhp if @nhp @nhp = PersistentHTTP.new("vault-ruby", nil, pool_size) if proxy_address proxy_uri = URI.parse "http://#{proxy_address}" proxy_uri.port = proxy_port if proxy_port if proxy_username proxy_uri.user = proxy_username proxy_uri.password = proxy_password end @nhp.proxy = proxy_uri end # Use a custom open timeout if open_timeout || timeout @nhp.open_timeout = (open_timeout || timeout).to_i end # Use a custom read timeout if read_timeout || timeout @nhp.read_timeout = (read_timeout || timeout).to_i end @nhp.verify_mode = OpenSSL::SSL::VERIFY_PEER # Vault requires TLS1.2 @nhp.ssl_version = "TLSv1_2" # Only use secure ciphers @nhp.ciphers = ssl_ciphers # Custom pem files, no problem! pem = ssl_pem_contents || (ssl_pem_file ? File.read(ssl_pem_file) : nil) if pem @nhp.cert = OpenSSL::X509::Certificate.new(pem) @nhp.key = OpenSSL::PKey::RSA.new(pem, ssl_pem_passphrase) end # Use custom CA cert for verification if ssl_ca_cert @nhp.ca_file = ssl_ca_cert end # Use custom CA path that contains CA certs if ssl_ca_path @nhp.ca_path = ssl_ca_path end if ssl_cert_store @nhp.cert_store = ssl_cert_store end # Naughty, naughty, naughty! Don't blame me when someone hops in # and executes a MITM attack! if !ssl_verify @nhp.verify_mode = OpenSSL::SSL::VERIFY_NONE end # Use custom timeout for connecting and verifying via SSL if ssl_timeout || timeout @nhp.ssl_timeout = (ssl_timeout || timeout).to_i end @nhp end end
[ "def", "pool", "@lock", ".", "synchronize", "do", "return", "@nhp", "if", "@nhp", "@nhp", "=", "PersistentHTTP", ".", "new", "(", "\"vault-ruby\"", ",", "nil", ",", "pool_size", ")", "if", "proxy_address", "proxy_uri", "=", "URI", ".", "parse", "\"http://#{proxy_address}\"", "proxy_uri", ".", "port", "=", "proxy_port", "if", "proxy_port", "if", "proxy_username", "proxy_uri", ".", "user", "=", "proxy_username", "proxy_uri", ".", "password", "=", "proxy_password", "end", "@nhp", ".", "proxy", "=", "proxy_uri", "end", "# Use a custom open timeout", "if", "open_timeout", "||", "timeout", "@nhp", ".", "open_timeout", "=", "(", "open_timeout", "||", "timeout", ")", ".", "to_i", "end", "# Use a custom read timeout", "if", "read_timeout", "||", "timeout", "@nhp", ".", "read_timeout", "=", "(", "read_timeout", "||", "timeout", ")", ".", "to_i", "end", "@nhp", ".", "verify_mode", "=", "OpenSSL", "::", "SSL", "::", "VERIFY_PEER", "# Vault requires TLS1.2", "@nhp", ".", "ssl_version", "=", "\"TLSv1_2\"", "# Only use secure ciphers", "@nhp", ".", "ciphers", "=", "ssl_ciphers", "# Custom pem files, no problem!", "pem", "=", "ssl_pem_contents", "||", "(", "ssl_pem_file", "?", "File", ".", "read", "(", "ssl_pem_file", ")", ":", "nil", ")", "if", "pem", "@nhp", ".", "cert", "=", "OpenSSL", "::", "X509", "::", "Certificate", ".", "new", "(", "pem", ")", "@nhp", ".", "key", "=", "OpenSSL", "::", "PKey", "::", "RSA", ".", "new", "(", "pem", ",", "ssl_pem_passphrase", ")", "end", "# Use custom CA cert for verification", "if", "ssl_ca_cert", "@nhp", ".", "ca_file", "=", "ssl_ca_cert", "end", "# Use custom CA path that contains CA certs", "if", "ssl_ca_path", "@nhp", ".", "ca_path", "=", "ssl_ca_path", "end", "if", "ssl_cert_store", "@nhp", ".", "cert_store", "=", "ssl_cert_store", "end", "# Naughty, naughty, naughty! Don't blame me when someone hops in", "# and executes a MITM attack!", "if", "!", "ssl_verify", "@nhp", ".", "verify_mode", "=", "OpenSSL", "::", "SSL", "::", "VERIFY_NONE", "end", "# Use custom timeout for connecting and verifying via SSL", "if", "ssl_timeout", "||", "timeout", "@nhp", ".", "ssl_timeout", "=", "(", "ssl_timeout", "||", "timeout", ")", ".", "to_i", "end", "@nhp", "end", "end" ]
Create a new Client with the given options. Any options given take precedence over the default options. @return [Vault::Client]
[ "Create", "a", "new", "Client", "with", "the", "given", "options", ".", "Any", "options", "given", "take", "precedence", "over", "the", "default", "options", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/client.rb#L82-L153
11,458
hashicorp/vault-ruby
lib/vault/client.rb
Vault.Client.list
def list(path, params = {}, headers = {}) params = params.merge(list: true) request(:get, path, params, headers) end
ruby
def list(path, params = {}, headers = {}) params = params.merge(list: true) request(:get, path, params, headers) end
[ "def", "list", "(", "path", ",", "params", "=", "{", "}", ",", "headers", "=", "{", "}", ")", "params", "=", "params", ".", "merge", "(", "list", ":", "true", ")", "request", "(", ":get", ",", "path", ",", "params", ",", "headers", ")", "end" ]
Perform a LIST request. @see Client#request
[ "Perform", "a", "LIST", "request", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/client.rb#L189-L192
11,459
hashicorp/vault-ruby
lib/vault/api/sys/lease.rb
Vault.Sys.renew
def renew(id, increment = 0) json = client.put("/v1/sys/renew/#{id}", JSON.fast_generate( increment: increment, )) return Secret.decode(json) end
ruby
def renew(id, increment = 0) json = client.put("/v1/sys/renew/#{id}", JSON.fast_generate( increment: increment, )) return Secret.decode(json) end
[ "def", "renew", "(", "id", ",", "increment", "=", "0", ")", "json", "=", "client", ".", "put", "(", "\"/v1/sys/renew/#{id}\"", ",", "JSON", ".", "fast_generate", "(", "increment", ":", "increment", ",", ")", ")", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Renew a lease with the given ID. @example Vault.sys.renew("aws/username") #=> #<Vault::Secret ...> @param [String] id the lease ID @param [Fixnum] increment @return [Secret]
[ "Renew", "a", "lease", "with", "the", "given", "ID", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/lease.rb#L13-L18
11,460
hashicorp/vault-ruby
lib/vault/response.rb
Vault.Response.to_h
def to_h self.class.fields.inject({}) do |h, (k, opts)| if opts[:as].nil? h[k] = self.public_send(k) else h[k] = self.public_send(opts[:as]) end if !h[k].nil? && !h[k].is_a?(Array) && h[k].respond_to?(:to_h) h[k] = h[k].to_h end h end end
ruby
def to_h self.class.fields.inject({}) do |h, (k, opts)| if opts[:as].nil? h[k] = self.public_send(k) else h[k] = self.public_send(opts[:as]) end if !h[k].nil? && !h[k].is_a?(Array) && h[k].respond_to?(:to_h) h[k] = h[k].to_h end h end end
[ "def", "to_h", "self", ".", "class", ".", "fields", ".", "inject", "(", "{", "}", ")", "do", "|", "h", ",", "(", "k", ",", "opts", ")", "|", "if", "opts", "[", ":as", "]", ".", "nil?", "h", "[", "k", "]", "=", "self", ".", "public_send", "(", "k", ")", "else", "h", "[", "k", "]", "=", "self", ".", "public_send", "(", "opts", "[", ":as", "]", ")", "end", "if", "!", "h", "[", "k", "]", ".", "nil?", "&&", "!", "h", "[", "k", "]", ".", "is_a?", "(", "Array", ")", "&&", "h", "[", "k", "]", ".", "respond_to?", "(", ":to_h", ")", "h", "[", "k", "]", "=", "h", "[", "k", "]", ".", "to_h", "end", "h", "end", "end" ]
Create a hash-bashed representation of this response. @return [Hash]
[ "Create", "a", "hash", "-", "bashed", "representation", "of", "this", "response", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/response.rb#L69-L83
11,461
hashicorp/vault-ruby
lib/vault/api/sys/init.rb
Vault.Sys.init
def init(options = {}) json = client.put("/v1/sys/init", JSON.fast_generate( root_token_pgp_key: options.fetch(:root_token_pgp_key, nil), secret_shares: options.fetch(:secret_shares, options.fetch(:shares, 5)), secret_threshold: options.fetch(:secret_threshold, options.fetch(:threshold, 3)), pgp_keys: options.fetch(:pgp_keys, nil), stored_shares: options.fetch(:stored_shares, nil), recovery_shares: options.fetch(:recovery_shares, nil), recovery_threshold: options.fetch(:recovery_threshold, nil), recovery_pgp_keys: options.fetch(:recovery_pgp_keys, nil), )) return InitResponse.decode(json) end
ruby
def init(options = {}) json = client.put("/v1/sys/init", JSON.fast_generate( root_token_pgp_key: options.fetch(:root_token_pgp_key, nil), secret_shares: options.fetch(:secret_shares, options.fetch(:shares, 5)), secret_threshold: options.fetch(:secret_threshold, options.fetch(:threshold, 3)), pgp_keys: options.fetch(:pgp_keys, nil), stored_shares: options.fetch(:stored_shares, nil), recovery_shares: options.fetch(:recovery_shares, nil), recovery_threshold: options.fetch(:recovery_threshold, nil), recovery_pgp_keys: options.fetch(:recovery_pgp_keys, nil), )) return InitResponse.decode(json) end
[ "def", "init", "(", "options", "=", "{", "}", ")", "json", "=", "client", ".", "put", "(", "\"/v1/sys/init\"", ",", "JSON", ".", "fast_generate", "(", "root_token_pgp_key", ":", "options", ".", "fetch", "(", ":root_token_pgp_key", ",", "nil", ")", ",", "secret_shares", ":", "options", ".", "fetch", "(", ":secret_shares", ",", "options", ".", "fetch", "(", ":shares", ",", "5", ")", ")", ",", "secret_threshold", ":", "options", ".", "fetch", "(", ":secret_threshold", ",", "options", ".", "fetch", "(", ":threshold", ",", "3", ")", ")", ",", "pgp_keys", ":", "options", ".", "fetch", "(", ":pgp_keys", ",", "nil", ")", ",", "stored_shares", ":", "options", ".", "fetch", "(", ":stored_shares", ",", "nil", ")", ",", "recovery_shares", ":", "options", ".", "fetch", "(", ":recovery_shares", ",", "nil", ")", ",", "recovery_threshold", ":", "options", ".", "fetch", "(", ":recovery_threshold", ",", "nil", ")", ",", "recovery_pgp_keys", ":", "options", ".", "fetch", "(", ":recovery_pgp_keys", ",", "nil", ")", ",", ")", ")", "return", "InitResponse", ".", "decode", "(", "json", ")", "end" ]
Initialize a new vault. @example Vault.sys.init #=> #<Vault::InitResponse keys=["..."] root_token="..."> @param [Hash] options the list of init options @option options [String] :root_token_pgp_key optional base64-encoded PGP public key used to encrypt the initial root token. @option options [Fixnum] :secret_shares the number of shares @option options [Fixnum] :secret_threshold the number of keys needed to unlock @option options [Array<String>] :pgp_keys an optional Array of base64-encoded PGP public keys to encrypt sharees @option options [Fixnum] :stored_shares the number of shares that should be encrypted by the HSM for auto-unsealing @option options [Fixnum] :recovery_shares the number of shares to split the recovery key into @option options [Fixnum] :recovery_threshold the number of shares required to reconstruct the recovery key @option options [Array<String>] :recovery_pgp_keys an array of PGP public keys used to encrypt the output for the recovery keys @return [InitResponse]
[ "Initialize", "a", "new", "vault", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/init.rb#L69-L81
11,462
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.set_role
def set_role(name, options = {}) headers = extract_headers!(options) client.post("/v1/auth/approle/role/#{encode_path(name)}", JSON.fast_generate(options), headers) return true end
ruby
def set_role(name, options = {}) headers = extract_headers!(options) client.post("/v1/auth/approle/role/#{encode_path(name)}", JSON.fast_generate(options), headers) return true end
[ "def", "set_role", "(", "name", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "client", ".", "post", "(", "\"/v1/auth/approle/role/#{encode_path(name)}\"", ",", "JSON", ".", "fast_generate", "(", "options", ")", ",", "headers", ")", "return", "true", "end" ]
Creates a new AppRole or update an existing AppRole with the given name and attributes. @example Vault.approle.set_role("testrole", { secret_id_ttl: "10m", token_ttl: "20m", policies: "default", period: 3600, }) #=> true @param [String] name The name of the AppRole @param [Hash] options @option options [Boolean] :bind_secret_id Require secret_id to be presented when logging in using this AppRole. @option options [String] :bound_cidr_list Comma-separated list of CIDR blocks. Specifies blocks of IP addresses which can perform the login operation. @option options [String] :policies Comma-separated list of policies set on tokens issued via this AppRole. @option options [String] :secret_id_num_uses Number of times any particular SecretID can be used to fetch a token from this AppRole, after which the SecretID will expire. @option options [Fixnum, String] :secret_id_ttl The number of seconds or a golang-formatted timestamp like "60m" after which any SecretID expires. @option options [Fixnum, String] :token_ttl The number of seconds or a golang-formatted timestamp like "60m" to set as the TTL for issued tokens and at renewal time. @option options [Fixnum, String] :token_max_ttl The number of seconds or a golang-formatted timestamp like "60m" after which the issued token can no longer be renewed. @option options [Fixnum, String] :period The number of seconds or a golang-formatted timestamp like "60m". If set, the token generated using this AppRole is a periodic token. So long as it is renewed it never expires, but the TTL set on the token at each renewal is fixed to the value specified here. If this value is modified, the token will pick up the new value at its next renewal. @return [true]
[ "Creates", "a", "new", "AppRole", "or", "update", "an", "existing", "AppRole", "with", "the", "given", "name", "and", "attributes", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L59-L63
11,463
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.role
def role(name) json = client.get("/v1/auth/approle/role/#{encode_path(name)}") return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
ruby
def role(name) json = client.get("/v1/auth/approle/role/#{encode_path(name)}") return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise end
[ "def", "role", "(", "name", ")", "json", "=", "client", ".", "get", "(", "\"/v1/auth/approle/role/#{encode_path(name)}\"", ")", "return", "Secret", ".", "decode", "(", "json", ")", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Gets the AppRole by the given name. If an AppRole does not exist by that name, +nil+ is returned. @example Vault.approle.role("testrole") #=> #<Vault::Secret lease_id="..."> @return [Secret, nil]
[ "Gets", "the", "AppRole", "by", "the", "given", "name", ".", "If", "an", "AppRole", "does", "not", "exist", "by", "that", "name", "+", "nil", "+", "is", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L72-L78
11,464
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.role_id
def role_id(name) json = client.get("/v1/auth/approle/role/#{encode_path(name)}/role-id") return Secret.decode(json).data[:role_id] rescue HTTPError => e return nil if e.code == 404 raise end
ruby
def role_id(name) json = client.get("/v1/auth/approle/role/#{encode_path(name)}/role-id") return Secret.decode(json).data[:role_id] rescue HTTPError => e return nil if e.code == 404 raise end
[ "def", "role_id", "(", "name", ")", "json", "=", "client", ".", "get", "(", "\"/v1/auth/approle/role/#{encode_path(name)}/role-id\"", ")", "return", "Secret", ".", "decode", "(", "json", ")", ".", "data", "[", ":role_id", "]", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Reads the RoleID of an existing AppRole. If an AppRole does not exist by that name, +nil+ is returned. @example Vault.approle.role_id("testrole") #=> #<Vault::Secret lease_id="..."> @return [Secret, nil]
[ "Reads", "the", "RoleID", "of", "an", "existing", "AppRole", ".", "If", "an", "AppRole", "does", "not", "exist", "by", "that", "name", "+", "nil", "+", "is", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L102-L108
11,465
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.set_role_id
def set_role_id(name, role_id) options = { role_id: role_id } client.post("/v1/auth/approle/role/#{encode_path(name)}/role-id", JSON.fast_generate(options)) return true end
ruby
def set_role_id(name, role_id) options = { role_id: role_id } client.post("/v1/auth/approle/role/#{encode_path(name)}/role-id", JSON.fast_generate(options)) return true end
[ "def", "set_role_id", "(", "name", ",", "role_id", ")", "options", "=", "{", "role_id", ":", "role_id", "}", "client", ".", "post", "(", "\"/v1/auth/approle/role/#{encode_path(name)}/role-id\"", ",", "JSON", ".", "fast_generate", "(", "options", ")", ")", "return", "true", "end" ]
Updates the RoleID of an existing AppRole to a custom value. @example Vault.approle.set_role_id("testrole") #=> true @return [true]
[ "Updates", "the", "RoleID", "of", "an", "existing", "AppRole", "to", "a", "custom", "value", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L116-L120
11,466
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.create_secret_id
def create_secret_id(role_name, options = {}) headers = extract_headers!(options) if options[:secret_id] json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/custom-secret-id", JSON.fast_generate(options), headers) else json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", JSON.fast_generate(options), headers) end return Secret.decode(json) end
ruby
def create_secret_id(role_name, options = {}) headers = extract_headers!(options) if options[:secret_id] json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/custom-secret-id", JSON.fast_generate(options), headers) else json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", JSON.fast_generate(options), headers) end return Secret.decode(json) end
[ "def", "create_secret_id", "(", "role_name", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "if", "options", "[", ":secret_id", "]", "json", "=", "client", ".", "post", "(", "\"/v1/auth/approle/role/#{encode_path(role_name)}/custom-secret-id\"", ",", "JSON", ".", "fast_generate", "(", "options", ")", ",", "headers", ")", "else", "json", "=", "client", ".", "post", "(", "\"/v1/auth/approle/role/#{encode_path(role_name)}/secret-id\"", ",", "JSON", ".", "fast_generate", "(", "options", ")", ",", "headers", ")", "end", "return", "Secret", ".", "decode", "(", "json", ")", "end" ]
Generates and issues a new SecretID on an existing AppRole. @example Generate a new SecretID result = Vault.approle.create_secret_id("testrole") #=> #<Vault::Secret lease_id="..."> result.data[:secret_id] #=> "841771dc-11c9-bbc7-bcac-6a3945a69cd9" @example Assign a custom SecretID result = Vault.approle.create_secret_id("testrole", { secret_id: "testsecretid" }) #=> #<Vault::Secret lease_id="..."> result.data[:secret_id] #=> "testsecretid" @param [String] role_name The name of the AppRole @param [Hash] options @option options [String] :secret_id SecretID to be attached to the Role. If not set, then the new SecretID will be generated @option options [Hash<String, String>] :metadata Metadata to be tied to the SecretID. This should be a JSON-formatted string containing the metadata in key-value pairs. It will be set on tokens issued with this SecretID, and is logged in audit logs in plaintext. @return [true]
[ "Generates", "and", "issues", "a", "new", "SecretID", "on", "an", "existing", "AppRole", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L160-L168
11,467
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.secret_id
def secret_id(role_name, secret_id) opts = { secret_id: secret_id } json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/lookup", JSON.fast_generate(opts), {}) return nil unless json return Secret.decode(json) rescue HTTPError => e if e.code == 404 || e.code == 405 begin json = client.get("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/#{encode_path(secret_id)}") return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise e end end raise end
ruby
def secret_id(role_name, secret_id) opts = { secret_id: secret_id } json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/lookup", JSON.fast_generate(opts), {}) return nil unless json return Secret.decode(json) rescue HTTPError => e if e.code == 404 || e.code == 405 begin json = client.get("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/#{encode_path(secret_id)}") return Secret.decode(json) rescue HTTPError => e return nil if e.code == 404 raise e end end raise end
[ "def", "secret_id", "(", "role_name", ",", "secret_id", ")", "opts", "=", "{", "secret_id", ":", "secret_id", "}", "json", "=", "client", ".", "post", "(", "\"/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/lookup\"", ",", "JSON", ".", "fast_generate", "(", "opts", ")", ",", "{", "}", ")", "return", "nil", "unless", "json", "return", "Secret", ".", "decode", "(", "json", ")", "rescue", "HTTPError", "=>", "e", "if", "e", ".", "code", "==", "404", "||", "e", ".", "code", "==", "405", "begin", "json", "=", "client", ".", "get", "(", "\"/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/#{encode_path(secret_id)}\"", ")", "return", "Secret", ".", "decode", "(", "json", ")", "rescue", "HTTPError", "=>", "e", "return", "nil", "if", "e", ".", "code", "==", "404", "raise", "e", "end", "end", "raise", "end" ]
Reads out the properties of a SecretID assigned to an AppRole. If the specified SecretID don't exist, +nil+ is returned. @example Vault.approle.role("testrole", "841771dc-11c9-...") #=> #<Vault::Secret lease_id="..."> @param [String] role_name The name of the AppRole @param [String] secret_id SecretID belonging to AppRole @return [Secret, nil]
[ "Reads", "out", "the", "properties", "of", "a", "SecretID", "assigned", "to", "an", "AppRole", ".", "If", "the", "specified", "SecretID", "don", "t", "exist", "+", "nil", "+", "is", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L182-L199
11,468
hashicorp/vault-ruby
lib/vault/api/approle.rb
Vault.AppRole.secret_id_accessors
def secret_id_accessors(role_name, options = {}) headers = extract_headers!(options) json = client.list("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", options, headers) return Secret.decode(json).data[:keys] || [] rescue HTTPError => e return [] if e.code == 404 raise end
ruby
def secret_id_accessors(role_name, options = {}) headers = extract_headers!(options) json = client.list("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", options, headers) return Secret.decode(json).data[:keys] || [] rescue HTTPError => e return [] if e.code == 404 raise end
[ "def", "secret_id_accessors", "(", "role_name", ",", "options", "=", "{", "}", ")", "headers", "=", "extract_headers!", "(", "options", ")", "json", "=", "client", ".", "list", "(", "\"/v1/auth/approle/role/#{encode_path(role_name)}/secret-id\"", ",", "options", ",", "headers", ")", "return", "Secret", ".", "decode", "(", "json", ")", ".", "data", "[", ":keys", "]", "||", "[", "]", "rescue", "HTTPError", "=>", "e", "return", "[", "]", "if", "e", ".", "code", "==", "404", "raise", "end" ]
Lists the accessors of all the SecretIDs issued against the AppRole. This includes the accessors for "custom" SecretIDs as well. If there are no SecretIDs against this role, an empty array will be returned. @example Vault.approle.secret_ids("testrole") #=> ["ce102d2a-...", "a1c8dee4-..."] @return [Array<String>]
[ "Lists", "the", "accessors", "of", "all", "the", "SecretIDs", "issued", "against", "the", "AppRole", ".", "This", "includes", "the", "accessors", "for", "custom", "SecretIDs", "as", "well", ".", "If", "there", "are", "no", "SecretIDs", "against", "this", "role", "an", "empty", "array", "will", "be", "returned", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/approle.rb#L209-L216
11,469
hashicorp/vault-ruby
lib/vault/encode.rb
Vault.EncodePath.encode_path
def encode_path(path) path.b.gsub(%r!([^a-zA-Z0-9_.-/]+)!) { |m| '%' + m.unpack('H2' * m.bytesize).join('%').upcase } end
ruby
def encode_path(path) path.b.gsub(%r!([^a-zA-Z0-9_.-/]+)!) { |m| '%' + m.unpack('H2' * m.bytesize).join('%').upcase } end
[ "def", "encode_path", "(", "path", ")", "path", ".", "b", ".", "gsub", "(", "%r!", "!", ")", "{", "|", "m", "|", "'%'", "+", "m", ".", "unpack", "(", "'H2'", "*", "m", ".", "bytesize", ")", ".", "join", "(", "'%'", ")", ".", "upcase", "}", "end" ]
Encodes a string according to the rules for URL paths. This is used as opposed to CGI.escape because in a URL path, space needs to be escaped as %20 and CGI.escapes a space as +. @param [String] @return [String]
[ "Encodes", "a", "string", "according", "to", "the", "rules", "for", "URL", "paths", ".", "This", "is", "used", "as", "opposed", "to", "CGI", ".", "escape", "because", "in", "a", "URL", "path", "space", "needs", "to", "be", "escaped", "as", "%20", "and", "CGI", ".", "escapes", "a", "space", "as", "+", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/encode.rb#L11-L15
11,470
hashicorp/vault-ruby
lib/vault/api/sys/mount.rb
Vault.Sys.mounts
def mounts json = client.get("/v1/sys/mounts") json = json[:data] if json[:data] return Hash[*json.map do |k,v| [k.to_s.chomp("/").to_sym, Mount.decode(v)] end.flatten] end
ruby
def mounts json = client.get("/v1/sys/mounts") json = json[:data] if json[:data] return Hash[*json.map do |k,v| [k.to_s.chomp("/").to_sym, Mount.decode(v)] end.flatten] end
[ "def", "mounts", "json", "=", "client", ".", "get", "(", "\"/v1/sys/mounts\"", ")", "json", "=", "json", "[", ":data", "]", "if", "json", "[", ":data", "]", "return", "Hash", "[", "json", ".", "map", "do", "|", "k", ",", "v", "|", "[", "k", ".", "to_s", ".", "chomp", "(", "\"/\"", ")", ".", "to_sym", ",", "Mount", ".", "decode", "(", "v", ")", "]", "end", ".", "flatten", "]", "end" ]
List all mounts in the vault. @example Vault.sys.mounts #=> { :secret => #<struct Vault::Mount type="generic", description="generic secret storage"> } @return [Hash<Symbol, Mount>]
[ "List", "all", "mounts", "in", "the", "vault", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/mount.rb#L28-L34
11,471
hashicorp/vault-ruby
lib/vault/api/sys/mount.rb
Vault.Sys.mount_tune
def mount_tune(path, data = {}) json = client.post("/v1/sys/mounts/#{encode_path(path)}/tune", JSON.fast_generate(data)) return true end
ruby
def mount_tune(path, data = {}) json = client.post("/v1/sys/mounts/#{encode_path(path)}/tune", JSON.fast_generate(data)) return true end
[ "def", "mount_tune", "(", "path", ",", "data", "=", "{", "}", ")", "json", "=", "client", ".", "post", "(", "\"/v1/sys/mounts/#{encode_path(path)}/tune\"", ",", "JSON", ".", "fast_generate", "(", "data", ")", ")", "return", "true", "end" ]
Tune a mount at the given path. @example Vault.sys.mount_tune("pki", max_lease_ttl: '87600h') #=> true @param [String] path the path to write @param [Hash] data the data to write
[ "Tune", "a", "mount", "at", "the", "given", "path", "." ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/mount.rb#L64-L67
11,472
hashicorp/vault-ruby
lib/vault/api/sys/mount.rb
Vault.Sys.remount
def remount(from, to) client.post("/v1/sys/remount", JSON.fast_generate( from: from, to: to, )) return true end
ruby
def remount(from, to) client.post("/v1/sys/remount", JSON.fast_generate( from: from, to: to, )) return true end
[ "def", "remount", "(", "from", ",", "to", ")", "client", ".", "post", "(", "\"/v1/sys/remount\"", ",", "JSON", ".", "fast_generate", "(", "from", ":", "from", ",", "to", ":", "to", ",", ")", ")", "return", "true", "end" ]
Change the name of the mount @example Vault.sys.remount("pg", "postgres") #=> true @param [String] from the origin mount path @param [String] to the new mount path @return [true]
[ "Change", "the", "name", "of", "the", "mount" ]
02f0532a802ba1a2a0d8703a4585dab76eb9d864
https://github.com/hashicorp/vault-ruby/blob/02f0532a802ba1a2a0d8703a4585dab76eb9d864/lib/vault/api/sys/mount.rb#L95-L101
11,473
colszowka/simplecov
lib/simplecov/configuration.rb
SimpleCov.Configuration.coverage_path
def coverage_path @coverage_path ||= begin coverage_path = File.expand_path(coverage_dir, root) FileUtils.mkdir_p coverage_path coverage_path end end
ruby
def coverage_path @coverage_path ||= begin coverage_path = File.expand_path(coverage_dir, root) FileUtils.mkdir_p coverage_path coverage_path end end
[ "def", "coverage_path", "@coverage_path", "||=", "begin", "coverage_path", "=", "File", ".", "expand_path", "(", "coverage_dir", ",", "root", ")", "FileUtils", ".", "mkdir_p", "coverage_path", "coverage_path", "end", "end" ]
Returns the full path to the output directory using SimpleCov.root and SimpleCov.coverage_dir, so you can adjust this by configuring those values. Will create the directory if it's missing
[ "Returns", "the", "full", "path", "to", "the", "output", "directory", "using", "SimpleCov", ".", "root", "and", "SimpleCov", ".", "coverage_dir", "so", "you", "can", "adjust", "this", "by", "configuring", "those", "values", ".", "Will", "create", "the", "directory", "if", "it", "s", "missing" ]
8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2
https://github.com/colszowka/simplecov/blob/8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2/lib/simplecov/configuration.rb#L42-L48
11,474
colszowka/simplecov
lib/simplecov/configuration.rb
SimpleCov.Configuration.at_exit
def at_exit(&block) return proc {} unless running || block_given? @at_exit = block if block_given? @at_exit ||= proc { SimpleCov.result.format! } end
ruby
def at_exit(&block) return proc {} unless running || block_given? @at_exit = block if block_given? @at_exit ||= proc { SimpleCov.result.format! } end
[ "def", "at_exit", "(", "&", "block", ")", "return", "proc", "{", "}", "unless", "running", "||", "block_given?", "@at_exit", "=", "block", "if", "block_given?", "@at_exit", "||=", "proc", "{", "SimpleCov", ".", "result", ".", "format!", "}", "end" ]
Gets or sets the behavior to process coverage results. By default, it will call SimpleCov.result.format! Configure with: SimpleCov.at_exit do puts "Coverage done" SimpleCov.result.format! end
[ "Gets", "or", "sets", "the", "behavior", "to", "process", "coverage", "results", "." ]
8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2
https://github.com/colszowka/simplecov/blob/8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2/lib/simplecov/configuration.rb#L179-L183
11,475
colszowka/simplecov
lib/simplecov/configuration.rb
SimpleCov.Configuration.project_name
def project_name(new_name = nil) return @project_name if defined?(@project_name) && @project_name && new_name.nil? @project_name = new_name if new_name.is_a?(String) @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ") end
ruby
def project_name(new_name = nil) return @project_name if defined?(@project_name) && @project_name && new_name.nil? @project_name = new_name if new_name.is_a?(String) @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ") end
[ "def", "project_name", "(", "new_name", "=", "nil", ")", "return", "@project_name", "if", "defined?", "(", "@project_name", ")", "&&", "@project_name", "&&", "new_name", ".", "nil?", "@project_name", "=", "new_name", "if", "new_name", ".", "is_a?", "(", "String", ")", "@project_name", "||=", "File", ".", "basename", "(", "root", ".", "split", "(", "\"/\"", ")", ".", "last", ")", ".", "capitalize", ".", "tr", "(", "\"_\"", ",", "\" \"", ")", "end" ]
Returns the project name - currently assuming the last dirname in the SimpleCov.root is this.
[ "Returns", "the", "project", "name", "-", "currently", "assuming", "the", "last", "dirname", "in", "the", "SimpleCov", ".", "root", "is", "this", "." ]
8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2
https://github.com/colszowka/simplecov/blob/8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2/lib/simplecov/configuration.rb#L189-L193
11,476
colszowka/simplecov
lib/simplecov/configuration.rb
SimpleCov.Configuration.parse_filter
def parse_filter(filter_argument = nil, &filter_proc) filter = filter_argument || filter_proc if filter SimpleCov::Filter.build_filter(filter) else raise ArgumentError, "Please specify either a filter or a block to filter with" end end
ruby
def parse_filter(filter_argument = nil, &filter_proc) filter = filter_argument || filter_proc if filter SimpleCov::Filter.build_filter(filter) else raise ArgumentError, "Please specify either a filter or a block to filter with" end end
[ "def", "parse_filter", "(", "filter_argument", "=", "nil", ",", "&", "filter_proc", ")", "filter", "=", "filter_argument", "||", "filter_proc", "if", "filter", "SimpleCov", "::", "Filter", ".", "build_filter", "(", "filter", ")", "else", "raise", "ArgumentError", ",", "\"Please specify either a filter or a block to filter with\"", "end", "end" ]
The actual filter processor. Not meant for direct use
[ "The", "actual", "filter", "processor", ".", "Not", "meant", "for", "direct", "use" ]
8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2
https://github.com/colszowka/simplecov/blob/8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2/lib/simplecov/configuration.rb#L295-L303
11,477
colszowka/simplecov
lib/simplecov/raw_coverage.rb
SimpleCov.RawCoverage.merge_resultsets
def merge_resultsets(result1, result2) (result1.keys | result2.keys).each_with_object({}) do |filename, merged| file1 = result1[filename] file2 = result2[filename] merged[filename] = merge_file_coverage(file1, file2) end end
ruby
def merge_resultsets(result1, result2) (result1.keys | result2.keys).each_with_object({}) do |filename, merged| file1 = result1[filename] file2 = result2[filename] merged[filename] = merge_file_coverage(file1, file2) end end
[ "def", "merge_resultsets", "(", "result1", ",", "result2", ")", "(", "result1", ".", "keys", "|", "result2", ".", "keys", ")", ".", "each_with_object", "(", "{", "}", ")", "do", "|", "filename", ",", "merged", "|", "file1", "=", "result1", "[", "filename", "]", "file2", "=", "result2", "[", "filename", "]", "merged", "[", "filename", "]", "=", "merge_file_coverage", "(", "file1", ",", "file2", ")", "end", "end" ]
Merges two Coverage.result hashes
[ "Merges", "two", "Coverage", ".", "result", "hashes" ]
8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2
https://github.com/colszowka/simplecov/blob/8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2/lib/simplecov/raw_coverage.rb#L15-L21
11,478
colszowka/simplecov
lib/simplecov/profiles.rb
SimpleCov.Profiles.load
def load(name) name = name.to_sym raise "Could not find SimpleCov Profile called '#{name}'" unless key?(name) SimpleCov.configure(&self[name]) end
ruby
def load(name) name = name.to_sym raise "Could not find SimpleCov Profile called '#{name}'" unless key?(name) SimpleCov.configure(&self[name]) end
[ "def", "load", "(", "name", ")", "name", "=", "name", ".", "to_sym", "raise", "\"Could not find SimpleCov Profile called '#{name}'\"", "unless", "key?", "(", "name", ")", "SimpleCov", ".", "configure", "(", "self", "[", "name", "]", ")", "end" ]
Applies the profile of given name on SimpleCov.configure
[ "Applies", "the", "profile", "of", "given", "name", "on", "SimpleCov", ".", "configure" ]
8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2
https://github.com/colszowka/simplecov/blob/8f6978a2513f10c4dd8d7dd7eed666fe3f2b55c2/lib/simplecov/profiles.rb#L27-L31
11,479
troessner/reek
lib/reek/documentation_link.rb
Reek.DocumentationLink.build
def build(subject) Kernel.format(HELP_LINK_TEMPLATE, version: Version::STRING, item: name_to_param(subject)) end
ruby
def build(subject) Kernel.format(HELP_LINK_TEMPLATE, version: Version::STRING, item: name_to_param(subject)) end
[ "def", "build", "(", "subject", ")", "Kernel", ".", "format", "(", "HELP_LINK_TEMPLATE", ",", "version", ":", "Version", "::", "STRING", ",", "item", ":", "name_to_param", "(", "subject", ")", ")", "end" ]
Build link to the documentation about the given subject for the current version of Reek. The subject can be either a smell type like 'FeatureEnvy' or a general subject like 'Rake Task'. @param subject [String] @return [String] the full URL for the relevant documentation
[ "Build", "link", "to", "the", "documentation", "about", "the", "given", "subject", "for", "the", "current", "version", "of", "Reek", ".", "The", "subject", "can", "be", "either", "a", "smell", "type", "like", "FeatureEnvy", "or", "a", "general", "subject", "like", "Rake", "Task", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/documentation_link.rb#L16-L18
11,480
troessner/reek
samples/smelly_source/inline.rb
Inline.C.load_cache
def load_cache begin file = File.join("inline", File.basename(so_name)) if require file then dir = Inline.directory warn "WAR\NING: #{dir} exists but is not being used" if test ?d, dir and $VERBOSE return true end rescue LoadError end return false end
ruby
def load_cache begin file = File.join("inline", File.basename(so_name)) if require file then dir = Inline.directory warn "WAR\NING: #{dir} exists but is not being used" if test ?d, dir and $VERBOSE return true end rescue LoadError end return false end
[ "def", "load_cache", "begin", "file", "=", "File", ".", "join", "(", "\"inline\"", ",", "File", ".", "basename", "(", "so_name", ")", ")", "if", "require", "file", "then", "dir", "=", "Inline", ".", "directory", "warn", "\"WAR\\NING: #{dir} exists but is not being used\"", "if", "test", "?d", ",", "dir", "and", "$VERBOSE", "return", "true", "end", "rescue", "LoadError", "end", "return", "false", "end" ]
Attempts to load pre-generated code returning true if it succeeds.
[ "Attempts", "to", "load", "pre", "-", "generated", "code", "returning", "true", "if", "it", "succeeds", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/samples/smelly_source/inline.rb#L315-L326
11,481
troessner/reek
samples/smelly_source/inline.rb
Inline.C.add_type_converter
def add_type_converter(type, r2c, c2r) warn "WAR\NING: overridding #{type} on #{caller[0]}" if @@type_map.has_key? type @@type_map[type] = [r2c, c2r] end
ruby
def add_type_converter(type, r2c, c2r) warn "WAR\NING: overridding #{type} on #{caller[0]}" if @@type_map.has_key? type @@type_map[type] = [r2c, c2r] end
[ "def", "add_type_converter", "(", "type", ",", "r2c", ",", "c2r", ")", "warn", "\"WAR\\NING: overridding #{type} on #{caller[0]}\"", "if", "@@type_map", ".", "has_key?", "type", "@@type_map", "[", "type", "]", "=", "[", "r2c", ",", "c2r", "]", "end" ]
Registers C type-casts +r2c+ and +c2r+ for +type+.
[ "Registers", "C", "type", "-", "casts", "+", "r2c", "+", "and", "+", "c2r", "+", "for", "+", "type", "+", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/samples/smelly_source/inline.rb#L520-L523
11,482
troessner/reek
samples/smelly_source/inline.rb
Inline.C.c
def c src, options = {} options = { :expand_types => true, }.merge options self.generate src, options end
ruby
def c src, options = {} options = { :expand_types => true, }.merge options self.generate src, options end
[ "def", "c", "src", ",", "options", "=", "{", "}", "options", "=", "{", ":expand_types", "=>", "true", ",", "}", ".", "merge", "options", "self", ".", "generate", "src", ",", "options", "end" ]
Adds a C function to the source, including performing automatic type conversion to arguments and the return value. The Ruby method name can be overridden by providing method_name. Unknown type conversions can be extended by using +add_type_converter+.
[ "Adds", "a", "C", "function", "to", "the", "source", "including", "performing", "automatic", "type", "conversion", "to", "arguments", "and", "the", "return", "value", ".", "The", "Ruby", "method", "name", "can", "be", "overridden", "by", "providing", "method_name", ".", "Unknown", "type", "conversions", "can", "be", "extended", "by", "using", "+", "add_type_converter", "+", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/samples/smelly_source/inline.rb#L575-L580
11,483
troessner/reek
samples/smelly_source/inline.rb
Inline.C.c_singleton
def c_singleton src, options = {} options = { :expand_types => true, :singleton => true, }.merge options self.generate src, options end
ruby
def c_singleton src, options = {} options = { :expand_types => true, :singleton => true, }.merge options self.generate src, options end
[ "def", "c_singleton", "src", ",", "options", "=", "{", "}", "options", "=", "{", ":expand_types", "=>", "true", ",", ":singleton", "=>", "true", ",", "}", ".", "merge", "options", "self", ".", "generate", "src", ",", "options", "end" ]
Same as +c+, but adds a class function.
[ "Same", "as", "+", "c", "+", "but", "adds", "a", "class", "function", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/samples/smelly_source/inline.rb#L585-L591
11,484
troessner/reek
samples/smelly_source/inline.rb
Inline.C.c_raw_singleton
def c_raw_singleton src, options = {} options = { :singleton => true, }.merge options self.generate src, options end
ruby
def c_raw_singleton src, options = {} options = { :singleton => true, }.merge options self.generate src, options end
[ "def", "c_raw_singleton", "src", ",", "options", "=", "{", "}", "options", "=", "{", ":singleton", "=>", "true", ",", "}", ".", "merge", "options", "self", ".", "generate", "src", ",", "options", "end" ]
Same as +c_raw+, but adds a class function.
[ "Same", "as", "+", "c_raw", "+", "but", "adds", "a", "class", "function", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/samples/smelly_source/inline.rb#L606-L611
11,485
troessner/reek
lib/reek/spec.rb
Reek.Spec.reek_of
def reek_of(smell_type, smell_details = {}, configuration = Configuration::AppConfiguration.default) ShouldReekOf.new(smell_type, smell_details, configuration) end
ruby
def reek_of(smell_type, smell_details = {}, configuration = Configuration::AppConfiguration.default) ShouldReekOf.new(smell_type, smell_details, configuration) end
[ "def", "reek_of", "(", "smell_type", ",", "smell_details", "=", "{", "}", ",", "configuration", "=", "Configuration", "::", "AppConfiguration", ".", "default", ")", "ShouldReekOf", ".", "new", "(", "smell_type", ",", "smell_details", ",", "configuration", ")", "end" ]
Checks the target source code for instances of "smell type" and returns true only if it can find one of them that matches. You can pass the smell type you want to check for as String or as Symbol: - :UtilityFunction - "UtilityFunction" It is recommended to pass this as a symbol like :UtilityFunction. However we don't enforce this. Additionally you can be more specific and pass in "smell_details" you want to check for as well e.g. "name" or "count" (see the examples below). The parameters you can check for are depending on the smell you are checking for. For instance "count" doesn't make sense everywhere whereas "name" does in most cases. If you pass in a parameter that doesn't exist (e.g. you make a typo like "namme") Reek will raise an ArgumentError to give you a hint that you passed something that doesn't make much sense. @param smell_type [Symbol, String] The "smell type" to check for. @param smell_details [Hash] A hash containing "smell warning" parameters @example Without smell_details reek_of(:FeatureEnvy) reek_of(:UtilityFunction) @example With smell_details reek_of(:UncommunicativeParameterName, name: 'x2') reek_of(:DataClump, count: 3) @example From a real spec expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing') @public @quality :reek:UtilityFunction
[ "Checks", "the", "target", "source", "code", "for", "instances", "of", "smell", "type", "and", "returns", "true", "only", "if", "it", "can", "find", "one", "of", "them", "that", "matches", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/spec.rb#L88-L92
11,486
troessner/reek
lib/reek/spec.rb
Reek.Spec.reek_only_of
def reek_only_of(smell_type, configuration = Configuration::AppConfiguration.default) ShouldReekOnlyOf.new(smell_type, configuration) end
ruby
def reek_only_of(smell_type, configuration = Configuration::AppConfiguration.default) ShouldReekOnlyOf.new(smell_type, configuration) end
[ "def", "reek_only_of", "(", "smell_type", ",", "configuration", "=", "Configuration", "::", "AppConfiguration", ".", "default", ")", "ShouldReekOnlyOf", ".", "new", "(", "smell_type", ",", "configuration", ")", "end" ]
See the documentaton for "reek_of". Notable differences to reek_of: 1.) "reek_of" doesn't mind if there are other smells of a different type. "reek_only_of" will fail in that case. 2.) "reek_only_of" doesn't support the additional smell_details hash. @param smell_type [Symbol, String] The "smell type" to check for. @public @quality :reek:UtilityFunction
[ "See", "the", "documentaton", "for", "reek_of", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/spec.rb#L107-L109
11,487
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.build
def build(exp, parent_exp = nil) context_processor = "process_#{exp.type}" if context_processor_exists?(context_processor) send(context_processor, exp, parent_exp) else process exp end current_context end
ruby
def build(exp, parent_exp = nil) context_processor = "process_#{exp.type}" if context_processor_exists?(context_processor) send(context_processor, exp, parent_exp) else process exp end current_context end
[ "def", "build", "(", "exp", ",", "parent_exp", "=", "nil", ")", "context_processor", "=", "\"process_#{exp.type}\"", "if", "context_processor_exists?", "(", "context_processor", ")", "send", "(", "context_processor", ",", "exp", ",", "parent_exp", ")", "else", "process", "exp", "end", "current_context", "end" ]
Processes the given AST, memoizes it and returns a tree of nested contexts. For example this ruby code: class Car; def drive; end; end would get compiled into this AST: (class (const nil :Car) nil (def :drive (args) nil)) Processing this AST would result in a context tree where each node contains the outer context, the AST and the child contexts. The top node is always Reek::Context::RootContext. Using the example above, the tree would look like this: RootContext -> children: 1 ModuleContext -> children: 1 MethodContext @return [Reek::Context::RootContext] tree of nested contexts
[ "Processes", "the", "given", "AST", "memoizes", "it", "and", "returns", "a", "tree", "of", "nested", "contexts", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L62-L70
11,488
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.process
def process(exp) exp.children.grep(AST::Node).each { |child| build(child, exp) } end
ruby
def process(exp) exp.children.grep(AST::Node).each { |child| build(child, exp) } end
[ "def", "process", "(", "exp", ")", "exp", ".", "children", ".", "grep", "(", "AST", "::", "Node", ")", ".", "each", "{", "|", "child", "|", "build", "(", "child", ",", "exp", ")", "}", "end" ]
Handles every node for which we have no context_processor.
[ "Handles", "every", "node", "for", "which", "we", "have", "no", "context_processor", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L74-L76
11,489
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.process_def
def process_def(exp, parent) inside_new_context(current_context.method_context_class, exp, parent) do increase_statement_count_by(exp.body) process(exp) end end
ruby
def process_def(exp, parent) inside_new_context(current_context.method_context_class, exp, parent) do increase_statement_count_by(exp.body) process(exp) end end
[ "def", "process_def", "(", "exp", ",", "parent", ")", "inside_new_context", "(", "current_context", ".", "method_context_class", ",", "exp", ",", "parent", ")", "do", "increase_statement_count_by", "(", "exp", ".", "body", ")", "process", "(", "exp", ")", "end", "end" ]
Handles `def` nodes. An input example that would trigger this method would be: def call_me; foo = 2; bar = 5; end Given the above example we would count 2 statements overall.
[ "Handles", "def", "nodes", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L123-L128
11,490
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.process_send
def process_send(exp, _parent) process(exp) case current_context when Context::ModuleContext handle_send_for_modules exp when Context::MethodContext handle_send_for_methods exp end end
ruby
def process_send(exp, _parent) process(exp) case current_context when Context::ModuleContext handle_send_for_modules exp when Context::MethodContext handle_send_for_methods exp end end
[ "def", "process_send", "(", "exp", ",", "_parent", ")", "process", "(", "exp", ")", "case", "current_context", "when", "Context", "::", "ModuleContext", "handle_send_for_modules", "exp", "when", "Context", "::", "MethodContext", "handle_send_for_methods", "exp", "end", "end" ]
Handles `send` nodes a.k.a. method calls. An input example that would trigger this method would be: call_me() Besides checking if it's a visibility modifier or an attribute writer we also record to what the method call is referring to which we later use for smell detectors like FeatureEnvy.
[ "Handles", "send", "nodes", "a", ".", "k", ".", "a", ".", "method", "calls", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L155-L163
11,491
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.process_if
def process_if(exp, _parent) children = exp.children increase_statement_count_by(children[1]) increase_statement_count_by(children[2]) decrease_statement_count process(exp) end
ruby
def process_if(exp, _parent) children = exp.children increase_statement_count_by(children[1]) increase_statement_count_by(children[2]) decrease_statement_count process(exp) end
[ "def", "process_if", "(", "exp", ",", "_parent", ")", "children", "=", "exp", ".", "children", "increase_statement_count_by", "(", "children", "[", "1", "]", ")", "increase_statement_count_by", "(", "children", "[", "2", "]", ")", "decrease_statement_count", "process", "(", "exp", ")", "end" ]
Handles `if` nodes. An input example that would trigger this method would be: if a > 5 && b < 3 puts 'bingo' else 3 end Counts the `if` body as one statement and the `else` body as another statement. At the end we subtract one statement because the surrounding context was already counted as one (e.g. via `process_def`). `children[1]` refers to the `if` body (so `puts 'bingo'` from above) and `children[2]` to the `else` body (so `3` from above), which might be nil.
[ "Handles", "if", "nodes", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L312-L318
11,492
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.process_rescue
def process_rescue(exp, _parent) increase_statement_count_by(exp.children.first) decrease_statement_count process(exp) end
ruby
def process_rescue(exp, _parent) increase_statement_count_by(exp.children.first) decrease_statement_count process(exp) end
[ "def", "process_rescue", "(", "exp", ",", "_parent", ")", "increase_statement_count_by", "(", "exp", ".", "children", ".", "first", ")", "decrease_statement_count", "process", "(", "exp", ")", "end" ]
Handles `rescue` nodes. An input example that would trigger this method would be: def simple raise ArgumentError, 'raising...' rescue => e puts 'rescued!' end Counts everything before the `rescue` body as one statement. At the end we subtract one statement because the surrounding context was already counted as one (e.g. via `process_def`). `exp.children.first` below refers to everything before the actual `rescue` which would be the raise ArgumentError, 'raising...' in the example above. `exp` would be the whole method body wrapped under a `rescue` node. See `process_resbody` for additional reference.
[ "Handles", "rescue", "nodes", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L388-L392
11,493
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.inside_new_context
def inside_new_context(klass, *args) new_context = append_new_context(klass, *args) orig, self.current_context = current_context, new_context yield self.current_context = orig end
ruby
def inside_new_context(klass, *args) new_context = append_new_context(klass, *args) orig, self.current_context = current_context, new_context yield self.current_context = orig end
[ "def", "inside_new_context", "(", "klass", ",", "*", "args", ")", "new_context", "=", "append_new_context", "(", "klass", ",", "args", ")", "orig", ",", "self", ".", "current_context", "=", "current_context", ",", "new_context", "yield", "self", ".", "current_context", "=", "orig", "end" ]
Stores a reference to the current context, creates a nested new one, yields to the given block and then restores the previous context. @param klass [Context::*Context] context class @param args arguments for the class initializer @yield block
[ "Stores", "a", "reference", "to", "the", "current", "context", "creates", "a", "nested", "new", "one", "yields", "to", "the", "given", "block", "and", "then", "restores", "the", "previous", "context", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L489-L495
11,494
troessner/reek
lib/reek/context_builder.rb
Reek.ContextBuilder.append_new_context
def append_new_context(klass, *args) klass.new(*args).tap do |new_context| new_context.register_with_parent(current_context) end end
ruby
def append_new_context(klass, *args) klass.new(*args).tap do |new_context| new_context.register_with_parent(current_context) end end
[ "def", "append_new_context", "(", "klass", ",", "*", "args", ")", "klass", ".", "new", "(", "args", ")", ".", "tap", "do", "|", "new_context", "|", "new_context", ".", "register_with_parent", "(", "current_context", ")", "end", "end" ]
Appends a new child context to the current context but does not change the current context. @param klass [Context::*Context] context class @param args arguments for the class initializer @return [Context::*Context] the context that was appended
[ "Appends", "a", "new", "child", "context", "to", "the", "current", "context", "but", "does", "not", "change", "the", "current", "context", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/context_builder.rb#L505-L509
11,495
troessner/reek
lib/reek/smell_configuration.rb
Reek.SmellConfiguration.value
def value(key, context) overrides_for(context).each { |conf| return conf[key] if conf.key?(key) } options.fetch(key) end
ruby
def value(key, context) overrides_for(context).each { |conf| return conf[key] if conf.key?(key) } options.fetch(key) end
[ "def", "value", "(", "key", ",", "context", ")", "overrides_for", "(", "context", ")", ".", "each", "{", "|", "conf", "|", "return", "conf", "[", "key", "]", "if", "conf", ".", "key?", "(", "key", ")", "}", "options", ".", "fetch", "(", "key", ")", "end" ]
Retrieves the value, if any, for the given +key+ in the given +context+. Raises an error if neither the context nor this config have a value for the key.
[ "Retrieves", "the", "value", "if", "any", "for", "the", "given", "+", "key", "+", "in", "the", "given", "+", "context", "+", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/smell_configuration.rb#L37-L40
11,496
troessner/reek
lib/reek/smell_configuration.rb
Reek.Overrides.for_context
def for_context(context) contexts = hash.keys.select { |ckey| context.matches?([ckey]) } contexts.map { |exc| hash[exc] } end
ruby
def for_context(context) contexts = hash.keys.select { |ckey| context.matches?([ckey]) } contexts.map { |exc| hash[exc] } end
[ "def", "for_context", "(", "context", ")", "contexts", "=", "hash", ".", "keys", ".", "select", "{", "|", "ckey", "|", "context", ".", "matches?", "(", "[", "ckey", "]", ")", "}", "contexts", ".", "map", "{", "|", "exc", "|", "hash", "[", "exc", "]", "}", "end" ]
Find any overrides that match the supplied context
[ "Find", "any", "overrides", "that", "match", "the", "supplied", "context" ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/smell_configuration.rb#L56-L59
11,497
troessner/reek
lib/reek/tree_dresser.rb
Reek.TreeDresser.dress
def dress(sexp, comment_map) return sexp unless sexp.is_a? ::Parser::AST::Node type = sexp.type children = sexp.children.map { |child| dress(child, comment_map) } comments = comment_map[sexp] klass_map.klass_for(type).new(type, children, location: sexp.loc, comments: comments) end
ruby
def dress(sexp, comment_map) return sexp unless sexp.is_a? ::Parser::AST::Node type = sexp.type children = sexp.children.map { |child| dress(child, comment_map) } comments = comment_map[sexp] klass_map.klass_for(type).new(type, children, location: sexp.loc, comments: comments) end
[ "def", "dress", "(", "sexp", ",", "comment_map", ")", "return", "sexp", "unless", "sexp", ".", "is_a?", "::", "Parser", "::", "AST", "::", "Node", "type", "=", "sexp", ".", "type", "children", "=", "sexp", ".", "children", ".", "map", "{", "|", "child", "|", "dress", "(", "child", ",", "comment_map", ")", "}", "comments", "=", "comment_map", "[", "sexp", "]", "klass_map", ".", "klass_for", "(", "type", ")", ".", "new", "(", "type", ",", "children", ",", "location", ":", "sexp", ".", "loc", ",", "comments", ":", "comments", ")", "end" ]
Recursively enhance an AST with type-dependent mixins, and comments. See {file:docs/How-reek-works-internally.md} for the big picture of how this works. Example: This class Klazz; def meth(argument); argument.call_me; end; end corresponds to this sexp: (class (const nil :Klazz) nil (def :meth (args (arg :argument)) (send (lvar :argument) :call_me))) where every node is of type Parser::AST::Node. Passing this into `dress` will return the exact same structure, but this time the nodes will contain type-dependent mixins, e.g. this: (const nil :Klazz) will be of type Reek::AST::Node with Reek::AST::SexpExtensions::ConstNode mixed in. @param sexp [Parser::AST::Node] the given sexp @param comment_map [Hash] see the documentation for SourceCode#syntax_tree @return an instance of Reek::AST::Node with type-dependent sexp extensions mixed in. @quality :reek:FeatureEnvy @quality :reek:TooManyStatements { max_statements: 6 }
[ "Recursively", "enhance", "an", "AST", "with", "type", "-", "dependent", "mixins", "and", "comments", "." ]
8c6b5c0c6228a6981ab48543457889f9ea984054
https://github.com/troessner/reek/blob/8c6b5c0c6228a6981ab48543457889f9ea984054/lib/reek/tree_dresser.rb#L42-L50
11,498
uken/fluent-plugin-elasticsearch
lib/fluent/plugin/out_elasticsearch.rb
Fluent::Plugin.ElasticsearchOutput.append_record_to_messages
def append_record_to_messages(op, meta, header, record, msgs) case op when UPDATE_OP, UPSERT_OP if meta.has_key?(ID_FIELD) header[UPDATE_OP] = meta msgs << @dump_proc.call(header) << BODY_DELIMITER msgs << @dump_proc.call(update_body(record, op)) << BODY_DELIMITER return true end when CREATE_OP if meta.has_key?(ID_FIELD) header[CREATE_OP] = meta msgs << @dump_proc.call(header) << BODY_DELIMITER msgs << @dump_proc.call(record) << BODY_DELIMITER return true end when INDEX_OP header[INDEX_OP] = meta msgs << @dump_proc.call(header) << BODY_DELIMITER msgs << @dump_proc.call(record) << BODY_DELIMITER return true end return false end
ruby
def append_record_to_messages(op, meta, header, record, msgs) case op when UPDATE_OP, UPSERT_OP if meta.has_key?(ID_FIELD) header[UPDATE_OP] = meta msgs << @dump_proc.call(header) << BODY_DELIMITER msgs << @dump_proc.call(update_body(record, op)) << BODY_DELIMITER return true end when CREATE_OP if meta.has_key?(ID_FIELD) header[CREATE_OP] = meta msgs << @dump_proc.call(header) << BODY_DELIMITER msgs << @dump_proc.call(record) << BODY_DELIMITER return true end when INDEX_OP header[INDEX_OP] = meta msgs << @dump_proc.call(header) << BODY_DELIMITER msgs << @dump_proc.call(record) << BODY_DELIMITER return true end return false end
[ "def", "append_record_to_messages", "(", "op", ",", "meta", ",", "header", ",", "record", ",", "msgs", ")", "case", "op", "when", "UPDATE_OP", ",", "UPSERT_OP", "if", "meta", ".", "has_key?", "(", "ID_FIELD", ")", "header", "[", "UPDATE_OP", "]", "=", "meta", "msgs", "<<", "@dump_proc", ".", "call", "(", "header", ")", "<<", "BODY_DELIMITER", "msgs", "<<", "@dump_proc", ".", "call", "(", "update_body", "(", "record", ",", "op", ")", ")", "<<", "BODY_DELIMITER", "return", "true", "end", "when", "CREATE_OP", "if", "meta", ".", "has_key?", "(", "ID_FIELD", ")", "header", "[", "CREATE_OP", "]", "=", "meta", "msgs", "<<", "@dump_proc", ".", "call", "(", "header", ")", "<<", "BODY_DELIMITER", "msgs", "<<", "@dump_proc", ".", "call", "(", "record", ")", "<<", "BODY_DELIMITER", "return", "true", "end", "when", "INDEX_OP", "header", "[", "INDEX_OP", "]", "=", "meta", "msgs", "<<", "@dump_proc", ".", "call", "(", "header", ")", "<<", "BODY_DELIMITER", "msgs", "<<", "@dump_proc", ".", "call", "(", "record", ")", "<<", "BODY_DELIMITER", "return", "true", "end", "return", "false", "end" ]
append_record_to_messages adds a record to the bulk message payload to be submitted to Elasticsearch. Records that do not include '_id' field are skipped when 'write_operation' is configured for 'create' or 'update' returns 'true' if record was appended to the bulk message and 'false' otherwise
[ "append_record_to_messages", "adds", "a", "record", "to", "the", "bulk", "message", "payload", "to", "be", "submitted", "to", "Elasticsearch", ".", "Records", "that", "do", "not", "include", "_id", "field", "are", "skipped", "when", "write_operation", "is", "configured", "for", "create", "or", "update" ]
9f9e51ddd012acb36c7f9d7a16e00970004098bc
https://github.com/uken/fluent-plugin-elasticsearch/blob/9f9e51ddd012acb36c7f9d7a16e00970004098bc/lib/fluent/plugin/out_elasticsearch.rb#L492-L515
11,499
uken/fluent-plugin-elasticsearch
lib/fluent/plugin/out_elasticsearch.rb
Fluent::Plugin.ElasticsearchOutput.send_bulk
def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info) begin log.on_trace { log.trace "bulk request: #{data}" } response = client(info.host).bulk body: data, index: info.index log.on_trace { log.trace "bulk response: #{response}" } if response['errors'] error = Fluent::Plugin::ElasticsearchErrorHandler.new(self) error.handle_error(response, tag, chunk, bulk_message_count, extracted_values) end rescue RetryStreamError => e emit_tag = @retry_tag ? @retry_tag : tag router.emit_stream(emit_tag, e.retry_stream) rescue => e ignore = @ignore_exception_classes.any? { |clazz| e.class <= clazz } log.warn "Exception ignored in tag #{tag}: #{e.class.name} #{e.message}" if ignore @_es = nil if @reconnect_on_error @_es_info = nil if @reconnect_on_error raise UnrecoverableRequestFailure if ignore && @exception_backup # FIXME: identify unrecoverable errors and raise UnrecoverableRequestFailure instead raise RecoverableRequestFailure, "could not push logs to Elasticsearch cluster (#{connection_options_description(info.host)}): #{e.message}" unless ignore end end
ruby
def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info) begin log.on_trace { log.trace "bulk request: #{data}" } response = client(info.host).bulk body: data, index: info.index log.on_trace { log.trace "bulk response: #{response}" } if response['errors'] error = Fluent::Plugin::ElasticsearchErrorHandler.new(self) error.handle_error(response, tag, chunk, bulk_message_count, extracted_values) end rescue RetryStreamError => e emit_tag = @retry_tag ? @retry_tag : tag router.emit_stream(emit_tag, e.retry_stream) rescue => e ignore = @ignore_exception_classes.any? { |clazz| e.class <= clazz } log.warn "Exception ignored in tag #{tag}: #{e.class.name} #{e.message}" if ignore @_es = nil if @reconnect_on_error @_es_info = nil if @reconnect_on_error raise UnrecoverableRequestFailure if ignore && @exception_backup # FIXME: identify unrecoverable errors and raise UnrecoverableRequestFailure instead raise RecoverableRequestFailure, "could not push logs to Elasticsearch cluster (#{connection_options_description(info.host)}): #{e.message}" unless ignore end end
[ "def", "send_bulk", "(", "data", ",", "tag", ",", "chunk", ",", "bulk_message_count", ",", "extracted_values", ",", "info", ")", "begin", "log", ".", "on_trace", "{", "log", ".", "trace", "\"bulk request: #{data}\"", "}", "response", "=", "client", "(", "info", ".", "host", ")", ".", "bulk", "body", ":", "data", ",", "index", ":", "info", ".", "index", "log", ".", "on_trace", "{", "log", ".", "trace", "\"bulk response: #{response}\"", "}", "if", "response", "[", "'errors'", "]", "error", "=", "Fluent", "::", "Plugin", "::", "ElasticsearchErrorHandler", ".", "new", "(", "self", ")", "error", ".", "handle_error", "(", "response", ",", "tag", ",", "chunk", ",", "bulk_message_count", ",", "extracted_values", ")", "end", "rescue", "RetryStreamError", "=>", "e", "emit_tag", "=", "@retry_tag", "?", "@retry_tag", ":", "tag", "router", ".", "emit_stream", "(", "emit_tag", ",", "e", ".", "retry_stream", ")", "rescue", "=>", "e", "ignore", "=", "@ignore_exception_classes", ".", "any?", "{", "|", "clazz", "|", "e", ".", "class", "<=", "clazz", "}", "log", ".", "warn", "\"Exception ignored in tag #{tag}: #{e.class.name} #{e.message}\"", "if", "ignore", "@_es", "=", "nil", "if", "@reconnect_on_error", "@_es_info", "=", "nil", "if", "@reconnect_on_error", "raise", "UnrecoverableRequestFailure", "if", "ignore", "&&", "@exception_backup", "# FIXME: identify unrecoverable errors and raise UnrecoverableRequestFailure instead", "raise", "RecoverableRequestFailure", ",", "\"could not push logs to Elasticsearch cluster (#{connection_options_description(info.host)}): #{e.message}\"", "unless", "ignore", "end", "end" ]
send_bulk given a specific bulk request, the original tag, chunk, and bulk_message_count
[ "send_bulk", "given", "a", "specific", "bulk", "request", "the", "original", "tag", "chunk", "and", "bulk_message_count" ]
9f9e51ddd012acb36c7f9d7a16e00970004098bc
https://github.com/uken/fluent-plugin-elasticsearch/blob/9f9e51ddd012acb36c7f9d7a16e00970004098bc/lib/fluent/plugin/out_elasticsearch.rb#L709-L736