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(profiles): rename Profile to ProfileManifest and update related functions #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions corim/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,22 @@ func GetUnsignedCorim(profileID *eat.Profile) *UnsignedCorim {
// Profile associates an EAT profile ID with a set of extensions. It allows
// obtaining new CoRIM and CoMID structures that had associated extensions
// registered.
type Profile struct {
type ProfileManifest struct {
ID *eat.Profile
MapExtensions extensions.Map
}

// GetComid returns a pointer to a new comid.Comid that had the Profile's
// extensions (if any) registered.
func (o *Profile) GetComid() *comid.Comid {
func (o *ProfileManifest) GetComid() *comid.Comid {
ret := comid.NewComid()
o.registerExtensions(ret, ComidMapExtensionPoints)
return ret
}

// GetUnsignedCorim returns a pointer to a new UnsignedCorim that had the
// Profile's extensions (if any) registered.
func (o *Profile) GetUnsignedCorim() *UnsignedCorim {
func (o *ProfileManifest) GetUnsignedCorim() *UnsignedCorim {
ret := NewUnsignedCorim()
ret.Profile = o.ID
o.registerExtensions(ret, UnsignedCorimMapExtensionPoints)
Expand All @@ -216,14 +216,14 @@ func (o *Profile) GetUnsignedCorim() *UnsignedCorim {

// GetSignedCorim returns a pointer to a new SignedCorim that had the
// Profile's extensions (if any) registered.
func (o *Profile) GetSignedCorim() *SignedCorim {
func (o *ProfileManifest) GetSignedCorim() *SignedCorim {
ret := NewSignedCorim()
ret.UnsignedCorim.Profile = o.ID
o.registerExtensions(ret, SignedCorimMapExtensionPoints)
return ret
}

func (o *Profile) registerExtensions(e iextensible, points []extensions.Point) {
func (o *ProfileManifest) registerExtensions(e iextensible, points []extensions.Point) {
exts := extensions.NewMap()
for _, p := range points {
if v, ok := o.MapExtensions[p]; ok {
Expand Down Expand Up @@ -262,7 +262,7 @@ func RegisterProfile(id *eat.Profile, exts extensions.Map) error {
}
}

profilesRegister[strID] = Profile{ID: id, MapExtensions: exts}
profilesRegister[strID] = ProfileManifest{ID: id, MapExtensions: exts}

return nil
}
Expand Down Expand Up @@ -291,14 +291,14 @@ func UnregisterProfile(id *eat.Profile) bool {
// GetProfile returns the Profile associated with the specified ID, or an empty
// profile if no Profile has been registered for the id. The second return
// value indicates whether a profile for the ID has been found.
func GetProfile(id *eat.Profile) (Profile, bool) {
func GetProfile(id *eat.Profile) (ProfileManifest, bool) {
if id == nil {
return Profile{}, false
return ProfileManifest{}, false
}

strID, err := id.Get()
if err != nil {
return Profile{}, false
return ProfileManifest{}, false
}

prof, ok := profilesRegister[strID]
Expand All @@ -309,7 +309,7 @@ type iextensible interface {
RegisterExtensions(exts extensions.Map) error
}

var profilesRegister = make(map[string]Profile)
var profilesRegister = make(map[string]ProfileManifest)

func init() {
for _, p := range SignedCorimMapExtensionPoints {
Expand Down
2 changes: 1 addition & 1 deletion corim/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestProfile_getters(t *testing.T) {
id, err := eat.NewProfile("1.2.3")
require.NoError(t, err)

profile := Profile{
profile := ProfileManifest{
ID: id,
MapExtensions: extensions.NewMap().
Add(comid.ExtComid, &struct{}{}).
Expand Down