differences between get_directory_client and get_subdirectory_client for azure file share - azure-files

Azure file share Python SDKs have two similar methods get_directory_client and get_subdirectory_client. It seems both are interacting with directories. But do we need two methods to perform the same task?

get_directory_client is to get the root directory, and get_subdirectory_client is to get the subdirectories of the current directory.
As you can see from the document, you must get the ShareClient object first. At this time, you can only call get_directory_client to get the root directory, and then you will get the ShareDirectoryClient object. At this time, if you want to get the subdirectory , You can only call the get_subdirectory_client method.
You can also refer to the description of the file share client to understand the difference:
==========================update======================
connection_string = "<your-connection-string>"
service = ShareServiceClient.from_connection_string(conn_str=connection_string)
share = service.get_share_client("<your-file-share-name>")
my_files = []
for item in share.list_directories_and_files():
my_files.append(item)
if item["is_directory"]:
for item2 in share.get_directory_client(item["name"]).list_directories_and_files():
my_files.append(item)
for item3 in share.get_directory_client(item["name"]).get_subdirectory_client(item2["name"]).list_directories_and_files():
my_files.append(item3)
else:
my_files.append(item)
print(my_files)
You can refer to this official documentation.

Honestly, I find it a bit confusing having to deal with two different methods to do "the same thing". I prefer to instantiate the directory client via the from_connection_string method.
For more information on how to list files from a FileShare, take a look at the following post: "Azure File Share - Recursive Directory Search like os.walk". The approach I reported allows to list files recursively, walking through the directories.

Related

hyperledger composer & access security

I am currently building a network with a lot of different company with each one running a node.
The model is basically one big asset. A company might access couple of property and be restricted from other.
I saw that asset property permission is not possible.
The only solution I can see would be to create sub asset of that main asset and apply different permission and deny the possibility to host a node ?
Thanks a lot for your ideas & suggestions.
Jonathan.
Yes your solution work perfectly in case of a participant that does not host a node. However if the participant host a node It is now possible with a new feature implemented in Fabric 1.2: http://hyperledger-fabric.readthedocs.io/en/latest/private-data/private-data.html
Hyperledger Composer:
I suggest you to split your asset in smaller ones and implement the right access control for each one.
However you can implement specific logics in the transaction processor based on the identity / participant which is invoking the chaincode.
For example:
// Get the current participant.
var currentParticipant = getCurrentParticipant();
if (currentParticipant.getFullyQualifiedType() == 'org.example.ParticipantOfCompanyA') {
//do something
} else if (currentParticipant.getFullyQualifiedType() == 'org.example.ParticipantOfCompanyB') {
//do something else
}
Here the link to the official documentation:
https://hyperledger.github.io/composer/unstable/api/runtime-api#getcurrentparticipant
Hyperledger Fabric:
From Fabric v1.2 is possible to create private data between organizations on the same channel.
Here the link to the official documentation:
http://hyperledger-fabric.readthedocs.io/en/latest/private-data/private-data.html

How to restrict fields returned by stackexchange api, and turn off paging?

I'd like to have a list of just the current titles for all questions in one of the smaller (less than 10,000 questions) stackexchange site. I tried the interactive utility here: https://api.stackexchange.com/docs/questions and it both reports the result as a json at the bottom, and produces the requesting url at the top. For example:
https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=apples&site=cooking
returns this JSON in my browser:
{"items":[{"tags":["apples","crumble"],"owner":{ ...
...
...],"has_more":true,"quota_max":300,"quota_remaining":252}
What is quota? It was 10,000 on one search on one site, but suddenly it's only 300 here.
I won't be doing this very often, what I'd like is the quickest way to edit that (or similar of course) url so I can get a list of all of the titles on a small site. I don't understand how to use paging, and I don't need any of the other fields. I don't care if I get them, but I'm thinking if I exclude them I can have more at once.
If I need to script it, python (2.7) is my preferred (only) language.
quota_max is the number of requests your application is allowed per day. 300 is the default for an unregistered application. This used to be mentioned directly on the page describing throttles, but seems to have been removed. Here is historical information describing the default.
To increase this to 10,000, you need to register an application and then authenticate by passing an access token in your script.
To get all titles on a site, you can use a Python library to help:
StackAPI. The answer below will use this library. DISCLAIMER: I wrote this library
Py-StackExchange
SEAPI
StackPy
Assuming you have registered your application and authenticated we can proceed.
First, install StackAPI (documentation):
pip install stackapi
This code will then grab the 10,000 most recent questions (max_pages * page_size) for the site hardwarerecs. Each page costs you one API hit, so the more items per page, the few API calls.
from stackapi import StackAPI
SITE = StackAPI('hardwarerecs')
SITE.page_size = 100
SITE.max_pages = 100
# Filter to only get question title and link
filter = '!BHMIbze0EQ*ved8LyoO6rNjkuLgHPR'
questions = SITE.fetch('questions', filter=filter)
In the questions variable is a dictionary that looks very similar to the API output, except that the library did all the paging for you. Your data is in questions['data'] and, in this case, contains a list of dictionaries that look like this:
[
...
{u'link': u'http://hardwarerecs.stackexchange.com/questions/29/sound-board-to-replace-a-gl2200-in-a-house-of-worship-foh-setting',
u'title': u'Sound board to replace a GL2200 in a house-of-worship FOH setting?'},
{ u'link': u'http://hardwarerecs.stackexchange.com/questions/31/passive-gps-tracker-logger',
u'title': u'Passive GPS tracker/logger'}
...
]
This result set is limited to only the title and the link because of the filter we applied. You can find the appropriate filter by adjusting what fields you want in the web UI and copying the filter field.
The hardwarerecs parameter that is passed when creating the SITE parameter is the first part of the site's domain URL. Alternatively, you can find it by looking at the api_site_parameter for your site when looking at the /sites end point.

java-how to get number class files executed by particuler test class from sonar qube data base

hi guys how can i get information like how many number of class files which will be executed from particular test class from sonarqube database,my sonarqube database is resided in MySQL db i am not finding any answers can guys help to this problem
The short answer is: it is not recommended to access SonarQube DB to get information, so forget about directly manipulating SQ's database.
A longer answer might be: have a look at SonarQube's webservice API, especially these ones :
http://nemo.sonarqube.org/api_documentation/api/tests/list
http://nemo.sonarqube.org/api_documentation/api/tests/covered_files
The first one should allow you to retrieve all test id then you can pass the ID you're looking for to the second webservice then check the size of the files array... but I don't think that this will be easy as it isn't straightforward to get the testFileId you need to feed the first webservice (you can't pass a file's key as far as I know.)

How can I use the Box Java SDK to create a shared link without specifying the share type?

In Box API v1, it was possible to request creation of a shared link for a file or folder, without caring about what kind of sharing was required. In fact, it was not possible to ask for a particular type of share - you just used the public_share method and passed in the target type (file/folder) and target ID, and optionally a share password. In an Enterprise Account, for instance, this might result in the maximum access level being "company" or "collaborators", if public links are disallowed.
With Box API v2, according to the docs here, you need to specify an access parameter that has to be "open", "company", or "collaborators".
The problem is, using the wrong type may cause the share to fail. For instance, in a folder/account that only allows collaborators, I get a 400 error if I ask for a "open" share.
What I really want is to get exactly the same result as if the user clicked the "Share" link in the Box web site. Which is, it should enable sharing for the file but default the level appropriately.
Is there a way to do this with v2, without the admin having to tell us their "preferred" access level for shared links we create? I'm using the Java SDK, like this:
BoxItemRequestObject req = BoxItemRequestObject.createSharedLinkRequestObject(BoxSharedLinkRequestObject.createSharedLinkRequestObject("open"));
BoxItem item = itemsManager.createSharedLink(<ID>, req, BoxResourceType.FILE);
Thanks,
Ben Gilbert
Smartsheet.com
Just set the access to the empty set {}
So your request would look like this:
{"shared_link": {}}
I figured out how to make this work. I need to set access to null when creating the BoxSharedLinkRequestObject, like this:**
BoxItemRequestObject req = BoxItemRequestObject.createSharedLinkRequestObject(BoxSharedLinkRequestObject.createSharedLinkRequestObject(null));
This doesn't produce quite the same JSON as was recommended (shared_link: {}), but it does produce JSON that is apparently equivalent: shared_link: { access: null }. I couldn't figure out any way to produce an empty shared_link object using the SDK -- I either had to have a null shared_link (which didn't work at all) or some value for the access field.

Not receiving "webViewLink" in response?

After turning on Google Drive API access from the management console and getting my Client ID keys, I followed the sample code (using Python 2.7) and I am able to insert a folder, set the appropriate permissions (type=anyone,role=reader), and insert a text/html type file into the new folder.
However the JSON file resource objects I receive from executing insert on the drive service have no 'webViewLink' field! There are 'webContentLink' and 'selfLink' fields but 'webViewLink', which is necessary for static HTML publishing, seems to be missing.
Most perplexing. If this feature hasn't been turned on yet or if I need to configure my account settings to allow HTML publishing please let me know. Any other help would be most appreciated ;)
The webViewLink property is only returned for public folders, and not the single files inside such folders. You can use that as the base url to construct links to your files.
The WebViewLink file property can be retrieved by doing something like this:
$file = $service->files->get($file_id, array('fields' => 'webViewLink'));
$web_link_view = $file->getWebViewLink();
OR
$sheetsList = $drive_service->files->listFiles([
'fields' => 'files(id, name, webViewLink, webContentLink)',
]);
$web_link_view = $sheetsList->current()->getWebViewLink();
Pay attention that you should load the file specifying which fields you wanna bring with it (In this case, webViewLink). If you don't do that, only id and name will be available.
If you also need to configure file permissions, you can do something like:
$permissions = new \Google_Service_Drive_Permission();
$permissions->setRole('writer');
$permissions->setType('anyone');
$drive_service->permissions->create($file_id, $permissions);
Possible values for setRole() and setType() can be found here: https://developers.google.com/drive/api/v3/reference/permissions/create