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

refactor: Extract Defra specific logic from ACPLocal type #2656

Merged

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented May 29, 2024

Relevant issue(s)

Resolves #2655

Description

Extracts Defra specific logic from the ACPLocal type so that it may be re-used for SourceHub ACP.

None of the code has changed, it's just moved around.

I'm opening a PR now, as a lot of us (including Bruno) are working in this space, and merging refactors like this asap tends to minimise conflicts.

The (WIP) source hub implementation can be found here: #2657

@AndrewSisley AndrewSisley added area/auth Related to the authorization and authentication of data refactor This issue specific to or requires *notable* refactoring of existing codebases and components labels May 29, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.12 milestone May 29, 2024
@AndrewSisley AndrewSisley requested review from Lodek and a team May 29, 2024 20:25
@AndrewSisley AndrewSisley self-assigned this May 29, 2024
@AndrewSisley AndrewSisley force-pushed the 2655-defra-acp-wrapper branch from 47decef to 82f7148 Compare May 29, 2024 20:27
@shahzadlone shahzadlone added the area/acp Related to the acp (access control) system label May 31, 2024
Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

I wonder if we are over abstracting things by having both the ACP and sourcehubClient interfaces. This introduces a complexity which I am not sure we need.

From what I understand so far (correct me if missing something):

  • The ACP interface was combining the "wrapping of sourcehub" + "defra specific acp logic"

  • But rather than re-implementing the wrapping of sourcehub logic for remote acp and the defra specific acp logic you thought perhaps you can separate the sourcehub client to re-use those parts? Hence the current bridge and new interface?

  • The sourcehubClient just seems like a lean wrapper extracting the functions we need from sourcehub. Couldn't this just be a struct? What other thing would implement it other than the sourceHubBridge

acp/source_hub_client.go Outdated Show resolved Hide resolved
acp/source_hub_client.go Outdated Show resolved Hide resolved
acp/source_hub_client.go Outdated Show resolved Hide resolved
@AndrewSisley
Copy link
Contributor Author

AndrewSisley commented May 31, 2024

The ACP interface was combining the "wrapping of sourcehub" + "defra specific acp logic"

Not just the ACP interface, the localACP implementation of that interface was. The ACP interface should/can/continues-to do that.

But rather than re-implementing the wrapping of sourcehub logic for remote acp and the defra specific acp logic you thought perhaps you can separate the sourcehub client to re-use those parts? Hence the current bridge and new interface?

If by those parts, you mean the defra specific logic, yes. It is shared 'business logic' that should be the same regardless of what the underlying sourcehub/acp tech is. Later it can be extracted further so that the wrapper does not only function for sourcehub lib based clients, but any acp client - however I don't want to code for the imaginary and over engineer something that wont get used as such for a while.

The sourcehubClient just seems like a lean wrapper extracting the functions we need from sourcehub. Couldn't this just be a struct? What other thing would implement it other than the sourceHubBridge

I think you are confused. sourceHubBridge implements acp.ACP. sourcehubClient is implemented by acpLocal and acpSourceHub.

@AndrewSisley AndrewSisley requested a review from shahzadlone May 31, 2024 16:57
@shahzadlone
Copy link
Member

Thanks for the clarification, so to understand the full picture:

  • sourcehubClient will be implemented by acpLocal and acpRemote.
  • ACP interface will continue to be the "sourcehub wrapper / bridge (local or global) + defra specfic acp logic"

Is that correct?

@AndrewSisley
Copy link
Contributor Author

Is that correct?

Yes. We shouldn't expose the internals (client vs defra logic spit) outside of the acp package. You can see the source hub implementation of the client in the PR linked in this PR's description

@shahzadlone
Copy link
Member

Thanks for the explanation here and on Discord.

I think ACP interface should be a struct rather than an interface with the new changes, I don't like abstractions at this stage when we only have sourcehub acp that we need to worry about now, mostly for the sake of simplicity.

But the preference isn't a hard blocker however. So will give an approval, would be nice to hear from others too.

@AndrewSisley
Copy link
Contributor Author

I think ACP interface should be a struct rather than an interface with the new changes,

I do strongly disagree with that. acp.ACP is a public type and users should be free to provide their own. The only implementation we have is very much an internal construct too, and we have plans to add more implementations. We also really don't want to couple every referencing location to a concrete type - it makes changing the acp implementation much more expensive.

@AndrewSisley
Copy link
Contributor Author

would be nice to hear from others too.

I'm very happy to continue this discussion post-merge, changing that after this goes in will probably cause far less problems than delaying this merge. I would like to merge this before I start my weekend too (I don't want to have this PR in my head next week).

@AndrewSisley AndrewSisley merged commit 5829f9d into sourcenetwork:develop May 31, 2024
28 of 30 checks passed
@AndrewSisley AndrewSisley deleted the 2655-defra-acp-wrapper branch May 31, 2024 19:25
@jsimnz
Copy link
Member

jsimnz commented May 31, 2024

Want to briefly chime in and say I agree with @AndrewSisley regarding the interface vs struct approach.

I'm not a huge fan of the internals of some of this PR regarding the client approach, but it's fine and wouldn't have caused me to block the merge anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/acp Related to the acp (access control) system area/auth Related to the authorization and authentication of data refactor This issue specific to or requires *notable* refactoring of existing codebases and components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract Defra specific logic from ACPLocal type
3 participants