nicoru icon indicating copy to clipboard operation
nicoru copied to clipboard

Create Distinct type for Image, Repo, Tag, etc

Open elcritch opened this issue 4 years ago • 1 comments

Looking though the code, it may make sense to define distinct types for tags, image ids, etc. Something like:

let 
   Tag = distinct string
   Repo = distinct string
   Image = distinct string
   ImagePath = distinct string
   ImageId = distinct string
   ...

proc `/`(path: string, image: ImageId): ImagePath = ...

Using this pattern of creating distinct types of strings would be easy to use, but allow the compiler to catch cases where "oops, a tag was used when I meant an image". There's a lot of places where various string types could likely get mixed up!

Distinct types would also help prevent a lot of potential security risks by adding known safe internal types from user input strings. Not sure how much of an issue this is currently, but personally I prefer to prevent certain classes of issues where it''s difficult to know if user input strings have been properly sanitized. For example, the repoUrl = fmt"..." type of things might need sanitizing using URLEncode (or the Nim equivalent) to prevent weird URL related issues (or just bugs...).

If you like the idea I might be able to create a PR for it at some point.

elcritch avatar Jul 01 '21 00:07 elcritch

@elcritch

It looks like a good idea! PR is welcome!

fox0430 avatar Jul 01 '21 08:07 fox0430