Module: Aem

Defined in:
lib/aemninja/aem.rb

Class Method Summary collapse

Class Method Details

.delete(host = "localhost:4502", user = "admin", password = "admin", package) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aemninja/aem.rb', line 81

def self.delete host="localhost:4502", user="admin", password="admin", package
  auth = Base64.strict_encode64("#{user}:#{password}")
  request = RestClient::Request.new( 
      :method => :post,
      :url => "#{host}/crx/packmgr/service/.json/etc/packages/#{package}",
      :payload => {
          :cmd => 'delete'
      },
      :headers => {Authorization: "Basic #{auth}"}
  )
  response = request.execute

  JSON.parse(response)["success"]
  
end

.install(host = "localhost:4502", user = "admin", password = "admin", package) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/aemninja/aem.rb', line 98

def self.install host="localhost:4502", user="admin", password="admin", package
  auth = Base64.strict_encode64("#{user}:#{password}")
  stripped_pkg = Aemninja::Helpers::remove_path_and_version_from package
  request = RestClient::Request.new( 
      :method => :post,
      :url => "@#{host}/crx/packmgr/service.jsp",
      :payload => {
          :multipart => true,
          :file => File.new(package, 'rb'),
          :name => stripped_pkg,
          :force => true,
          :install => true
      },
      :headers => {Authorization: "Basic #{auth}"}
  )
  response_xml = request.execute

  #response_hash = Hash.from_xml(response_xml.body)

  errors = response_xml.body.each_line.grep /^E/

  if errors.present?
    puts
    puts
    puts "  ERRORS:"
    puts errors
    puts
    return false
  elsif Hash.from_xml(response_xml.body)["crx"]["response"]["status"] == 'ok'
    return true
  else
    return false
  end

end

.is_package_installed?(host = "localhost:4502", user = "admin", password = "admin", package) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aemninja/aem.rb', line 48

def self.is_package_installed? host="localhost:4502", user="admin", password="admin", package
  auth = Base64.strict_encode64("#{user}:#{password}")

  response_xml = RestClient.get "#{host}/crx/packmgr/service.jsp", {params: {cmd: 'ls'}, Authorization: "Basic #{auth}"}

  response_hash = Hash.from_xml(response_xml.body)

  installed_packages = response_hash["crx"]["response"]["data"]["packages"]["package"]

  if ary = installed_packages.find { |h| h['downloadName'].include? package }
    result = ary['group'] + "/" + ary['downloadName']
  else
    result = nil
  end

  result
end

.list(host = "localhost:4502", user = "admin", password = "admin") ⇒ Object

<crx version=“1.4.1” user=“admin” workspace=“crx.default”> <request>

<param name="cmd" value="ls"/>

</request> <response>

<data>
  <packages>
    <package>
      <group>Adobe/granite</group>
      <name>com.adobe.granite.httpcache.content</name>
      <version>1.0.2</version>
      <downloadName>com.adobe.granite.httpcache.content-1.0.2.zip</downloadName>
      <size>13323</size>
      <created>Tue, 25 Feb 2014 11:40:56 +0100</created>
      <createdBy>Adobe</createdBy>
      <lastModified></lastModified>
      <lastModifiedBy>null</lastModifiedBy>
      <lastUnpacked>Thu, 10 Aug 2017 13:42:23 +0200</lastUnpacked>
      <lastUnpackedBy>admin</lastUnpackedBy>
    </package>

returns adobe/aem6/sample/we.retail.download-1.0.8.zip



37
38
39
40
41
42
43
44
45
46
# File 'lib/aemninja/aem.rb', line 37

def self.list host="localhost:4502", user="admin", password="admin"
  # puts user
  # puts password
  # puts "#{user}:#{password}"
  auth = Base64.strict_encode64("#{user}:#{password}")
  # puts auth
  response_xml = RestClient.get "#{host}/crx/packmgr/service.jsp", {params: {cmd: 'ls'}, Authorization: "Basic #{auth}"}

  puts response_xml
end

.uninstall(host = "localhost:4502", user = "admin", password = "admin", package) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/aemninja/aem.rb', line 66

def self.uninstall host="localhost:4502", user="admin", password="admin", package
  auth = Base64.strict_encode64("#{user}:#{password}")
  request = RestClient::Request.new( 
      :method => :post,
      :url => "#{host}/crx/packmgr/service/.json/etc/packages/#{package}",
      :payload => {
          :cmd => 'uninstall'
      },
      :headers => {Authorization: "Basic #{auth}"}
  )
  response = request.execute

  JSON.parse(response)["success"]
end