Comments (7)
We found an alternate method that seems to work. It calls this API endpoint directly using the com.azure.core.http.HttpClient
. If HNS is enabled for the account then it will return a 401 response status since we aren't authenticated, if HNS is not enabled then it will return a 400 response status that says it is an invalid URI. The upn
query parameter is only valid for HNS account types.
private boolean isHierarchicalNamespaceEnabled(String accountName)
throws IOException
{
URL url = UrlBuilder.parse("https://%s.dfs.core.windows.net/".formatted(accountName))
.addQueryParameter("action", "getStatus")
.addQueryParameter("upn", "true")
.toUrl();
HttpRequest request = new HttpRequest(HttpMethod.HEAD, url);
try (HttpResponse response = httpClient.send(request).block()) {
return Optional.ofNullable(response)
.map(HttpResponse::getStatusCode)
.map(statusCode -> !Objects.equals(statusCode, 400))
.orElseThrow();
}
}
from azure-sdk-for-java.
Thanks for filing this issue @findinpath.
I'll start by assuming when you want to make this check you already have a BlobContainerClient
, or BlobContainerAsyncClient
(and I'm going to write the following answer using the synchronous client but the same / equivalent APIs should exist in the async client).
You can get the BlobServiceClient
using BlobContainerClient.getServiceClient()
. The BlobServiceClient
should then have a method getAccountInfo
returning a StorageAccountInfo
object. This has an is getter isHierarchicalNamespaceEnabled
which will indicate if the Storage account being used has hierarchical namespace enabled.
boolean isHierarchicalNamespaceAccount = blobContainerClient.getServiceClient()
.getAccountInfo()
,isHierarchicalNamespaceEnabled();
from azure-sdk-for-java.
@alzimmermsft thank you for your reply.
Do note that the above mentioned method doesn't work when using OAuth2 authentication.
As mentioned here
This operation doesn't support OAuth-based authorization via an access token from Azure Active Directory/MSI or a user delegation SAS.
I'm not sure why this information is not being provided when using token credentials on the service level.
I'd like though to know whether there is a workaround to the current situation.
from azure-sdk-for-java.
Hmm, this one I don't have a good answer for, @seanmcc-msft do you have any additional information on how to use this without a connection string?
from azure-sdk-for-java.
Workaround
az storage account blob-service-properties show --account-name my-storage-account
{
"id": "/subscriptions/xxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount/blobServices/default",
.....
"resourceGroup": "myresourcegroup",
....
"type": "Microsoft.Storage/storageAccounts/blobServices"
}
https://stackoverflow.com/a/75711750
az resource show --name mystorageaccount --resource-group myresourcegroup --resource-type "Microsoft.Storage/storageAccounts" --query properties.isHnsEnabled
This will show whether HNS is enabled or not for the storage account while using az
tool.
Could you please add to the class https://github.com/Azure/azure-sdk-for-java/blob/eee5dc85bf53571289ee1cb5e3a0d0e6bf06df9c/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlobServiceProperties.java also the following information:
- field
resourceGroup
- field
id
I need them to extract via the resourceManager
the HNS related information
AzureProfile profile = new AzureProfile(tenantId, "xxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxxx", AzureEnvironment.AZURE);
ResourceManager resourceManager = ResourceManager
.authenticate(credential, profile)
.withDefaultSubscription();
ResourcesClient resourceClient = resourceManager.serviceClient().getResources();
GenericResourceInner resource = resourceClient.get("myresourcegroup", "Microsoft.Storage", "", "storageAccounts", "mystorageaccount", "2021-04-01");
Map<String, Object> resourceProperties = (Map<String, Object>)resource.properties();
boolean isHnsEnabled = Optional.ofNullable(resourceProperties.get("isHnsEnabled")).map(Boolean.class::cast).orElse(false);
Is there maybe a more elegant way to extract the subscription id from the BlobServiceProperties
output?
from azure-sdk-for-java.
With the above workaround aside, it feels though unnatural to go the above mentioned route just to know whether the container i'm dealing with is hierarchical or not and this only when using service tokens. :(
from azure-sdk-for-java.
Yet, another (maybe more elegant way)
ClientSecretCredential credential = new ClientSecretCredentialBuilder()
.authorityHost(authorityHost)
.tenantId(tenantId)
.clientId(clientId)
.clientSecret(secret)
.build();
DataLakeDirectoryClient dataLakeDirectoryClient = client.getFileSystemClient(azureLocation.container().orElseThrow()).getDirectoryClient("/");
boolean isHnsEnabled = dataLakeDirectoryClient.exists();
I'd like somebody from MSFT to confirm whether this solution should be correct in the long run.
from azure-sdk-for-java.
Related Issues (20)
- [BUG] getMetadata returns only nulls HOT 2
- [BUG] Encountering "java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-3" during delete operation after upgrading to latest Cosmos SDK and Spring Boot 3 HOT 1
- Just a blank issue for sanity testing HOT 2
- OpenSsl:154 - Failed to load netty-tcnative;OpenSslEngine will be unavailable, java.lang.illegalArgumentException: Failed to load any of given libraries :[netty_tcnative_windows_x86_64, netty_tcnative_x86_64, netty-tcnative HOT 4
- Make it so that `Response` contents can be lazily deserialized where necessary. HOT 2
- azure-ai-openai missing method to call GPT-4-turbo vision HOT 1
- [BUG] com.azure.core.http.HttpClient resolves proxy's DNS name only once and caches the IP address forever regardless of TTL. HOT 4
- [BUG] Android java - azure-storage-blob - blobClient.getProperties().getLastModified() - Wrong number of arguments; expected 1, got 0 HOT 2
- [OpenAI] Create a policy to route the AOAI and OAI API calls
- [BUG] Java OpenAI EmbeddingsOptions requires setUser be called with non-null value HOT 3
- [BUG] OpenAI beta6 using datasources - error: Unrecognized request argument supplied: dataSources
- [FEATURE REQ] eng, move SDK automation out of eng/mgmt folder HOT 1
- [BUG] CriteriaType ARRAY_CONTAINS does not support the 3rd parameter of the function in azure-spring-data-cosmos HOT 1
- [BUG] When prompt trigger the content filter, the serialized object with returned JSON is incorrect HOT 9
- [BUG] java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-epoll-1, when using uploadWithResponse method of BlobClient HOT 5
- Azure Key Vault- How to use AzureCliCredential first when using spring.cloud.azure.keyvault.secret.property-sources[0].endpoint HOT 6
- [OpenAI] Investigate the error message POJO that works for both AOAI and OAI HOT 2
- [BUG] Spring presents Bean selection issues when passwordless and resource-manager are used together. HOT 2
- Test Issue, please ignore HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-sdk-for-java.