Skip to content

General support for auxiliary resources - #554

Merged
jvherweg merged 9 commits into
mainfrom
feat/auxiliary
Feb 18, 2021
Merged

jvherweg merged 9 commits into
mainfrom
feat/auxiliary

Conversation

@jvherweg

@jvherweg jvherweg commented Jan 26, 2021 •

Copy link
Copy Markdown
Member

This is a lot of text (after re-reading this it got a bit longer than expected 😅), but several things in this PR are not set in stone yet so the discussion is the core part. This PR is partially just to see how it could work.

Suggestion on how to handle auxiliary files in a more general way. Currently we only have acl files, but the option exists for more and at some point we at least want to add shape files. .meta files are currently handled differently but this could also change.

There are several design decisions here where there were multiple options which I'll go over below as we might want to change some. The main functions are mostly the same as those that were in AclManager. New ones are:

  • getRequiredPermissions -> Currently used because acl files require different permissions. Could also be removed by editing the authorizer (more on this below)
  • getType -> Returns the type of this auxiliary resource. Used for adding metadata needed for the link headers and could also be used for identifying what type of auxiliary resource we have if needed
  • validate -> used to check if an auxiliary resource is valid. Currently this just checks if the data can be converted (so if it's valid RDF), but this could be extended in the future with shape validation for example.

Some more notes about the interface:

  • All functions take a ResourceIdentifier as input. Reason for this is because otherwise it would be impossible to make the CompositeAuxiliaryManager which I think could be useful for when we have multiple types. Although this could be thinking too far ahead.
  • Wasn't really sure where to put everything, it's currently in ldp/auxiliary.
  • Removed some promises from the original AclManager functions as chances are low those would ever be relevant.

Besides that interface the acl authorizer has been updated. Before, the authorizer had a single if-statement in the beginning to check if the input was an acl file and to take the correct permissions on that. This has now been removed to make the authorizer more consistent. Instead, a new Authorizer has been added for auxiliary resources (and added in a waterfall handler). In case the input is an auxiliary resource the permissions will be changed (as mentioned above), and the request will be passed to the default authorizer with the URI of the associated resource instead. Instead of having getRequiredPermissions in the auxiliary manager interface, it would also be possible to instead have an exception for acl files in this class (either by having 2 manager, or using getType to check what kind of auxiliary resource it is). Later edit: probably should make a specific permissions extractor for acl files, would make more sense than all the other suggestions.

There are still some more things to be added but I already wanted to create this PR for discussion and in case there are problems.

To be added:

  • A new LockingResourceStore. The new one would extend the old one, but edit the calls so the identifier of the associated resource is used for locking when performing operations on auxiliary resources.
  • A new ResourceStore to handle auxiliary behaviour, including:
    • Validation checks on all incoming auxiliary data.
    • Deleting auxiliary resources when the main resource gets deleted. Although other solutions were also suggested in Delete acl when deleting resource #53, I would like to keep everything auxiliary related out of the DataAccessorBasedStore if possible.
    • Add necessary metadata when getting the data (to create the link headers). Writing this just made me realize that the CompositeAuxiliaryHandler is not going to work as I wanted it to (since you need types for all auxiliary resources), so should probably scrap that one again.
    • Specifically for acl files we want to make sure they can't be deleted if they're in a root storage container (Prevent root acl file from being deleted #381). Not sure how to best do this one, either as a specific check in this store or a separate store just for this. Or perhaps we event want a separate store for every auxiliary type instead of having 1 store that handles all types. We probably never are going to have so many auxiliary types that this would become problematic so I'm sort of a fan of this idea.
    • Potentially filter out the references to auxiliary resources when doing a GET request on containers. Currently this would still be a bit annoying though, depending on Sending PATCH to container fails #384.

After last changes, now closes #53, closes #381, closes #385 and closes #573.

@jvherweg
jvherweg force-pushed the feat/auxiliary branch 2 times, most recently from 774b839 to b9b6582 Compare January 26, 2021 15:25
@RubenVerborgh RubenVerborgh self-assigned this Jan 27, 2021
@joshdcollins

joshdcollins commented Jan 27, 2021 •

Copy link
Copy Markdown

@joachimvh I've been following CSS' development, with a specific interest in how auxiliary resources would be supported.

Apologies in advance of any of these questions / thoughts are premature given the state of the PR...

  1. It looks like if I wanted to add support for a new aux resource the following changes would be required:
    • Create an implementation of SuffixAuxiliaryManager to determine the suffix to use
    • Create an implementation of MetadataWriter to express the link header
    • Wire the above into the config JSON

Does that cover it or would other steps be missing?

  1. It would be a welcome developer / configurer experience to be able to define "generic" auxiliary resources with only changes in the config JSON by specifying suffix and required permissions without the need to create new classes (unless extending functionality was required). It appears that the SuffixAuxiliaryManager is very close to that (or perhaps accomplishes it now and I don't fully grasp the DI of component.js).

Thanks!
jc

@jvherweg

Copy link
Copy Markdown
Member Author

Apologies in advance of any of these questions / thoughts are premature given the state of the PR...

Like you see, this PR is not a finished product yet and more of a look into how it could be done. After pushing this I already had some different ideas about how to tackle some things here. So my answer here is going to be more of a thought experiment on "what could be" once this PR would be finished.

  1. It looks like if I wanted to add support for a new aux resource the following changes would be required:

    • Create an implementation of SuffixAuxiliaryManager to determine the suffix to use
    • Create an implementation of MetadataWriter to express the link header
    • Wire the above into the config JSON

Does that cover it or would other steps be missing?

It depends on how similar the wanted behaviour is for your new type of aux resource compared to those that already exist. The main idea behind this PR is that the few aux resources that are defined in the spec (acl, shape, potentially meta) share several behaviours:

  • They have to be deleted when the main resource is deleted.
  • Permissions have to be checked on the main resource when accessing them.
  • They have to be exposed through a link header.
  • We want to not include them when showing the contents of a container.
  • Internally we want our locking system to lock the main resource when accessing them.
  • Their data has to be validated before being stored.
  • Potentially something I'm forgetting.
    In case your aux resource wants different behaviour it would need a custom implementation, so let's assume that it does want this behaviour.

An implementation of AuxiliaryManager would be needed then. SuffixAuxiliaryManager is a helper class to cover aux files with even more similar behaviour: their URIs are made by adding a suffix (e.g., .acl) to the original URL, and they have to at least be valid RDF.

Writing a MetadataWriter would actually not be needed. Currently there's one in place for acl, but the idea would be to remove that one once this PR is finished. As mentioned in the "to be added" section above, the idea would then be to have a class that, for all aux types, handles adding the correct metadata. We already have a generic metadata writer in place that can convert this kind of metadata to a correct header. So the only thing that would be required there would be some extra configuration in the JSON.

  1. It would be a welcome developer / configurer experience to be able to define "generic" auxiliary resources with only changes in the config JSON by specifying suffix and required permissions without the need to create new classes (unless extending functionality was required). It appears that the SuffixAuxiliaryManager is very close to that (or perhaps accomplishes it now and I don't fully grasp the DI of component.js).

That is true actually. Currently it would not be possible due to being an abstract class, but it would not require that much change to be an actual class that can completely be configured. The main reason it's currently not like this is because the 2 main cases I considered are those from the spec (acl and shapes), and both of these would require custom validation anyway besides just the RDF check. But if there is a use case for supporting new aux types that only require RDF validation that is certainly something we could consider.

@joshdcollins

Copy link
Copy Markdown

Thanks for the response -- I appreciate the detail.

In thinking more about it, I was likely over-simplifying the lifecycle of aux resources and agree that the case for purely configurable ones is probably more narrow than I had thought.

I could imagine a use case for purely "client-managed" aux resources that have the behavior you bulleted above. For instance, in advance of server-side support for shape trees we are performing client-side validation and just requiring that a server be able to expose a given link header and store content associated with it. That said, implementing this would be trivial given your proposal above.

Thanks again!

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree with conceptual part and implementation. Well done 👍👍👍

Comment thread config/presets/acl.json Resolved
Comment thread config/presets/acl.json Resolved

public async canHandle({ identifier }: AuthorizerArgs): Promise<void> {
if (this.aclManager.isAuxiliaryIdentifier(identifier)) {
throw new NotImplementedHttpError('WebAclAuthorizer does not support permissions on acl files.');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
throw new NotImplementedHttpError('WebAclAuthorizer does not support permissions on acl files.');
throw new NotImplementedHttpError('WebAclAuthorizer does not support permissions on auxiliary resources.');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The auxiliary manager it takes as input is one specifically for acl files (which it needs to find the correct acl resource for a permission), so the check here will only check specifically for acl resources and not all auxiliary resources in general. "files" still needs to be changed to "resources" though.

Comment thread src/authorization/WebAclAuthorizer.ts Outdated
* Returns the acl triples that are relevant for the given identifier.
* These can either be from a corresponding acl file or an acl file higher up with defaults.
* Rethrows any non-NotFoundHttpErrors thrown by the AclManager or ResourceStore.
* Rethrows any non-NotFoundHttpErrors thrown by the aclManager or ResourceStore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I probably did a replace-all for something and this was caught in the crossfire 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah no, I just remembered. I actually did this on purpose since there no longer is an AclManager class but only an aclManager variable.

Comment thread src/ldp/auxiliary/UrlBasedAclManager.ts Resolved
@jvherweg

jvherweg commented Feb 3, 2021 •

Copy link
Copy Markdown
Member Author

This PR has all the planned features now and closes 4 issues (added them in main message for auto-closure). Since it's quite big I'm going to link changes done to commits.

Changes since last version:

  • All resolved comments above
  • (Was already present but not mentioned explicitly): A new locking store that takes auxiliary resources into account.
  • getType was replaced with addMetadata
  • SuffixAuxiliaryManager takes an optional link parameter to be used for adding metadata
  • getPermissions was removed, there now is an acl permissions extractor instead
  • There is a new function in the interface: canDeleteRoot (more on this one in "Things I don't like")
  • UrlBasedAclManager is now almost empty but we will need this in the future anyway for acl validation
  • CompositeAuxiliaryManager now has a function getAuxiliaryIdentifiers (also more on this in "Things I don't like")
  • Updated some RepresentationMetadata helper functions (needed for commit after that)
  • DataAccessorBasedStore now does the spec required auxiliary actions
  • AclLinkMetadataWriter was removed since it can now be simply configured

Changes to DataAccessorBasedStore

This was the main goal of this PR, as this causes us to support most of the spec requirements regarding auxiliary resources.
The following features were added to the store:

  • GET: add auxiliary-related metadata
  • GET: remove ldp:contains triples of auxiliary resources
  • POST: reject slugs that would create an auxiliary resource
  • PUT: validate the incoming data of auxiliary resources
  • PATCH: no change here of course, but because of the other changes PATCH requests will also get validated (A Solid server SHOULD sanity check ACL auxiliary resources #571)
  • DELETE: prevent deletion of acl files in root storage containers
  • DELETE: allow deletion of containers with only auxiliary resources
  • DELETE: also delete corresponding auxiliary resources when deleting a normal resource

I initially tried creating a separate store with this functionality, but supporting all of this was just too much of a hassle. Especially the DELETE additions would require so many more calls to the backend store to be supported correctly.

This does tie this logic into the DataAccessorBasedStore, but on the other hand, the DataAccessorBasedStore already was our central point of supporting Solid logic on resources: not allowing deletion of root storage containers, preventings POSTs to non-containers, not allowing identifiers with and without trailing slash, and many many more. In this way the advantage is that there still is only one place to look for most of the spec required behaviour regarding resources.

The main issue with this is if in the future someone wants to create a new store (not a new DataAccessor). That store would then have to replicate all of this behaviour. But this would already have been a problem anyway, this PR does not increase the complexity of that problem that much. Potentially this could be easily fixed by moving more parts of the behaviour to separate protected functions in the DataAccessorBasedStore so they can be reused. Another solution would be to completely rethink the architecture of this class so functionality can be abstracted to separate classes that can be plugged in? I would say to cross that bridge when we get there, although if we do want to take this situation into account perhaps we can make an issue around this and try to make a new backend ResourceStore and see what is missing to make that easy.

Things I don't like

As mentioned above, there are 2 things in this PR I'm not really happy with and am open to suggestions on how to change those parts.

One is the fact that that acl files in root storage containers can't be deleted. For this the AuxiliaryManager interface now has the function canDeleteRoot which returns a boolean. But the only point of this function is for this specific case so it feels a bit unfortunate to add it just for that. On the other hand I have no idea how to improve upon this. Other solutions could be to add a separate store that supports just this behaviour, or have the DataAccessorBasedStore take 2 separate auxiliary managers as input, but both of those feel way worse

The other one is the getAuxiliaryIdentifiers function in the composite auxiliary manager. This is needed so we can know all auxiliary resources related to the main resource, so we can delete them together with the main resource. But this now causes the composite manager to expose a function not in the interface, so the DataAccessorBasedStore is required to take that specific type of manager as input parameter instead of a general auxiliary manager. Some other solutions (for each of which a case can be made imo):

  • Delete the CompositeAuxiliaryManager and have the store take an array of auxiliary managers instead. The disadvantage of this is that we would then need helper functions for all the things the composite manager does. There are more cases where we need to handle all auxiliary types separately so would need several new methods to iterate over them (either in the store or a separate AuxiliaryUtil file)
  • Add the getAuxiliaryIdentifiers function to the AuxiliaryManager. This might be the cleanest solution but on the other hand for single auxiliary managers it would be silly to have this function.

In comparison to the rest of the PR these are 2 minor things but they're the main ugly things still in there so I would be happy to have a cleaner solution there.

@jvherweg
jvherweg force-pushed the feat/auxiliary branch 4 times, most recently from ff3d4be to f5a509e Compare February 3, 2021 10:13
@joshdcollins

Copy link
Copy Markdown

@joachimvh As a point of validation for the changes in this PR -- I was able to fairly trivially implement support for exposing and maintaining an additional aux. resource -- janeirodigital@961f99f

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the hard work and the detailed explanation, @joachimvh.
After reviewing the code, I think this is the way to go, and I have some comments that will hopefully lead to further simplifications.

It is important to note that the architecture upon which the server is based, was created before the need for multiple auxiliary resources was apparent. So the friction we feel is because the architecture indeed did not take this into account. However, by extending the ResourceStore contract to also cover auxiliary resources (as we do here), I think we're there.


  • Let's change the ResourceStore interface TSdoc such that the contract becomes that it also manages auxiliary resources.

  • Add the getAuxiliaryIdentifiers function to the AuxiliaryManager.
  • This is the way to go indeed. (However, comment below).

I notice that currently, aux managers are doing three things:

  1. identifier management
  2. adding metadata
  3. validation

And canDeleteRoot too. But let's tackle that one later.

However, those 3 functions are independent—yet they are currently tied into a manager.

Concretely: ACL resources have .acl and need RDF validation.
But even if ACL resources would follow an ?acl pattern (as ESS currently does), they would still need validation.
And the same metadata.

And non-ACL auxiliaries might also need the RDF validation, even if they are not suffix-based!

As per your explanation above, I note that the existence of a nearly empty UrlBasedAclManager is because you are leaving an opening for validation. And similarly, @joshdcollins has ShapeTreeAuxiliaryManager. But I don't think you have to create subclasses at all—this can all done via configuration.

  • Step 1 is to split validation out of the aux managers. They should be independent validators.

  • Then we don't need to create UrlBasedAclManager and ShapeTreeAuxiliaryManager; they both are simply a (Components.js) configuration of AuxiliaryManager, where you pass the required validator (possibly composite: RDF syntax + further checks) as a constructor argument, as well as ".acl" for the extension and false for canDeleteRoot.

  • But I think we can even go further: rename AuxiliaryManager into AuxiliaryStrategy (it's not managing anything itself) and make it a composite component that is nothing more than an aggregation of three objects:

  • identifiers: IdentifierStrategy (or IdentifierManager)

    • isAuxiliaryIdentifier
    • getAuxiliaryIdentifiers
    • getAssociatedIdentifier
  • metadataGenerator: AsyncHandler<{ identifier: ResourceIdentifier, metadata: RepresentationMetadata }, void>

    • handle (implements addMetadata)
  • validator: : AsyncHandler<{ identifier: ResourceIdentifier, metadata: RepresentationMetadata }, void>

    • handle (implements validate)
  • In the last two cases, I wonder if we even need to pass identifier, or whether metadata covers that.

  • Some components, such as AuxiliaryLockingStore, can only take the IdentifierStrategy bit; they don't need the whole object.

  • We could also make the canDeleteRoot method part of this. However, I propose to simply drop it. I conjecture it will always be false. If we need it at any point, we introduce it and set its value through dependency injection.

Comment thread config/presets/acl.json Resolved
* An {@link AuxiliaryManager} that combines multiple AuxiliaryManagers into one.
* Uses `isAuxiliaryIdentifier` to know which manager to call for which call.
*/
export class CompositeAuxiliaryManager implements AuxiliaryManager {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So perhaps more of a RoutingAuxilaryManager then (for the specific type of composition it enables)?
I wonder if we want a generic interface/class for general composite classes, to be used as a tag perhaps. This interface could expose a sources getter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is something to be said for generalizing composite classes, but I'm going to skip that for this PR.

// Stream has been drained so need to create new stream
representation.data = guardedStreamFrom(data);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this is syntactical validation, this definitely needs to move to a RdfSyntaxValidator.

And perhaps validate does not need to be a method of an aux manager at all; this should just be delegated to a validator. After all, the identifier management strategy (suffix) is completely independent from the validation.

Does this assume that all aux files are RDF?

@jvherweg jvherweg Feb 4, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does this assume that all aux files are RDF?

When I originally wrote the idea for this class I saw all examples of auxiliary files were RDF so I made a helper function for that, but now I see that the spec actually has been updated to say that all auxiliary files have to be RDF ( "Auxiliary resources are represented as RDF documents" ), so now we have to assume that.

Comment thread src/ldp/auxiliary/UrlBasedAclManager.ts Outdated
Comment on lines +14 to +20
public constructor(converter: RepresentationConverter, suffix = '.acl') {
super(converter, suffix, ACL.accessControl);
}

public canDeleteRoot(): boolean {
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So this could actually be pure config, i.e., Components.js instantiation with converter, ".acl", false, ACL.accessControl as parameters?

Together th my comment above regarding validation: if we replace converter by validator, then this seems to void your statement that

UrlBasedAclManager is now almost empty but we will need this in the future anyway for acl validation

and we don't need specific classes.

Also works for janeirodigital@961f99f#diff-998bf041f3d60d5333d346f241b3fff0b9923f822689936d5a04fa7d74e2d267R5-R12

Comment thread src/storage/AuxiliaryLockingStore.ts Resolved
Comment thread src/ldp/auxiliary/AuxiliaryManager.ts Resolved
@RubenVerborgh RubenVerborgh removed their assignment Feb 3, 2021
@jvherweg

jvherweg commented Feb 4, 2021

Copy link
Copy Markdown
Member Author

(Replying to the main comment before going through the individual comments)

It's the main problem of how much modularization we want vs how complicated it would become to configure everything. Will look into doing it like this since I don't see any major problems with this at first.

However, those 3 functions are independent—yet they are currently tied into a manager.

Don't completely agree since the identifier management is probably always going to be necessary for adding the metadata. They can still be separated though but the metadata would need to be injected with the identifier management. Or the IdentifierStrategy could be a required parameter for the handle method of the metadata generator. Potentially also for the validator once we do more than simple RDF checking there.

In the last two cases, I wonder if we even need to pass identifier, or whether metadata covers that.

Yea I also doubted there. I kept identifier to be in line with the other functions but they could probably be removed.

We could also make the canDeleteRoot method part of this. However, I propose to simply drop it. I conjecture it will always be false.

There are currently 2 examples of auxiliary resources in the spec: acl files and description resources. We currently obfuscate the second one by internally storing it as metadata, but that is an example of an auxiliary resouce needing this value to be true.

@jvherweg

jvherweg commented Feb 4, 2021

Copy link
Copy Markdown
Member Author

Partially related: we already have something called an IdentifierStrategy, which mostly covers relative container behaviour: https://github.com/solid/community-server/blob/main/src/util/identifiers/IdentifierStrategy.ts

So this here we would need something like AuxiliaryIdentifierStrategy.

@jvherweg

jvherweg commented Feb 5, 2021

Copy link
Copy Markdown
Member Author

Version 3!

Although there are some comments on the previous version that could change things, this should already mostly match the new suggestion.

Although a lot is re-written, functionality wise not much changed. The changes to the DataAccessorBasedStore are pretty much the same for example. The main changes are the auxiliary related interfaces which have completely changed, and the corresponding configs.

An overview (main points are interfaces, sub points are implementations):

  • AuxiliaryIdentifierStrategy has all the identifier related functions. Now with getAuxiliaryIdentifiers although it still sort of feels weird there. Also the name is very long.
    • SuffixAuxiliaryIdentifierStrategy generates identifiers based on a suffix
    • RoutingAuxiliaryIdentifierStrategy combines multiple strategies into one.
  • MetadataGenerator takes as input a RepresentationMetadata and adds to it somehow
    • LinkMetadataGenerator adds links to auxiliary resources based on a given link predicate
  • Validator takes a Representation as input and validates it somehow. There's something to be said for calling it a RepresentationValidator.
    • RdfValidator validates a representation by checking if the data stream contains valid RDF in any format supported by the given converter
  • AuxiliaryStrategy extends AuxiliaryIdentifierStrategy and adds canDeleteRoot, addMetadata and validate functions
    • CompositeAuxiliaryStrategy takes as input an AuxiliaryIdentifierStrategy, a MetadataGenerator, a Validator and a boolean (for canDeleteRoot)
    • RoutingAuxiliaryStrategy extends RoutingAuxiliaryIdentifierStrategy and adds support for the 3 other functions

An example of how the acl strategy is now configured:

    {
      "@id": "urn:solid-server:default:AclIdentifierStrategy",
      "@type": "SuffixAuxiliaryIdentifierStrategy",
      "SuffixAuxiliaryIdentifierStrategy:_suffix": ".acl"
    },
    {
      "@id": "urn:solid-server:default:AclStrategy",
      "@type": "CompositeAuxiliaryStrategy",
      "CompositeAuxiliaryStrategy:_identifierStrategy": {
        "@id": "urn:solid-server:default:AclIdentifierStrategy"
      },
      "CompositeAuxiliaryStrategy:_metadataGenerator": {
        "@type": "LinkMetadataGenerator",
        "LinkMetadataGenerator:_link": "http://www.w3.org/ns/auth/acl#accessControl",
        "LinkMetadataGenerator:_identifierStrategy": {
          "@id": "urn:solid-server:default:AclIdentifierStrategy"
        }
      },
      "CompositeAuxiliaryStrategy:_validator": {
        "@id": "urn:solid-server:default:RdfValidator"
      },
      "CompositeAuxiliaryStrategy:_canDeleteRoot": false
    }

So some duplication on the AclIdentifierStrategy part. This entire block is what would be needed for a new auxiliary resource.

For all classes that need to support all auxiliary resources there's also this:

    {
      "@id": "urn:solid-server:default:AuxiliaryStrategy",
      "@type": "RoutingAuxiliaryStrategy",
      "RoutingAuxiliaryStrategy:_sources": [
        {
          "@id": "urn:solid-server:default:AclStrategy"
        }
      ]
    },

So new strategies would them simply have to be added to this list to be supported by all relevant classes. Some classes only require the IdentifierStrategy parts, but the full strategy extends that interface so no need to have both.

This is in preparation of generalizing permissions
of auxiliary resources.

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot. Just some random nits.

protected readonly logger = getLoggerFor(this);

private readonly resourceAuthorizer: Authorizer;
private readonly strategy: AuxiliaryIdentifierStrategy;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very minor nit

Suggested change
private readonly strategy: AuxiliaryIdentifierStrategy;
private readonly aclStrategy: AuxiliaryIdentifierStrategy;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

strategy is correct here since this authorizer handles all auxiliary resources. I do notice in the configs that currently it is linked to the acl strategy (which is sort of correct since it's the only one we have), but I should already link it to the composite one for when future auxiliary types get added.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I probably meant auxStrategy. Just found it weird to read strategy in the code below; like, what strategy?

Comment thread src/ldp/auxiliary/AuxiliaryStrategy.ts Resolved
Comment thread src/ldp/auxiliary/AuxiliaryStrategy.ts Resolved
Comment on lines +29 to +40
// Read data in memory first so it does not get lost
const data = await arrayifyStream(representation.data);
const preferences = { type: { [INTERNAL_QUADS]: 1 }};

// Creating new representation since converter might edit metadata
const tempRepresentation = new BasicRepresentation(data, identifier, representation.metadata.contentType);
const result = await this.converter.handleSafe({ identifier, representation: tempRepresentation, preferences });
// Drain stream to make sure data was parsed correctly
await arrayifyStream(result.data);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a later PR, let's create a utility for cloning a representation.
Perhaps mark this as TODO already.

But I'm missing a comment saying: we're just parsing the whole thing here.

I wonder whether we can double pipe (but I remember this causing a hanging issue at some point.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Double piping is dangerous and can cause some weird errors if for example one of the pipes errors further down the line. Also backpressuring can get more complicated there. So I would prefer to avoid it as much as possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed on double piping; but the risk is memory hogging. I would strongly suggest to make this a utility method, so we can at least keep track of where it is used.

@jvherweg
jvherweg merged commit 8ccc68d into main Feb 18, 2021
@jvherweg
jvherweg deleted the feat/auxiliary branch February 18, 2021 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants