Permalink
Browse files

Merge branch 'HHQ-4992' into hqapi-4.x

  • Loading branch information...
2 parents 231e7e8 + c9aa855 commit d2bab558c4d7a2ea020c1d19650c19dbd43a4e9b Wes Schlichter committed Aug 12, 2011
@@ -379,38 +379,18 @@ public void testGetPlatformResourceByIp() throws Exception {
String ip = "127.0.0.1";
assertNotNull("Platform has no ip", ip);
- ResourceResponse getResponse =
+ ResourcesResponse resourcesResponse =
getApi().getResourceApi().getPlatformResourceByIp(ip, false, false);
- hqAssertSuccess(getResponse);
- Resource resource = getResponse.getResource();
- validateResource(resource);
- }
-
- public void testGetPlatformResourceByIpNoPermission() throws Exception {
-
- Resource r = getLocalPlatformResource(false, false);
-
- String ip = "127.0.0.1";
- assertNotNull("Platform has no ip", ip);
-
- List<User> users = createTestUsers(1);
- User user = users.get(0);
- HQApi apiUnpriv = getApi(user.getName(), TESTUSER_PASSWORD);
-
- ResourceResponse getResponse =
- apiUnpriv.getResourceApi().getPlatformResourceByIp(ip, false, false);
-
- hqAssertFailurePermissionDenied(getResponse);
-
- deleteTestUsers(users);
+ hqAssertSuccess(resourcesResponse);
+ assertTrue(resourcesResponse.getResource().size() > 0);
}
public void testGetInvalidPlatformResourceByIp() throws Exception {
ResourceApi api = getApi().getResourceApi();
- ResourceResponse getResponse = api.getPlatformResourceByIp("Invalid platform ip",
+ ResourcesResponse getResponse = api.getPlatformResourceByIp("Invalid platform ip",
false, false);
hqAssertFailureObjectNotFound(getResponse);
}
@@ -404,7 +404,6 @@ class ResourceController extends ApiController {
def id = params.getOne("id")?.toInteger()
def platformName = params.getOne("platformName")
def fqdn = params.getOne("fqdn")
- def ip = params.getOne("ip")
def parentOf = params.getOne("parentOf")?.toInteger()
def platformId = params.getOne("platformId")?.toInteger()
def aeid = params.getOne("aeid")?.toString()
@@ -413,7 +412,7 @@ class ResourceController extends ApiController {
def resource = null
def failureXml
- if (!ip && !id && !platformName && !fqdn && !platformId && !parentOf && !aeid) {
+ if (!id && !platformName && !fqdn && !platformId && !parentOf && !aeid) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS)
} else {
try {
@@ -456,13 +455,6 @@ class ResourceController extends ApiController {
"Platform fqdn='" + fqdn +
"' not found")
}
- } else if (ip) {
- resource = findByIp(ip)
- if (!resource) {
- failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
- "Platform ip='" + ip +
- "' not found")
- }
} else if (parentOf) {
def child = getResource(parentOf)
if (!child) {
@@ -502,11 +494,12 @@ class ResourceController extends ApiController {
def description = params.getOne("description")
def children = params.getOne("children", "false").toBoolean()
def verbose = params.getOne("verbose", "false").toBoolean()
-
+ def ip = params.getOne("ip")
+
def resources = []
def failureXml
- if (!agentId && !prototype && !description) {
+ if (!agentId && !prototype && !description && !ip) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS)
} else {
if (agentId) {
@@ -535,6 +528,20 @@ class ResourceController extends ApiController {
log.debug("Ignoring resource " + resource.name + " due to permissions")
}
}
+ } else if (ip) {
+ def matching = findPlatformByIpAddr(ip)
+ if (matching.isEmpty()) {
+ failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
+ "Platform ip='" + ip +
+ "' not found")
+ }
+ for (resource in matching) {
+ try {
+ resources.add(resource.checkPerms(operation: 'view', user:user))
+ } catch (PermissionException e) {
+ log.debug("Ignoring resource " + resource.name + " due to permissions")
+ }
+ }
} else if (description) {
// TODO: Move into HQ.
def matching = []
@@ -1268,13 +1275,8 @@ class ResourceController extends ApiController {
}
- private Resource findByIp(ip) {
- try {
- def plat = platMan.findPlatformByFqdn(user, ip)
- return plat.resource
- } catch (PlatformNotFoundException e) {
- return null
- }
+ private Collection<Resource> findPlatformByIpAddr(ip) {
+ return platMan.getPlatformByIpAddr(user, ip)
}
}
@@ -367,16 +367,16 @@ public ResourceResponse getPlatformResourceByFqdn(String fqdn, boolean verbose,
*
* @throws java.io.IOException If a network error occurs while making the request.
*/
- public ResourceResponse getPlatformResourceByIp(String ip, boolean verbose,
+ public ResourcesResponse getPlatformResourceByIp(String ip, boolean verbose,
boolean children)
throws IOException
{
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("ip", new String[] { ip });
params.put("verbose", new String[] { Boolean.toString(verbose) });
params.put("children", new String[] { Boolean.toString(children)});
- return doGet("resource/get.hqu", params,
- new XmlResponseHandler<ResourceResponse>(ResourceResponse.class));
+ return doGet("resource/find.hqu", params,
+ new XmlResponseHandler<ResourcesResponse>(ResourcesResponse.class));
}
/**

0 comments on commit d2bab55

Please sign in to comment.