Skip to content
Snippets Groups Projects
supertokenEntry.go 1.39 KiB
Newer Older
package supertoken

import (
	"fmt"

	"github.com/zachmann/mytoken/internal/db/dbModels"
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	"github.com/zachmann/mytoken/internal/model"
	"github.com/zachmann/mytoken/internal/supertoken/capabilities"
	"github.com/zachmann/mytoken/internal/supertoken/restrictions"
)

// SuperTokenEntryTree is a tree of SuperTokenEntry
type SuperTokenEntryTree struct {
	Token    dbModels.SuperTokenEntry
	Children []SuperTokenEntryTree
}

func (t *SuperTokenEntryTree) print(level int) {
	for i := 0; i < 2*level; i++ {
		fmt.Printf(" ")
	}
	fmt.Printf("%s\n", t.Token.ID)
	for _, child := range t.Children {
		child.print(level + 1)
	}
}

Gabriel Zachmann's avatar
Gabriel Zachmann committed
func NewSuperTokenEntryFromSuperToken(name string, parent dbModels.SuperTokenEntry, r restrictions.Restrictions, c, sc capabilities.Capabilities, networkData model.NetworkData) (*dbModels.SuperTokenEntry, error) {
	newRestrictions := restrictions.Tighten(parent.Token.Restrictions, r)
	newCapabilities := capabilities.Tighten(parent.Token.Capabilities, c)
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	newSubtokenCapabilities := sc //TODO
	ste := dbModels.NewSuperTokenEntry(name, parent.Token.OIDCSubject, parent.Token.OIDCIssuer, newRestrictions, newCapabilities, newSubtokenCapabilities, networkData)
	ste.ParentID = parent.ID.String()
	rootID := parent.ID.String()
	if !parent.Root() {
		rootID = parent.RootID
	}
	ste.RootID = rootID
	err := ste.Store("Used grant_type super_token")
	if err != nil {
		return nil, err
	}
	return ste, nil
}