Closed maheshn99 closed 1 year ago
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @weidongxu-microsoft, @XiaofeiCao
@maheshn99
Would you elaborate what do you mean by a "hidden type"?
Please see attached image
Hello! Is there any update on this? Please prioritise implementing in the Java API a flag to denote that the resource being returned is of hidden type.
Portal uses a huge ARG query.
Here is what you can do equivalent via Java SDK.
code
ResourceGraphManager argManager = ResourceGraphManager.authenticate(
new DefaultAzureCredentialBuilder().build(),
new AzureProfile(AzureEnvironment.AZURE));
var subscriptionId1 = "<subscription-id>";
var rgName1 = "<resource-group>";
// load the query from resource, its too big to fit in String constant pool
var query = new Scanner(Main.class.getResourceAsStream("/queryAll.txt"), StandardCharsets.UTF_8)
.useDelimiter("\\A").next().trim()
.replace("{rgName}", rgName1);
// query ARG
var ret = argManager.resourceProviders().resources(
new QueryRequest()
.withSubscriptions(Collections.singletonList(subscriptionId1))
.withQuery(query));
Below is 2 query file: queryNoHidden.txt queryAll.txt
Thank you very much! I will give this a try.
Can you please throw some light on how can I get the list of GenericResources from the variable ret (QueryResponse) ? I need to iterate through each of the resources returned by the query.
Many thanks!
@maheshn99
I think the recommendation is to stick to ARG for related queries.
In the end of the query, there is project name,typeDisplayName,locationDisplayName,id,type,kind,location,subscriptionId,resourceGroup,tags,extendedLocation|sort by (tolower(tostring(name))) asc
, which you can modify to return more rich data of the resource.
If you had to query via GenericResource
, I only know how to query one by one, hence the performance would be pretty bad, if you have lots of resources.
You can try following code to query one item in the response of ARG query (assume ret
is the response of argManager.resourceProviders().resources(..)
API in the previous comment).
var item1 = (Map<String, String>) ((List) ret.data()).get(0);
var resourceName = (String) item1.get("name");
var resourceId = (String) item1.get("id");
// percentage encode
var encodedResourceName = URLEncoder.encode(resourceName, StandardCharsets.UTF_8)
.replace("+", "%20");
if (!Objects.equals(resourceName, encodedResourceName)) {
resourceId = resourceId.replace("/" + resourceName, "/" + encodedResourceName);
}
GenericResource resource = azure.genericResources().getById(resourceId);
Note the encoding part is pretty tricky and likely incomplete (Azure resource name should be simple, without space, but some are not).
Fantastic! I was able to use the projected tags themselves being returned as part of QueryResponse. Truly appreciate your prompt help. Thank you very much. Closing this issue now.
I need to know if any of the resources returned by the API: azureResourceManager.genericResources().list() is of hidden type. Can you please let me know how can I know that?
Many thanks!