ruby aws sdk s3 deletion of objects in folders - ruby

I'm using the aws sdk to delete an object (or objects) from a bucket, the problem is that keys that don't exist still get counted as successfully deleted, shouldn't the SDK raise an error that the key doesn't exist?
The other problem is that an object corresponding to a key that does exist isn't being removed but is returning as being successfully deleted.
EDIT:
The second problem only seems to be when the object to be deleted is inside of a folder, in the root it gets deleted fine.

The DELETE object operation for Amazon S3 intentionally returns a 200 OK even when the target object did not exist. This is because it is idempotent by design. For this reason, the aws-sdk gem will return a successful response in the same situation.
A quick clarification on the forward-slash. You can have any number of '/' characters at the beginning of your key, but an object with a preceding '/' is different from the object without. For example:
# public urls for two different objects
http://bucket-name.s3-amazonaws.com/key
http://bucket-name.s3-amazonaws.com//key
Just be consistent on whether you choose to use a slash or not.

Turns out what you can't have have '/' at the beginning of the key, which I didn't realise, not sure why it was there but it was screwing up the key.

Related

dexie.js difference between Table.bulkAdd() and Table.bulkPut()

The Dexie.js documentation for Table.bulkAdd()
https://dexie.org/docs/Table/Table.bulkAdd()#remarks
says: Add all given objects to the store.
The Dexie.js documentation for Table.bulkPut()
https://dexie.org/docs/Table/Table.bulkPut()#remarks
says: Add all given objects to the store.
Why are there two function if they both do the same thing, i.e. create a new records? I would have expected bulkPut() to execute updates on existing records.
Am I missing something?
It's a documentation issue. Will update docs. The difference between add and put is better described in the docs of Table.put() at https://dexie.org/docs/Table/Table.put() where it explains "Adds new or replaces existing object in the object store." and "If an object with the same primary key already exists, it will be replaced with the given object. If it does not exist, it will be added."

Using Exchange GetAddressEntryFromID method with LDAP msExchMailboxGuid

Outlook COM has a method under Application.Session.GetAddressEntryFromID method to grab an address entry without having to iterate through the entire Global or All Users address book.
The issue is it is expecting the ID that an entry has under the AddressLists object.
In Active Directory, there is no equivalent that gives me the same GetAddressEntryFromId string.
I was previously making a list of all users, minus rooms and resources, by going through the entire COM object, but that takes too long; 20mins.
I figured if I use AD, which is faster, with filters to find the users, then I can grab the GUID and when looking for info on the user, not have to go through the entire COM object to grab it, but it will happen locally to the executable being run.
The issue I am having, as an example, is that I have a user with the following ID;
00000000DCA740C8C042101AB4B908002B2FE18201000000000000002F6F3D45766572657374205265696E737572616E63652F6F753D436F72702D48512F636E3D526563697069656E74732F636E3D6A6E6700
In AD the msExchMailboxGuid has a value of
{4A49BD1C-62AE-4674-B097-C06528BDBEAE}
Not sure if these are the same, but I need to learn to better save it.
What else can I use, what can I do with the current time?
GAL entry id is constructed from the EX address (which is stored in the legacyDN attribute).
The entry id you have above contains the following:

How to rename an object in Google Storage bucket?

How to rename an object in Google Storage bucket through the API?
See also An error attempting to rename a Google Bucket object (Google bug?)
Objects can't be renamed. The best you can do is copy to a new object and delete the original. If the new and old object are the same location (which will be true if they're in the same bucket, for example) it will be a metadata-only (no byte copying) operation, and hence fast. However, since it's two operations it won't be atomic.
Not sure if you want to do this programmatically or manually, but the gsutil tool has a mv option which can be used for renaming objects.
gsutil mv gs://my_bucket/oldprefix gs://my_bucket/newprefix
As other posters noted, behind the scenes, this does a copy and delete.
First, use the "rewrite" method to produce a copy of the original object. Then, delete the original object.
Documentation on rewrite: https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite

Google Drive API v3, is there a way to get a list of folders that are parents of a fileId?

In v2 it was possible to make a call to /files with the query fileId in children to get a list of DriveFile objects that were parents of the supplied file.
Now, it seems to be required to make a call to /files/:fileId?fields=parents, then make a separate call to /files/:parentId for each returned parent, possibly turning one call into a dozen.
Is this correct, and if so why? This is a huge performance hit to our app, so hopefully there's an undocumented method.
The query "'fileId' in children'" doesn't publicly exist (not documented/supported) in v2 either and I don't recall it ever existing. What does exist in V2 is the Parents collection which effectively answers the same question. In v3, to get the parents of a file you just get the child and ask for the parents field.
As for whether or not that is a performance hit, I don't think it is in practice. The Parents resource in v2 was very light to begin with, and other than the ID the only useful field was the 'isRoot' property. That you can calculate yourself by calling files/root up front to get the ID of the root folder for that user (just once and save it, it won't change for that user.)
If you need to get more information about the parents than just the IDs and are worried about the # of calls you have to make, use batching to fetch them. If you just have one parent, no need to batch (it's just overhead.) If you find that a file has multiple parents, create a batch request. That'll be sent as a single HTTP request/response and is handled very efficiently on the back end.
Point is, if you just need IDs, it's no worse than before. It's one call to get the parents of a file.
If you need more than IDs, it's at most 2 HTTP requests (outside really bizarre edge cases like 1000+ parents which would exceed the batch size :)
In V3 it is possible to list all children of a parent as it's explained here: https://developers.google.com/drive/v3/web/search-parameters
Example call:
https://www.googleapis.com/drive/v3/files?q=parents in '0Byho0qAdzabmVl8xcDR1S0pNY3c' of course replace spaces with %20, this will list all the files in the folder which has id='0Byho0qAdzabmVl8xcDR1S0pNY3c'
you just need to mention like below:
var request = service.Files.List();
request.Q = "('root' in parents)";
var FileListOfParentOnly = request.Execute();

Remove entire object directory tree using AWS-SDK

I'm using the aws-sdk, and I'm trying to delete an object with the #delete_object method, for example:
s3.delete_object(bucket: ENV["AWS_BUCKET"]), key: "images/123/myimage.png"))
How can I delete the route (that's "images/123") instead of only the .png file? I don't want empty "folders". I've tested adding only the first part of the route (s3.delete_object(bucket: ENV["AWS_BUCKET"]), key: "images/")) in the key parameter but doesn't work. Thanks!
The folder will auto delete when it's empty.
So if you delete your file and refresh the root folder, you will see that it's gone ! Aws-Magic =)

Resources