Auth: Entity type refactor
Opening as a draft to get some feedback.
- The type of
entity.Typehas been changed to an interface. - A new type has been created for each shared entity type that implements the interface. These types are empty structs for the purpose of embedding them into the database type. The types are defined as
entity.Instance,entity.Networkand so on. A variable is also defined for each entity type for ease of use (e.g.var TypeInstance = Instance{}). - Because each entity requires different arguments for creating a URL, these methods are defined on the concrete types and this is not part of the interface.
- In the
db/clusterpackage, theEntityTypetype is now a struct which embeds anentityTypeinterface, theentityTypeinterface embeds(shared/entity).Typeand has methods for returning SQL for each entity type. - A consequence of using interfaces for entity types is that we need to be more careful when checking for equality. We need to always compare them by the
Name()function (e.g.entityType1.Name() == entityType2.Name(). I've added anEqualsmethod to theshared/entitypackage for this.
In order to add a new entity type, one needs to implement the interface in the shared package following the same pattern, and add the entity type to the list of all entity types in that package. Afterwards, the interface in the database package must be implemented (with the shared entity type being embedded in the database type) and this type must also be added to the list in the database package.
Closes #12928
@tomponline this is ready for review when you have some time. It will likely conflict with #13298 so I'll need to rebase when that's merged.
Rebased and ready for review. Thanks.
Ready for round two :)
I've just pushed again as I realised when working on #13072 that I had missed some equality checks that should now be using the entity.Equals method.
I've made the requested changes apart from the open discussions.
Please can you rebase this
@markylaing shall we move this to draft for now?
@markylaing shall we move this to draft for now?
Sure, I've not had time since the external IP allocation has been prioritised.
@tomponline this should be ready to go again when you have some time.
Needs a rebase now im afraid
@tomponline have rebased