Repository navigation
General support for auxiliary resources - #554
Conversation
774b839 to
b9b6582
Compare
|
@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...
Does that cover it or would other steps be missing?
Thanks! |
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.
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:
An implementation of Writing a
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. |
|
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
left a comment
There was a problem hiding this comment.
Agree with conceptual part and implementation. Well done 👍👍👍
|
|
||
| public async canHandle({ identifier }: AuthorizerArgs): Promise<void> { | ||
| if (this.aclManager.isAuxiliaryIdentifier(identifier)) { | ||
| throw new NotImplementedHttpError('WebAclAuthorizer does not support permissions on acl files.'); |
There was a problem hiding this comment.
| throw new NotImplementedHttpError('WebAclAuthorizer does not support permissions on acl files.'); | |
| throw new NotImplementedHttpError('WebAclAuthorizer does not support permissions on auxiliary resources.'); |
There was a problem hiding this comment.
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.
| * 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. |
There was a problem hiding this comment.
I probably did a replace-all for something and this was caught in the crossfire 😅
There was a problem hiding this comment.
Ah no, I just remembered. I actually did this on purpose since there no longer is an AclManager class but only an aclManager variable.
d081a19 to
c91af03
Compare
|
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:
Changes to DataAccessorBasedStoreThis was the main goal of this PR, as this causes us to support most of the spec requirements regarding auxiliary resources.
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 likeAs 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 The other one is the
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. |
ff3d4be to
f5a509e
Compare
|
@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
left a comment
There was a problem hiding this comment.
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
ResourceStoreinterface TSdoc such that the contract becomes that it also manages auxiliary resources.
- Add the
getAuxiliaryIdentifiersfunction to the AuxiliaryManager.
- This is the way to go indeed. (However, comment below).
I notice that currently, aux managers are doing three things:
- identifier management
- adding metadata
- 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
UrlBasedAclManagerandShapeTreeAuxiliaryManager; they both are simply a (Components.js) configuration ofAuxiliaryManager, where you pass the required validator (possibly composite: RDF syntax + further checks) as a constructor argument, as well as".acl"for the extension andfalseforcanDeleteRoot. -
But I think we can even go further: rename
AuxiliaryManagerintoAuxiliaryStrategy(it's not managing anything itself) and make it a composite component that is nothing more than an aggregation of three objects: -
identifiers: IdentifierStrategy(orIdentifierManager)isAuxiliaryIdentifiergetAuxiliaryIdentifiersgetAssociatedIdentifier
-
metadataGenerator: AsyncHandler<{ identifier: ResourceIdentifier, metadata: RepresentationMetadata }, void>handle(implementsaddMetadata)
-
validator: : AsyncHandler<{ identifier: ResourceIdentifier, metadata: RepresentationMetadata }, void>handle(implementsvalidate)
-
In the last two cases, I wonder if we even need to pass
identifier, or whethermetadatacovers that. -
Some components, such as
AuxiliaryLockingStore, can only take theIdentifierStrategybit; they don't need the whole object. -
We could also make the
canDeleteRootmethod part of this. However, I propose to simply drop it. I conjecture it will always befalse. If we need it at any point, we introduce it and set its value through dependency injection.
| * 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| public constructor(converter: RepresentationConverter, suffix = '.acl') { | ||
| super(converter, suffix, ACL.accessControl); | ||
| } | ||
|
|
||
| public canDeleteRoot(): boolean { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
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
|
(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.
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.
Yea I also doubted there. I kept identifier to be in line with the other functions but they could probably be removed.
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 |
|
Partially related: we already have something called an So this here we would need something like |
f5a509e to
f93f7db
Compare
|
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):
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 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. |
f93f7db to
55afca9
Compare
This is in preparation of generalizing permissions of auxiliary resources.
55afca9 to
d242613
Compare
RubenVerborgh
left a comment
There was a problem hiding this comment.
Thanks a lot. Just some random nits.
| protected readonly logger = getLoggerFor(this); | ||
|
|
||
| private readonly resourceAuthorizer: Authorizer; | ||
| private readonly strategy: AuxiliaryIdentifierStrategy; |
There was a problem hiding this comment.
Very minor nit
| private readonly strategy: AuxiliaryIdentifierStrategy; | |
| private readonly aclStrategy: AuxiliaryIdentifierStrategy; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I probably meant auxStrategy. Just found it weird to read strategy in the code below; like, what strategy?
| // 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d242613 to
1fdba9f
Compare
This way locks are always on the associated resource if there is a request on an auxiliary resource.
1fdba9f to
b07b5e5
Compare
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:
Some more notes about the interface:
CompositeAuxiliaryManagerwhich I think could be useful for when we have multiple types. Although this could be thinking too far ahead.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
getRequiredPermissionsin 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 usinggetTypeto 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:
DataAccessorBasedStoreif possible.After last changes, now closes #53, closes #381, closes #385 and closes #573.