Class: Jira4R::JiraTool
- Inherits:
-
Object
- Object
- Jira4R::JiraTool
- Defined in:
- lib/jira4r/jira_tool.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#enhanced ⇒ Object
Returns the value of attribute enhanced.
Instance Method Summary collapse
-
#call_driver(method_name, *args) ⇒ Object
Call a method on the driver, adding in the authentication token previously determined using login().
-
#driver ⇒ Object
Retrieve the driver, creating as required.
- #findEntityInPermissionMapping(permissionMapping, entityName) ⇒ Object
- #findPermission(allowedPermissions, permissionName) ⇒ Object
- #getGroup(groupName) ⇒ Object
- #getNotificationScheme(notificationSchemeName) ⇒ Object
- #getPermission(permissionName) ⇒ Object
- #getPermissionScheme(permissionSchemeName) ⇒ Object
- #getProject(key) ⇒ Object
- #getProjectByKey(projectKey) ⇒ Object
-
#getProjectNoScheme(key) ⇒ Object
Retrieve a project without the associated PermissionScheme.
- #getProjectNoSchemes(key) ⇒ Object
- #getProjectRoleByName(projectRoleName) ⇒ Object
- #http_auth(http_username, http_password, http_realm) ⇒ Object
-
#initialize(version, base_url) ⇒ JiraTool
constructor
Create a new JiraTool.
-
#logger=(logger) ⇒ Object
Assign a new logger to the tool.
-
#login(username, password) ⇒ Object
Login to the JIRA instance, storing the token for later calls.
-
#setPermissions(permissionScheme, allowedPermissions, entity) ⇒ Object
Removes entity.
-
#token ⇒ Object
Clients should avoid using the authentication token directly.
-
#wiredump_file_base=(base) ⇒ Object
Assign a wiredump file prefix to the driver.
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
32 33 34 35 36 37 |
# File 'lib/jira4r/jira_tool.rb', line 32 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)
225 226 227 228 |
# File 'lib/jira4r/jira_tool.rb', line 225 def method_missing(method_name, *args) args = fix_args(args) call_driver(method_name, *args) end |
Instance Attribute Details
#enhanced ⇒ Object
Returns the value of attribute enhanced.
25 26 27 |
# File 'lib/jira4r/jira_tool.rb', line 25 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()
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jira4r/jira_tool.rb', line 86 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 |
#driver ⇒ Object
Retrieve the driver, creating as required.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jira4r/jira_tool.rb', line 51 def driver() if not @driver @logger.info( "Connecting driver to #{@endpoint_url}" ) service_classname = "Jira4R::V#{@version}::JiraSoapService" puts "Service: #{service_classname}" service = eval(service_classname) @driver = service.send(:new, @endpoint_url) if not ( @http_realm.nil? or @http_username.nil? or @http_password.nil? ) @driver.["protocol.http.basic_auth"] << [ @http_realm, @http_username, @http_password ] end end @driver end |
#findEntityInPermissionMapping(permissionMapping, entityName) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/jira4r/jira_tool.rb', line 182 def findEntityInPermissionMapping(, entityName) .remoteEntities.each { |entity| return entity if entity.name == entityName } return nil end |
#findPermission(allowedPermissions, permissionName) ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/jira4r/jira_tool.rb', line 174 def findPermission(allowedPermissions, ) allowedPermissions.each { |allowedPermission| #puts "Checking #{allowedPermission.name} against #{permissionName} " return allowedPermission if allowedPermission.name == } return nil end |
#getGroup(groupName) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/jira4r/jira_tool.rb', line 128 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
154 155 156 157 158 159 |
# File 'lib/jira4r/jira_tool.rb', line 154 def getNotificationScheme( notificationSchemeName ) self.getNotificationSchemes().each { |notification_scheme| return notification_scheme if notification_scheme.name == notificationSchemeName } return nil end |
#getPermission(permissionName) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/jira4r/jira_tool.rb', line 161 def getPermission( ) if not @permissions @permissions = self.getAllPermissions() end @permissions.each { || return if .name.downcase == .downcase } @logger.warn("No permission #{} found") return nil end |
#getPermissionScheme(permissionSchemeName) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/jira4r/jira_tool.rb', line 147 def getPermissionScheme( ) self.getPermissionSchemes().each { || return if .name == } return nil end |
#getProject(key) ⇒ Object
109 110 111 112 113 |
# File 'lib/jira4r/jira_tool.rb', line 109 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
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/jira4r/jira_tool.rb', line 115 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
100 101 102 103 |
# File 'lib/jira4r/jira_tool.rb', line 100 def getProjectNoScheme(key) puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes." getProjectNoSchemes(key) end |
#getProjectNoSchemes(key) ⇒ Object
105 106 107 |
# File 'lib/jira4r/jira_tool.rb', line 105 def getProjectNoSchemes(key) self.getProjectsNoSchemes().find { |project| project.key == key } end |
#getProjectRoleByName(projectRoleName) ⇒ Object
141 142 143 144 145 |
# File 'lib/jira4r/jira_tool.rb', line 141 def getProjectRoleByName( projectRoleName ) getProjectRoles.each{ |projectRole| return projectRole if projectRole.name == projectRoleName } end |
#http_auth(http_username, http_password, http_realm) ⇒ Object
44 45 46 47 48 |
# File 'lib/jira4r/jira_tool.rb', line 44 def http_auth(http_username, http_password, http_realm) @http_username = http_username @http_password = http_password @http_realm = http_realm end |
#logger=(logger) ⇒ Object
Assign a new logger to the tool. By default a STDERR logger is used.
40 41 42 |
# File 'lib/jira4r/jira_tool.rb', line 40 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.
76 77 78 |
# File 'lib/jira4r/jira_tool.rb', line 76 def login(username, password) @token = driver().login(username, password) end |
#setPermissions(permissionScheme, allowedPermissions, entity) ⇒ Object
Removes entity
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/jira4r/jira_tool.rb', line 190 def setPermissions( , allowedPermissions, entity) allowedPermissions = [ allowedPermissions ].flatten.compact #Remove permissions that are no longer allowed ..each { |mapping| next unless findEntityInPermissionMapping(mapping, entity.name) allowedPermission = findPermission(allowedPermissions, mapping..name) if allowedPermission puts "Already has #{allowedPermission.name} in #{.name} for #{entity.name}" allowedPermissions.delete(allowedPermission) next end puts "Deleting #{mapping..name} from #{.name} for #{entity.name}" deletePermissionFrom( , mapping., entity) } puts allowedPermissions.inspect allowedPermissions.each { |allowedPermission| puts "Granting #{allowedPermission.name} to #{.name} for #{entity.name}" addPermissionTo(, allowedPermission, entity) } end |
#token ⇒ Object
Clients should avoid using the authentication token directly.
81 82 83 |
# File 'lib/jira4r/jira_tool.rb', line 81 def token() @token end |
#wiredump_file_base=(base) ⇒ Object
Assign a wiredump file prefix to the driver.
68 69 70 |
# File 'lib/jira4r/jira_tool.rb', line 68 def wiredump_file_base=(base) driver().wiredump_file_base = base end |