lxd icon indicating copy to clipboard operation
lxd copied to clipboard

Auth: Entity type refactor

Open markylaing opened this issue 1 year ago • 11 comments

Opening as a draft to get some feedback.

  • The type of entity.Type has 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.Network and 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/cluster package, the EntityType type is now a struct which embeds an entityType interface, the entityType interface embeds (shared/entity).Type and 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 an Equals method to the shared/entity package 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

markylaing avatar Apr 05 '24 11:04 markylaing

@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.

markylaing avatar Apr 10 '24 08:04 markylaing

Rebased and ready for review. Thanks.

markylaing avatar Apr 10 '24 12:04 markylaing

Ready for round two :)

markylaing avatar Apr 11 '24 12:04 markylaing

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.

markylaing avatar Apr 11 '24 13:04 markylaing

I've made the requested changes apart from the open discussions.

markylaing avatar Apr 12 '24 13:04 markylaing

Please can you rebase this

tomponline avatar Apr 23 '24 11:04 tomponline

@markylaing shall we move this to draft for now?

tomponline avatar Apr 26 '24 15:04 tomponline

@markylaing shall we move this to draft for now?

Sure, I've not had time since the external IP allocation has been prioritised.

markylaing avatar Apr 26 '24 15:04 markylaing

@tomponline this should be ready to go again when you have some time.

markylaing avatar May 03 '24 16:05 markylaing

Needs a rebase now im afraid

tomponline avatar Jun 06 '24 18:06 tomponline

@tomponline have rebased

markylaing avatar Jun 13 '24 08:06 markylaing