Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Remove calculation of deterministic id #148

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/models/bucket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const storj = require('storj-lib');
const mongoose = require('mongoose');
const SchemaOptions = require('../options');
const crypto = require('crypto');
Expand Down Expand Up @@ -88,14 +87,6 @@ Bucket.statics.create = function(user, data, callback) {
bucket.name = data.name;
}

// XXX THIS WILL BE DEPRECATED IN THE NEXT MAJOR RELEASE
// XXX Make sure to update any code that depends on this being
// XXX based on the name as soon as possible. Once this is
// XXX deprecated the id will be a unique ObjectId
bucket._id = mongoose.Types.ObjectId(
storj.utils.calculateBucketId(user._id, bucket.name)
);

bucket.save(function(err) {
if (err) {
if (err.code === 11000) {
Expand Down
11 changes: 0 additions & 11 deletions lib/models/bucketentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const hmactypes = ['sha512', 'sha256', 'ripemd160'];
const erasuretypes = ['reedsolomon'];

function isValidIndex(index) {
// XXX DEPRECATION IN NEXT MAJOR RELEASE
// XXX The determinitic id will be deprecated and the index field will
// XXX become required for any new bucket entries. This is to make sure
// XXX that each bucket entry will have a unique id.
if (index) {
Copy link
Contributor

@braydonf braydonf Mar 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to validate that the index exists, I think this was the plan from before. Will need to test to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is actually done by calling this isValidIndex() function from the create() function, right? (Line 117 after changes) Or did you mean something different?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by removing the if statement for if (index), but will need to check that this is okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PATCH method in the bridge will check if there is an index. If there isn't one, it will return Unprocessable Entity Error. So it would be safe to continue creating bucket entries without index. Simply, it won't be possible to rename them afterwards.

However, if you want to force clients to create only bucket entries with index, we should remove the if (index).

return index.length === 64 && utils.isHexaString(index);
}
Expand Down Expand Up @@ -112,14 +108,7 @@ BucketEntry.set('toObject', {
BucketEntry.statics.create = function(data, callback) {
var BucketEntry = this;

// XXX DEPRECATION IN NEXT MAJOR RELEASE
// XXX The determinitic id will be deprecated and the index field will
// XXX become required for any new bucket entries. This is to make sure
// XXX that each bucket entry will have a unique id.
const id = storj.utils.calculateFileId(data.bucket, data.name);

let doc = {
_id: id,
frame: data.frame,
bucket: data.bucket,
name: data.name
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "storj-service-storage-models",
"version": "11.0.0",
"version": "11.1.0",
"description": "common storage models for various storj services",
"main": "index.js",
"directories": {
Expand Down
8 changes: 0 additions & 8 deletions test/bucket.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ describe('Storage/models/Bucket', function() {

it('should create the bucket with the default props', function(done) {

// XXX DEPRECATED IN THE NEXT MAJOR RELEASE
var expectedBucketId =
storj.utils.calculateBucketId('user@domain.tld', 'New Bucket');

Bucket.create(
{ _id: 'user@domain.tld' },
{ name: 'New Bucket' },
Expand All @@ -51,10 +47,6 @@ describe('Storage/models/Bucket', function() {
expect(bucket.publicPermissions.length).to.equal(0);
Bucket.findOne({ _id: bucket.id }, function(err, bucket) {
expect(err).to.not.be.instanceOf(Error);

// XXX DEPRECATED IN THE NEXT MAJOR RELEASE
expect(bucket.id).to.equal(expectedBucketId);

expect(bucket.id.length).to.equal(24);
expect(bucket.name).to.equal('New Bucket');
expect(bucket.storage).to.equal(0);
Expand Down
15 changes: 3 additions & 12 deletions test/bucketentry.unit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const crypto = require('crypto');
const storj = require('storj-lib');
const expect = require('chai').expect;
const mongoose = require('mongoose');
const errors = require('storj-service-error-types');
Expand Down Expand Up @@ -41,17 +40,13 @@ after(function(done) {

describe('Storage/models/BucketEntry', function() {

var expectedBucketId =
storj.utils.calculateBucketId('user@domain.tld', 'New Bucket2');

// XXX DEPRECATED IN THE NEXT MAJOR RELEASE
var expectedFileId =
storj.utils.calculateFileId(expectedBucketId, 'test.txt');
var bucket2Id = null;

it('should create the bucket entry metadata', function(done) {
const index = crypto.randomBytes(32).toString('hex');
Bucket.create({ _id: 'user@domain.tld' }, { name: 'New Bucket2' },
function(err, bucket) {
bucket2Id = bucket._id;
var frame = new Frame({});
frame.save(function(err) {
expect(err).to.not.be.instanceOf(Error);
Expand All @@ -71,10 +66,6 @@ describe('Storage/models/BucketEntry', function() {
expect(entry.erasure.type).to.equal('reedsolomon');
expect(entry.index).to.equal(index);
expect(entry.filename).to.equal('test.txt');

// XXX DEPRECATED IN THE NEXT MAJOR RELEASE
expect(entry.id).to.equal(expectedFileId);

expect(entry.id.length).to.equal(24);
done();
});
Expand Down Expand Up @@ -113,7 +104,7 @@ describe('Storage/models/BucketEntry', function() {
BucketEntry.create({
index: crypto.randomBytes(32).toString('hex'),
frame: frame._id,
bucket: expectedBucketId,
bucket: bucket2Id,
name: 'test.txt',
mimetype: 'text/javascript'
}, function(err){
Expand Down