Module: NexusCli::N3Metadata

Defined in:
lib/nexus_cli/n3_metadata.rb

Class Method Summary collapse

Class Method Details

.convert_result_to_hash(custom_metadata) ⇒ Object

Parses the regular custom metadata xml into a hash containing only the custom metadata.



44
45
46
47
48
49
50
51
# File 'lib/nexus_cli/n3_metadata.rb', line 44

def convert_result_to_hash()
  request = {}
  document = REXML::Document.new()
  REXML::XPath.each(document, "//customMetadataResponse/data/customMetadata[namespace=\"urn:nexus/user#\"]") do |row|
    request[row.elements["key"].text.strip] = row.elements["value"].text.strip
  end
  request
end

.convert_result_to_simple_xml(custom_metadata) ⇒ Object

Parses the regular custom metadata xml into a simpler format containing only the custom metadata.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nexus_cli/n3_metadata.rb', line 29

def convert_result_to_simple_xml()
  request = []
  document = REXML::Document.new()
  REXML::XPath.each(document, "//customMetadataResponse/data/customMetadata[namespace=\"urn:nexus/user#\"]") do |row|
    request.push(create_tag(row.elements["key"].text.strip, row.elements["value"].text.strip))
  end
  formatter = REXML::Formatters::Pretty.new(4)
  formatter.compact = true
  document = REXML::Document.new("<artifact-resolution><data>#{request.join}</data></artifact-resolution>")
  out = ""
  formatter.write(document, out)
  out
end

.create_base64_subject(artifact) ⇒ Object

Creates a custom metadata subject for HTTP requests.



24
25
26
# File 'lib/nexus_cli/n3_metadata.rb', line 24

def create_base64_subject(artifact)
  return Base64.urlsafe_encode64("urn:maven/artifact##{artifact.group_id}:#{artifact.artifact_id}:#{artifact.version}::#{artifact.extension}")
end

.create_metadata_hash(source, target = {}) ⇒ Object

Create the request from the specified list of custom metadata key:value pairs

Parameters:

  • source (Hash)

    The source hash of custom metadata key:value pairs

  • target (Hash) (defaults to: {})

    The target hash to merge with the source hash (optional)



58
59
60
61
62
63
64
# File 'lib/nexus_cli/n3_metadata.rb', line 58

def (source, target={})
  request = []
  source.merge(target).each do |key, value|
    request.push({:namespace => "urn:nexus/user#", :key => key, :value => value, :readOnly => false}) unless value.empty?
  end
  return request
end

.missing_custom_metadata?(custom_metadata) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/nexus_cli/n3_metadata.rb', line 66

def missing_custom_metadata?()
  return !.match(/<data[ ]*\/>/).nil? ? true : false
end

.valid_n3_key?(element) ⇒ Boolean

Checks if the custom metadata key is valid. Valid characters are alphanumeric with no special characeters.

Returns:

  • (Boolean)


8
9
10
# File 'lib/nexus_cli/n3_metadata.rb', line 8

def valid_n3_key?(element)
  return !element.nil? && !element.match(/^[a-zA-Z0-9]+$/).nil? ? true : false
end

.valid_n3_search_type?(element) ⇒ Boolean

Check if the custom metadata search type is valid.

Returns:

  • (Boolean)


19
20
21
# File 'lib/nexus_cli/n3_metadata.rb', line 19

def valid_n3_search_type?(element)
  return !element.nil? && ["equal", "notequal", "matches", "bounded"].include?(element)
end

.valid_n3_value?(element) ⇒ Boolean

Checks if the custom metadata value is valid. Valid characters are anything but quotes.

Returns:

  • (Boolean)


14
15
16
# File 'lib/nexus_cli/n3_metadata.rb', line 14

def valid_n3_value?(element)
  return !element.nil? && !element.match(/^[^"'\\]*$/).nil? ? true : false
end