Skip to content
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

Merge URI_With_Query into URI, extend API of URI #8591

Merged
merged 28 commits into from
Dec 21, 2023

Conversation

radeusgd
Copy link
Member

Pull Request Description

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@radeusgd radeusgd added the CI: No changelog needed Do not require a changelog entry for this PR. label Dec 19, 2023
@radeusgd radeusgd self-assigned this Dec 19, 2023
@radeusgd radeusgd force-pushed the wip/radeusgd/url-encode branch from 734b5e2 to eef7793 Compare December 19, 2023 17:43
@radeusgd radeusgd force-pushed the wip/radeusgd/8544-merge-uri-with-query branch from b690744 to 68afb4a Compare December 19, 2023 17:44
@radeusgd radeusgd linked an issue Dec 19, 2023 that may be closed by this pull request
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Removing duplication is good. I'd suggest some more removal, but I don't see the whole picture.

@@ -87,6 +89,12 @@ type Enso_Secret
exists name:Text parent:(Enso_File | Nothing)=Nothing =
Enso_Secret.list parent . any s-> s.name == name

## PRIVATE
to_java_value : Text | Enso_Secret | Nothing -> HideableValue
Copy link
Member

Choose a reason for hiding this comment

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

Things related to security should really be private not just documented ## PRIVATE, in my opinion. E.g. move the method into own private module, make it an extension method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think I can do this, because Enso_Secret.to_java_value is used within Standard.Database, outside of Standard.Base.

I can move it to a separate file but I cannot make it inaccessible from other modules.

Note that this does not expose any 'sensitive' data - it just creates a Java representation of the Enso_Secret value, using its payload. It's just a transformation of existing data into an internal format.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved this method to Enso_Cloud/Utils and renamed it to as_hideable_value

@@ -99,43 +81,3 @@ URI_With_Query.fetch self (method:HTTP_Method=HTTP_Method.Get) headers=[] try_au
URI.post : Request_Body -> HTTP_Method -> Vector (Header | Pair Text Text) -> Boolean -> Any
URI.post self (body:Request_Body=Request_Body.Empty) (method:HTTP_Method=HTTP_Method.Post) (headers:(Vector (Header | Pair Text Text))=[]) (try_auto_parse_response:Boolean=True) =
Data.post self body method headers try_auto_parse_response

Copy link
Member

Choose a reason for hiding this comment

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

Looks like a simplification.

}
}

String render();
Copy link
Member

Choose a reason for hiding this comment

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

This is usually called toString() in Java.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair, I wanted to make sure we call it explicitly to distinguish the usages where we convert secrets to __SECRET__ vs usages where we disallow secrets vs usages where we read actual secret values.

I can change to toString if you think that does not clash with the above.

}
}

record PlainValue(String value) implements HideableValue {
Copy link
Member

Choose a reason for hiding this comment

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

Secure computing suggests to store values in byte[] - because (unlike String) byte[] can be programaticaly destroyed. That gives the user of the HideableValue control of the life-span a value is valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

The PlainValue is nothing that has to be destroyed.

This PR is not changing any of the 'secure' secret logic from #8006, it just refactors it a bit and changes the API.

Also note that for the actual secrets (not something the HideableValue is), we have to hold them as String at some point because we need to pass it to places like JDBC properties.


I think the comment suggests that HideableValue is a misleading name. I really didn't have better ideas how to call this type. Any suggestions?

HideableValue is a type that can either be plain non-sensitive text value OR a secret id that will be resolved into a proper sensitive value much later (the ID itself is nothing that has to be secure).

* <p>The query parameters and user info are stored separately, because they may contain secrets and
* will only be resolved to plain values within {@link org.enso.base.enso_cloud.EnsoSecretHelper}.
*/
public record URIWithSecrets(
Copy link
Member

Choose a reason for hiding this comment

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

How is this different to URISchematic? Why isn't schematic working with HideableValue to beging with?

Copy link
Member Author

Choose a reason for hiding this comment

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

The URISchematic is just a helper method that I need because I could no longer use the Apache URIBuilder. It is encapsulating parts of the logic of building an URI while overriding some parts of it. I did not want to couple this with the Secrets logic as its completely independent concept.

The URIWithSecrets may be converted into URISchematic in 2 ways - either resolving the secret ids to actual secret values (done only in EnsoSecretHelper) OR resolving secrets to just say __SECRET__ (the 'public' appearance). Then URISchematic takes either of these and builds a proper URI.

@radeusgd radeusgd force-pushed the wip/radeusgd/8544-merge-uri-with-query branch 2 times, most recently from 7d864ed to bf0043e Compare December 20, 2023 09:23
Comment on lines +142 to +143
/ : Text -> URI
/ self segment:Text =
Copy link
Member

Choose a reason for hiding this comment

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

not saying it should, but we could add pre the query string part

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think I understand what you mean, could you please clarify?

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't what you mean the thing that is checked in this test?

        Test.specify "should keep existing query arguments intact when extending the path" <|
            uri0 = URI.parse "https://example.com/path?a=b&c=d"
            uri1 = uri0 / "x" / "y"
            uri2 = uri1 . add_query_argument "e" "f"
            uri3 = uri2 / "z"

            uri3.path . should_equal "/path/x/y/z"
            uri3.query . should_equal "a=b&c=d&e=f"
            uri3.to_text . should_equal "https://example.com/path/x/y/z?a=b&c=d&e=f"

or is that sth else?

Base automatically changed from wip/radeusgd/url-encode to develop December 20, 2023 18:01
@radeusgd radeusgd force-pushed the wip/radeusgd/8544-merge-uri-with-query branch from bf0043e to d853c14 Compare December 21, 2023 08:53
@radeusgd radeusgd added the CI: Ready to merge This PR is eligible for automatic merge label Dec 21, 2023
@mergify mergify bot merged commit d41d48e into develop Dec 21, 2023
31 checks passed
@mergify mergify bot deleted the wip/radeusgd/8544-merge-uri-with-query branch December 21, 2023 18:39
@radeusgd radeusgd mentioned this pull request Jan 11, 2024
5 tasks
mergify bot pushed a commit that referenced this pull request Jan 15, 2024
I have added this in #8591, but I have realised it may not be a good idea to have it, so I am removing that particular change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge URI with URI_With_Query
4 participants