Class: Jira4R::JiraTool

Inherits:
Object
  • Object
show all
Defined in:
lib/jira4r/jira_tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, base_url) ⇒ JiraTool

Create a new JiraTool

where: version … the version of the SOAP API you wish to use - currently supported versions [ 2 ] base_url … the base URL of the JIRA instance - eg. confluence.atlassian.com



15
16
17
18
19
20
# File 'lib/jira4r/jira_tool.rb', line 15

def initialize(version, base_url)
  @version = version
  @base_url = base_url  
  @logger = Logger.new(STDERR)
  @endpoint_url = "#{@base_url}/rpc/soap/jirasoapservice-v#{version}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)



204
205
206
207
# File 'lib/jira4r/jira_tool.rb', line 204

def method_missing(method_name, *args)
  args = fix_args(args)
  call_driver(method_name, *args)
end

Instance Attribute Details

#enhancedObject

Returns the value of attribute enhanced.



8
9
10
# File 'lib/jira4r/jira_tool.rb', line 8

def enhanced
  @enhanced
end

Instance Method Details

#call_driver(method_name, *args) ⇒ Object

Call a method on the driver, adding in the authentication token previously determined using login()



65
66
67
68
69
70
71
72
73
74
# File 'lib/jira4r/jira_tool.rb', line 65

def call_driver(method_name, *args)
  @logger.debug("Finding method #{method_name}")
  method = driver().method(method_name)     
  
  if args.length > 0
    method.call(@token, *args)     
  else
    method.call(@token)
  end
end

#driverObject

Retrieve the driver, creating as required.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jira4r/jira_tool.rb', line 28

def driver()
  if not @driver
    @logger.info( "Connecting driver to #{@endpoint_url}" )

    require "jira4r/v#{@version}/jiraService.rb"
    require "jira4r/v#{@version}/JiraSoapServiceDriver.rb"
    require "jira4r/v#{@version}/jiraServiceMappingRegistry.rb"
    
    service_classname = "Jira4R::V#{@version}::JiraSoapService"
    puts "Service: #{service_classname}"
    service = eval(service_classname)
    @driver = service.send(:new, @endpoint_url)
    # Ignore SSL Certs that are Self Signed or Signed by a None Standard CA
    @driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
  end
  @driver
end

#findEntityInPermissionMapping(permissionMapping, entityName) ⇒ Object



161
162
163
164
165
166
# File 'lib/jira4r/jira_tool.rb', line 161

def findEntityInPermissionMapping(permissionMapping, entityName)
     permissionMapping.remoteEntities.each { |entity|
    return entity if entity.name == entityName
  }
  return nil
end

#findPermission(allowedPermissions, permissionName) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/jira4r/jira_tool.rb', line 153

def findPermission(allowedPermissions, permissionName)
		allowedPermissions.each { |allowedPermission|
 #puts "Checking #{allowedPermission.name} against #{permissionName} "
 return allowedPermission if allowedPermission.name == permissionName
		}
		return nil    
end

#getGroup(groupName) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/jira4r/jira_tool.rb', line 107

def getGroup( groupName )
  begin
    return call_driver( "getGroup", groupName )
  rescue SOAP::FaultError => soap_error
    #XXX surely there is a better way to detect this kind of condition in the JIRA server
    if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteValidationException: no group found for that groupName: #{groupName}"
      return nil
    else
      raise soap_error
    end
  end
end

#getNotificationScheme(notificationSchemeName) ⇒ Object



133
134
135
136
137
138
# File 'lib/jira4r/jira_tool.rb', line 133

def getNotificationScheme( notificationSchemeName )
  self.getNotificationSchemes().each { |notification_scheme| 
    return notification_scheme if notification_scheme.name == notificationSchemeName
  }
  return nil
end

#getPermission(permissionName) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jira4r/jira_tool.rb', line 140

def getPermission( permissionName )
  if not @permissions
    @permissions = self.getAllPermissions()
  end
  
  @permissions.each { |permission|
    return permission if permission.name.downcase == permissionName.downcase
  }
  
  @logger.warn("No permission #{permissionName} found")
  return nil
end

#getPermissionScheme(permissionSchemeName) ⇒ Object



126
127
128
129
130
131
# File 'lib/jira4r/jira_tool.rb', line 126

def getPermissionScheme( permissionSchemeName )
  self.getPermissionSchemes().each { |permission_scheme| 
    return permission_scheme if permission_scheme.name == permissionSchemeName
  }
  return nil
end

#getProject(key) ⇒ Object



88
89
90
91
92
# File 'lib/jira4r/jira_tool.rb', line 88

def getProject(key)
  #Jira > 3.10 has been patched to support this method directly as getProjectByKey
  puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
  return getProjectByKey(key)
end

#getProjectByKey(projectKey) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/jira4r/jira_tool.rb', line 94

def getProjectByKey( projectKey )
  begin
    return call_driver( "getProjectByKey", projectKey )
  rescue SOAP::FaultError => soap_error
    #XXX surely there is a better way to detect this kind of condition in the JIRA server
    if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteException: Project: #{projectKey} does not exist"
      return nil
    else
      raise soap_error
    end
  end
end

#getProjectNoScheme(key) ⇒ Object

Retrieve a project without the associated PermissionScheme. This will be significantly faster for larger Jira installations. See: JRA-10660



79
80
81
82
# File 'lib/jira4r/jira_tool.rb', line 79

def getProjectNoScheme(key)
  puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
  getProjectNoSchemes(key)
end

#getProjectNoSchemes(key) ⇒ Object



84
85
86
# File 'lib/jira4r/jira_tool.rb', line 84

def getProjectNoSchemes(key)
  self.getProjectsNoSchemes().find { |project| project.key == key }
end

#getProjectRoleByName(projectRoleName) ⇒ Object



120
121
122
123
124
# File 'lib/jira4r/jira_tool.rb', line 120

def getProjectRoleByName( projectRoleName )
  getProjectRoles.each{ |projectRole|
    return projectRole if projectRole.name == projectRoleName
  }
end

#logger=(logger) ⇒ Object

Assign a new logger to the tool. By default a STDERR logger is used.



23
24
25
# File 'lib/jira4r/jira_tool.rb', line 23

def logger=(logger)
  @logger = logger
end

#login(username, password) ⇒ Object

Login to the JIRA instance, storing the token for later calls.

This is typically the first call that is made on the JiraTool.



55
56
57
# File 'lib/jira4r/jira_tool.rb', line 55

def (username, password)
  @token = driver().(username, password)
end

#setPermissions(permissionScheme, allowedPermissions, entity) ⇒ Object

Removes entity



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/jira4r/jira_tool.rb', line 169

def setPermissions( permissionScheme, allowedPermissions, entity)
  allowedPermissions = [ allowedPermissions ].flatten.compact
  #Remove permissions that are no longer allowed
  permissionScheme.permissionMappings.each { |mapping|
    next unless findEntityInPermissionMapping(mapping, entity.name)
  
    allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
 if allowedPermission
     puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
allowedPermissions.delete(allowedPermission)
   next
 end

		puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
    deletePermissionFrom( permissionScheme, mapping.permission, entity)
  }
  
  puts allowedPermissions.inspect
  allowedPermissions.each { |allowedPermission|
		puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
		addPermissionTo(permissionScheme, allowedPermission, entity) 
	  }   
end

#tokenObject

Clients should avoid using the authentication token directly.



60
61
62
# File 'lib/jira4r/jira_tool.rb', line 60

def token()
  @token
end

#wiredump_file_base=(base) ⇒ Object

Assign a wiredump file prefix to the driver.



47
48
49
# File 'lib/jira4r/jira_tool.rb', line 47

def wiredump_file_base=(base)
  driver().wiredump_file_base = base
end