Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Add encryption #10

Merged
merged 10 commits into from
Jul 17, 2020
Merged

Add encryption #10

merged 10 commits into from
Jul 17, 2020

Conversation

mrcnski
Copy link
Contributor

@mrcnski mrcnski commented Jul 10, 2020

No description provided.

@mrcnski mrcnski requested review from peterjan and MSevey July 10, 2020 15:41
skynet.go Outdated Show resolved Hide resolved
skynet.go Outdated Show resolved Hide resolved
@mrcnski mrcnski requested a review from MSevey July 10, 2020 15:48
skynet.go Show resolved Hide resolved
skynet.go Outdated Show resolved Hide resolved
skynet.go Outdated
if err != nil {
return errors.AddContext(err, "could not execute POST")
}
if resp.StatusCode >= 400 {
Copy link
Contributor

@MSevey MSevey Jul 10, 2020

Choose a reason for hiding this comment

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

Do we expected to receive non error codes other than successful?

My initial reaction is that we should know the StatusCodes we should receive and handle them accordingly. Something like a switch statement that handles different codes explicitly and gives a developer error if we have missed one?

Otherwise if that is over the top I think we should explicitly check for success and return an error if not so we aren't hiding any weird status codes that might create UX bugs or inconsistencies for users.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. The potential errors are part of the public API, after all. I'll do this on Monday

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm so I'm actually not sure what checking for explicit codes would give us. I'm not a web dev person but I'm pretty sure that all codes >= 400 are defined to be errors. Any other code should therefore be a success. I don't think we have many success codes at all but I hesitate to enumerate them here because I'm thinking that a portal could define its own (e.g. redirects which should have their own status code). Maybe @kwypchlo can weigh in here but I'm thinking we move this to a followup so as not to block the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

a follow up is fine.

Choose a reason for hiding this comment

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

As far as I know, we only use 200 (with response content) and 204 (without content) as OK but any 2xx should be treated as ok while any 4xx and 5xx should be treated as error. We don't have a finite list of what errors does the API return, that would have to be up to the api to document first.

skynet.go Outdated Show resolved Hide resolved
skynet.go Outdated Show resolved Hide resolved
skynet.go Outdated Show resolved Hide resolved
@MSevey
Copy link
Contributor

MSevey commented Jul 10, 2020

This comment seems to have been lost. But we need to add in this MR or in a follow up MR the skykey parameter to the uploads. Then a test that verifies a file uploaded with a skykey can only be downloaded once the skykey is added.

Not sure if that level of testing is possible with the current infrastructure, but none the less we need the skykey parameter for the uploads so that the uploads can be encrypted.

@mrcnski
Copy link
Contributor Author

mrcnski commented Jul 10, 2020

Added the skykey parameters to uploads just as you submitted your comment. Will address the rest of the comments on Monday

Not sure if that level of testing is possible with the current infrastructure

Not really, because we mock all our HTTP calls and don't actually test the implementation. I feel it should be enough to ensure that the requests contain the necessary parameters and are formed correctly and that responses are parsed correctly. The actual implementation logic can be tested on the Sia side I think.

@MSevey
Copy link
Contributor

MSevey commented Jul 13, 2020

Added the skykey parameters to uploads just as you submitted your comment. Will address the rest of the comments on Monday

Not sure if that level of testing is possible with the current infrastructure

Not really, because we mock all our HTTP calls and don't actually test the implementation. I feel it should be enough to ensure that the requests contain the necessary parameters and are formed correctly and that responses are parsed correctly. The actual implementation logic can be tested on the Sia side I think.

ok fair enough. Wasn't sure the limitations of the testing for the SDK.

@mrcnski mrcnski requested a review from MSevey July 13, 2020 16:12
skynet.go Show resolved Hide resolved
skynet.go Show resolved Hide resolved
skynet.go Outdated Show resolved Hide resolved
skynet.go Outdated Show resolved Hide resolved
tests/skykeys_integration_test.go Show resolved Hide resolved
tests/upload_integration_test.go Show resolved Hide resolved
@mrcnski mrcnski requested a review from MSevey July 14, 2020 12:29
ConnectionOptions
// PortalCreateSkykeyPath is the relative URL path of the createskykey
// endpoint.
PortalCreateSkykeyPath string
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this MR more I'm wondering if it makes more sense to rename this to APIRoute and add it to the ConnectionOptions.

That would allow us to generalize the code even more. Unless there is a plan to move the parameters like name, id, skykeytype into their corresponding options struct it seems unnecessary to be defining an Options struct for each endpoint.

Then this line becomes even more clear

url := makeURL(opts.PortalURL, opts.APIRoute)

To be able to define the defaults easily we could have just two structs.

ConnectionOptions struct {}
APIRouteOptions struct {}

I'm thinking that there are a number of common API parameters that could be included in the APIRoutes eventually, like async root force etc.

Then the defaults can be defined as

DefaultGetSkyKeyOptions = APIRouteOptions {
  ConnectionOptions: defaultConnectionOptions,
  APIRoute: "/skynet/skykey",
}

@mrcnski mrcnski requested a review from MSevey July 15, 2020 13:28
@mrcnski
Copy link
Contributor Author

mrcnski commented Jul 17, 2020

Merging, issues were created for the remaining two discussions

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

Successfully merging this pull request may close these issues.

None yet

3 participants