Skip to content

Make S3Overrides accessible via E-Var or option AND tests #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed

Conversation

mrmarcsmith
Copy link
Contributor

Background: when using parse server with a config file there is no way to specify S3Override options.
-This change doesn't affect the current method of passing s3overrides = backwards compatible.
-s3overrides would now be accessible by via parse-server config file like this:
"filesAdapter": {
"module":"parse-server-s3-adapter",
"options":{
"s3overrides": { "endpoint": {"protocol":"https:","host":"$FILEURL","port":443,"hostname":"","pathname":"/","path":"/","href":"https:///"},
"s3BucketEndpoint": false,
ANY OTHER S3OVERRIDES GO HERE... },
"baseUrl": "https://",
"directAccess": true,
"accessKey": "",
"secretKey": "",
"bucket": "",
"region": ""
}
}

-OR in theory (I haven't tested) by Environmental variable like so:

S3_OVERRIDES="{ "endpoint": {"protocol":"https:","host":"$FILEURL","port":443,"hostname":"$FILEURL","pathname":"/","path":"/","href":"https://$FILEURL/"},
"s3BucketEndpoint": false,
ANY OTHER S3OVERRIDES GO HERE... }"

Background: when using parse server with a config file there is no way to specify S3Override options.
-This change doesn't affect the current method of passing s3overrides = backwards compatible.
-s3overrides would now be accessible by via parse-server config file like this:
"filesAdapter": {
                  "module":"parse-server-s3-adapter",
                  "options":{
                     "s3overrides": { "endpoint": {"protocol":"https:","host":"$FILEURL","port":443,"hostname":"<your NOT s3 url like minio>","pathname":"/","path":"/","href":"https://<your NOT s3 url like minio>/"}, 
"s3BucketEndpoint": false,
ANY OTHER S3OVERRIDES GO HERE... },
                     "baseUrl": "https://<your url>",
                     "directAccess": true,
                     "accessKey": "<your access key>",
                     "secretKey": "<your secret>",
                     "bucket": "<your bucket>",
                     "region": ""
                  }
      }


-OR in theory (I haven't tested) by Environmental variable like so:

S3_OVERRIDES="{ "endpoint": {"protocol":"https:","host":"$FILEURL","port":443,"hostname":"$FILEURL","pathname":"/","path":"/","href":"https://$FILEURL/"}, 
"s3BucketEndpoint": false,
ANY OTHER S3OVERRIDES GO HERE... }"
Make S3Overrides accessible via E-Var or option.
deleted data to see if that helps error
changed Key to see if this is the issue
isolating ACL
removed isolations variables
deleting extra space
added error handling to create bucket
bucket change
only mark bucket as yes if it exists
added logging of final override options
this ends up being a breaking change. reverting
@mrmarcsmith mrmarcsmith mentioned this pull request Jan 26, 2017
@mrmarcsmith
Copy link
Contributor Author

mrmarcsmith commented Jan 26, 2017

@acinader Nope, I ran into a discussion topic, given we have a config JSON as follow

var confObj = { 
bucketPrefix: 'test/', 
bucket: 'bucket-1', 
secretKey: 'secret-1', 
accessKey: 'key-1' ,
s3overrides: {
       secretAccessKey: 'secret-2', 
       accessKeyId: 'key-2', 
       params: { 
              Bucket: 'bucket-2' 
       }
   } 
};

which should take priority bucket-1 or bucket-2?
or should we throw an error so avoid confusion?

@acinader
Copy link
Contributor

acinader commented Jan 26, 2017

what do you think?

My $.02 in a situation like this would be: ideally throw an error, as it is probably a mistake.
But simply going with the last value works for me too.

Ok, the one in overrides should take precedent. that's what override means, right?

@@ -123,6 +123,27 @@ describe('S3Adapter tests', () => {
expect(options.bucketPrefix).toEqual('test/');
});

it('should accept options and overrides as an option in args', () => {
var confObj = { bucketPrefix: 'test/', bucket: 'bucket-1', secretKey: 'secret-1', accessKey: 'key-1' ,s3overrides: { secretAccessKey: 'secret-2', accessKeyId: 'key-2', params: { Bucket: 'bucket-2' }} };
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add a space after the comma

it should be
, s3over....
not
,s3over...

options[key] = options[key] || process.env[env] || defaultValue;

//If we used the overrides,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. add space after //

so // If

@acinader
Copy link
Contributor

two suggestions:

  1. figure out how to configure editor to strip trailing white space.
  2. run npm run lint before pushing commits. if you look at srcipts section of package.json you'll see the if your run npm test lint is also run first.

@mrmarcsmith
Copy link
Contributor Author

@acinader Sorry about flooding your feed with commits. I thought this would be a quick fix so I've been editing on the GitHub website. I'll switch over.

@acinader
Copy link
Contributor

haha well that explains that!

@@ -133,7 +133,7 @@ describe('S3Adapter tests', () => {
});

it('should accept options and overrides as an Enviromental Variable', () => {
var confObj = { bucketPrefix: 'test/', bucket: 'bucket-1', secretKey: 'secret-1', accessKey: 'key-1' };
var confObj = { bucketPrefix: 'test/', bucket: 'bucket-1', secretKey: 'secret-1', accessKey: 'key-1'};
Copy link
Contributor

@acinader acinader Jan 26, 2017

Choose a reason for hiding this comment

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

why'd you take out that trailing space? for consistency, there should be a space between the 1' };

that's how all the other object spacing is done in the file. we just want to be consistent, when possible we put those consistency rules into lint so we don't have to think about it......

@ghost
Copy link

ghost commented Apr 11, 2017

Hi
What is the state of this pr?

@acinader
Copy link
Contributor

@aaronschmied unfortunately the unit tests are failing as a direct result of this change. I haven't looked into why that is.

@ghost
Copy link

ghost commented Apr 11, 2017

For everyone who's looking for a quick and dirty fix:
I installed @acinader's repo using the following command in the Dockerfile:

RUN npm install && \
    npm install --save git+https://github.com/mrmarcsmith/parse-server-s3-adapter && \
    npm run build

After this I was able to configure my custom s3 endpoint in the parse server's config.json

...
        "cloud": "/parse-server/cloud/main.js",
        "filesAdapter": {
                "module": "parse-server-s3-adapter",
                "options": {
                        "bucket": "bucketname",
                        "accessKey": "accesskey",
                        "secretKey": "secretkey",
                        "region": "region",
                        "directAccess": true,
                        "baseUrl": "https://my.custom.s3/bucketname",
                        "s3overrides": {
                                "endpoint": "my.custom.s3",
                                "s3ForcePathStyle": true
                        }
                }
        }
}

@acinader
Copy link
Contributor

it's actually @mrmarcsmith's repo, not mine ;).

would be nice to get the unit test fixed and have this merged in....

@ghost
Copy link

ghost commented Apr 11, 2017

Oh, missed that 😆
Thanks for your work @mrmarcsmith

@mrmarcsmith
Copy link
Contributor Author

@aaronschmied no problem! Let me see if I have time today or tomorrow to look into the failing unit test so we can get this merged.

@flovilmart
Copy link
Contributor

@mrmarcsmith any news on that?

acinader pushed a commit to acinader/parse-server-s3-adapter that referenced this pull request Jul 1, 2017
- fix typos in unit tests
- remove ability to configure s3overrides via environment variables -- can't store objects in env
- add a pretty test reporter so i can read output.
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

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

I pulled this branch so I could figure out what was going on with the tests to determine what to do with this pr. Now that I have a thorough understanding, I'd like to close this pr un-merged.

  1. The idea of passing an object in the environment just does't work. Env vars need to be strings. The unit test that attempts to pass the s3Overrides is failing because the values are not in the env, just the string "[object, object]"

  2. the two other tests are failing because this pr doesn't attempt to reconcile the existing difference in names for the AWS Secret. Its secretKey in one place but secretAccessKey in an another (see it in action right here).

While I could attempt to figure out some sensible way to deal with this, I don't want to bother cause a) Its probable that there will be some backward compatibility issue, but more importantly, I'm about to deprecate passing keys and secrets anyway.

@mrmarcsmith if you want help me understand so I can fix, I'm all ears, but given how old this is and that we shouldn't be monkeying with keys and secrets in our code any way since AWS has a super awesome way to deal with it that relieves even having to thinking about how to handle these things securely.

@acinader
Copy link
Contributor

acinader commented Jul 1, 2017

@mrmarcsmith we can reopen, but i'm going to close it pending further discussion with you.

@mrmarcsmith
Copy link
Contributor Author

@acinader thank you for taking the time to look at this PR. That makes a lot of sense about the Env Vars but that is only half of the PR and I would gladly get rid of the Env Var part in favor of being able to pass the override options as a dictionary in the parse server config file. This is a setup (not Env Vars) I am currently using in production because I couldn't find any other way to get it to work before Parse shut down. If I remove the Env Vars part would this PR be considered?

@mrmarcsmith mrmarcsmith mentioned this pull request Jul 5, 2017
@mrmarcsmith
Copy link
Contributor Author

Since we have removed ENV VAR, I have created a new PR #50 to avoid any confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants