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

WIP: Improve parser for WAC Allow header #1326

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ThisIsMissEm
Copy link
Contributor

@ThisIsMissEm ThisIsMissEm commented Nov 8, 2021

This new parser is more thoroughly tested, and also has a small efficiency gain: we only parse the header once, and then make assertions on it, rather than parsing once for each scope group.

There's not yet a ticket for this work, as it was just an improvement I saw that we could make to improve code quality (I wasn't working on anything else more important today whilst I was waiting for feedback on scheduled work)

Related work: https://github.com/solid/wac-allow

Checklist

  • All acceptance criteria are met.
  • Relevant documentation, if any, has been written/updated. not sure if this needs updates, as it's an internal API
  • The changelog has been updated, if applicable. not sure if this needs updates, as it's an internal API
  • New functions/types have been exported in index.ts, if applicable. n/a
  • New modules (i.e. new .ts files) are listed in the exports field in package.json, if applicable. n/a
  • New modules (i.e. new .ts files) are listed in the typedocOptions.entryPoints field in tsconfig.json, if applicable. n/a
  • Commits in this PR are minimal and have descriptive commit messages.

This new parser is more thoroughly tested, and also has a small efficiency gain: we only parse the header once, and then make assertions on it, rather than parsing once for each scope group.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 8, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dafe51d:

Sandbox Source
solid-client-sandbox Configuration

*/

// TODO: Should we move this type internally, as the Access in this file is not strictly the same as ACL Access
import { Access } from "../acl/acl";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NSeydoux @VirginiaBalseiro what're your thoughts on this one? I think parsing WAC Allow shouldn't be re-using data structures from ACL, as they are different things (the types just happen to currently be compatible)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well it kind of makes sense that the Access definition defined in ACL is used for the WAC-Allow header, given that the WAC-Allow header was initially described in the ACL spec. We have another Access type definition from the access/universal submodule for universal (i.e. for both ACL-controlled and ACP-controlled Pods), which is somewhat different (because ACP has a different notion of Control than ACL), but could maybe used here, since the WAC-Allow header is now present in both ACL and ACP specs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make sense to rename Access in ./acl/acl to AclAccess (we would need to export it still as Access but mark that as a deprecated name (that'd give interface/type naming consistency within Acl

Then have wacAllow use a internal_Access type that's compatible? There's also a WacAccess in https://github.com/inrupt/solid-client-js/blob/c8da4e5b0a7baa20ff04558b7e06d1a42e8df3ae/src/access/wac.ts — I'm not sure what this is exactly, and it's undocumented in the currently released SDK version, as far as I can tell.

Perhaps we move the WacAccess up to a ./wac-allow directory, and move WacAccess and the parser / transform there?

Copy link
Contributor

Choose a reason for hiding this comment

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

The Access interface (there is no reason for it to be a type considering its declaration) should in my opinion:

  1. Be moved to a type folder under src: /src/type/
  2. Have all the modes
  3. Be used everywhere such Objects are inputs/outputs (we need to remove all the aliasing and other similar definitions)

It would be particularly convenient to have one place where all the standard interfaces are defined.
We really need to remove all the aliasing going on, it is exactly the opposite of what interfaces are for. You don't want 20 names for the same thing, you want 1 name for a specific shape and as few of them as required.

As a sidenote, the ACP specification will adopt the standard Solid access modes shortly, that is, use the acl:Control mode just like WAC. It is a design flaw that it currently invents another mechanism. The operations entailed by Access Modes are defined at the Solid protocol level.

Copy link
Contributor Author

@ThisIsMissEm ThisIsMissEm left a comment

Choose a reason for hiding this comment

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

Highlighted a few areas in the diff that might be of interest

return entries;
}

function internal_getWacPermissions(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure this is named correctly / strictly belongs here; perhaps internal_getPermissions would be better, as it's just checking a parsed WAC Allow for given values

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me, we can always move it if it becomes relevant elsewhere.


return {
read: permissions.includes("read"),
append: permissions.includes("append") || permissions.includes("write"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 the way https://github.com/inrupt/solid-client-js/blob/main/src/resource/resource.internal.ts#L87-L100 is written was motivated by type definitions, if I recall correctly the TS compiler was complaining if the appendand write values were not constants, but this looks definitely simpler.

@ThisIsMissEm
Copy link
Contributor Author

I'm not sure why CD / cd-end-to-end-tests (14.x) (push) Failing after 11m — cd-end-to-end-tests (14.x) is failing — the output doesn't make a lot of sense to me.

*/

// TODO: Should we move this type internally, as the Access in this file is not strictly the same as ACL Access
import { Access } from "../acl/acl";
Copy link
Contributor

Choose a reason for hiding this comment

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

Well it kind of makes sense that the Access definition defined in ACL is used for the WAC-Allow header, given that the WAC-Allow header was initially described in the ACL spec. We have another Access type definition from the access/universal submodule for universal (i.e. for both ACL-controlled and ACP-controlled Pods), which is somewhat different (because ACP has a different notion of Control than ACL), but could maybe used here, since the WAC-Allow header is now present in both ACL and ACP specs.

return entries;
}

function internal_getWacPermissions(
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me, we can always move it if it becomes relevant elsewhere.


return {
read: permissions.includes("read"),
append: permissions.includes("append") || permissions.includes("write"),
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 the way https://github.com/inrupt/solid-client-js/blob/main/src/resource/resource.internal.ts#L87-L100 is written was motivated by type definitions, if I recall correctly the TS compiler was complaining if the appendand write values were not constants, but this looks definitely simpler.

@ThisIsMissEm ThisIsMissEm marked this pull request as draft February 1, 2022 19:08
@ThisIsMissEm ThisIsMissEm changed the title [WIP] Improve parser for WAC Allow header WIP: Improve parser for WAC Allow header Feb 3, 2022
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.

None yet

3 participants