Skip to content
Snippets Groups Projects
Commit f4b27169 authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

Rename file and struct for DID:WEB to URL transformation

parent c19e7248
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ func main() { ...@@ -87,7 +87,7 @@ func main() {
taskFuncs := regofunc.NewTaskFuncs(cfg.Task.Addr, httpClient) taskFuncs := regofunc.NewTaskFuncs(cfg.Task.Addr, httpClient)
ocmFuncs := regofunc.NewOcmFuncs(cfg.OCM.Addr, httpClient) ocmFuncs := regofunc.NewOcmFuncs(cfg.OCM.Addr, httpClient)
signerFuncs := regofunc.NewSignerFuncs(cfg.Signer.Addr, httpClient) signerFuncs := regofunc.NewSignerFuncs(cfg.Signer.Addr, httpClient)
didTransformerFuncs := regofunc.NewDIDTransformerFuncs() didTransformerFuncs := regofunc.NewDIDWebFuncs()
regofunc.Register("cacheGet", rego.Function3(cacheFuncs.CacheGetFunc())) regofunc.Register("cacheGet", rego.Function3(cacheFuncs.CacheGetFunc()))
regofunc.Register("cacheSet", rego.Function4(cacheFuncs.CacheSetFunc())) regofunc.Register("cacheSet", rego.Function4(cacheFuncs.CacheSetFunc()))
regofunc.Register("didResolve", rego.Function1(didResolverFuncs.ResolveFunc())) regofunc.Register("didResolve", rego.Function1(didResolverFuncs.ResolveFunc()))
...@@ -100,8 +100,8 @@ func main() { ...@@ -100,8 +100,8 @@ func main() {
regofunc.Register("verifyProof", rego.Function1(signerFuncs.VerifyProof())) regofunc.Register("verifyProof", rego.Function1(signerFuncs.VerifyProof()))
regofunc.Register("ocmLoginProofInvitation", rego.Function2(ocmFuncs.GetLoginProofInvitation())) regofunc.Register("ocmLoginProofInvitation", rego.Function2(ocmFuncs.GetLoginProofInvitation()))
regofunc.Register("ocmLoginProofResult", rego.Function1(ocmFuncs.GetLoginProofResult())) regofunc.Register("ocmLoginProofResult", rego.Function1(ocmFuncs.GetLoginProofResult()))
regofunc.Register("didToURL", rego.Function1(didTransformerFuncs.ToURLFunc())) regofunc.Register("didToURL", rego.Function1(didTransformerFuncs.DIDToURLFunc()))
regofunc.Register("urlToDID", rego.Function1(didTransformerFuncs.FromURLFunc())) regofunc.Register("urlToDID", rego.Function1(didTransformerFuncs.URLToDIDFunc()))
} }
// subscribe the cache for policy data changes // subscribe the cache for policy data changes
......
...@@ -17,7 +17,7 @@ const ( ...@@ -17,7 +17,7 @@ const (
defaultURLPath = ".well-known" defaultURLPath = ".well-known"
) )
type DIDTransformerFuncs struct{} type DIDWebFuncs struct{}
type DID struct { type DID struct {
scheme string // scheme is always "did" scheme string // scheme is always "did"
...@@ -25,11 +25,11 @@ type DID struct { ...@@ -25,11 +25,11 @@ type DID struct {
path string // path is the unique URI assigned by the DID method path string // path is the unique URI assigned by the DID method
} }
func NewDIDTransformerFuncs() *DIDTransformerFuncs { func NewDIDWebFuncs() *DIDWebFuncs {
return &DIDTransformerFuncs{} return &DIDWebFuncs{}
} }
func (dt *DIDTransformerFuncs) ToURLFunc() (*rego.Function, rego.Builtin1) { func (dw *DIDWebFuncs) DIDToURLFunc() (*rego.Function, rego.Builtin1) {
return &rego.Function{ return &rego.Function{
Name: "url_from_did", Name: "url_from_did",
Decl: types.NewFunction(types.Args(types.S), types.A), Decl: types.NewFunction(types.Args(types.S), types.A),
...@@ -45,7 +45,7 @@ func (dt *DIDTransformerFuncs) ToURLFunc() (*rego.Function, rego.Builtin1) { ...@@ -45,7 +45,7 @@ func (dt *DIDTransformerFuncs) ToURLFunc() (*rego.Function, rego.Builtin1) {
return nil, errors.New("DID cannot be empty") return nil, errors.New("DID cannot be empty")
} }
u, err := dt.didToURL(did) u, err := dw.didToURL(did)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -54,7 +54,7 @@ func (dt *DIDTransformerFuncs) ToURLFunc() (*rego.Function, rego.Builtin1) { ...@@ -54,7 +54,7 @@ func (dt *DIDTransformerFuncs) ToURLFunc() (*rego.Function, rego.Builtin1) {
} }
} }
func (dt *DIDTransformerFuncs) FromURLFunc() (*rego.Function, rego.Builtin1) { func (dw *DIDWebFuncs) URLToDIDFunc() (*rego.Function, rego.Builtin1) {
return &rego.Function{ return &rego.Function{
Name: "did_from_url", Name: "did_from_url",
Decl: types.NewFunction(types.Args(types.S), types.A), Decl: types.NewFunction(types.Args(types.S), types.A),
...@@ -77,7 +77,7 @@ func (dt *DIDTransformerFuncs) FromURLFunc() (*rego.Function, rego.Builtin1) { ...@@ -77,7 +77,7 @@ func (dt *DIDTransformerFuncs) FromURLFunc() (*rego.Function, rego.Builtin1) {
return nil, errors.New("invalid URL for did:web method") return nil, errors.New("invalid URL for did:web method")
} }
did := dt.urlToDID(uri) did := dw.urlToDID(uri)
return ast.StringTerm(did.String()), nil return ast.StringTerm(did.String()), nil
} }
...@@ -85,7 +85,7 @@ func (dt *DIDTransformerFuncs) FromURLFunc() (*rego.Function, rego.Builtin1) { ...@@ -85,7 +85,7 @@ func (dt *DIDTransformerFuncs) FromURLFunc() (*rego.Function, rego.Builtin1) {
// didToURL transforms a valid DID, created by the "did:web" Method Specification, to a URL. // didToURL transforms a valid DID, created by the "did:web" Method Specification, to a URL.
// Documentation can be found here: https://w3c-ccg.github.io/did-method-web/ // Documentation can be found here: https://w3c-ccg.github.io/did-method-web/
func (dt *DIDTransformerFuncs) didToURL(DID string) (*url.URL, error) { func (dw *DIDWebFuncs) didToURL(DID string) (*url.URL, error) {
ss := strings.Split(DID, didSeparator) ss := strings.Split(DID, didSeparator)
if len(ss) < 3 { if len(ss) < 3 {
return nil, errors.New("invalid DID, host is not found") return nil, errors.New("invalid DID, host is not found")
...@@ -117,7 +117,7 @@ func (dt *DIDTransformerFuncs) didToURL(DID string) (*url.URL, error) { ...@@ -117,7 +117,7 @@ func (dt *DIDTransformerFuncs) didToURL(DID string) (*url.URL, error) {
// urlToDID transforms a valid URL to a DID created following the "did:web" Method Specification. // urlToDID transforms a valid URL to a DID created following the "did:web" Method Specification.
// Documentation can be found here: https://w3c-ccg.github.io/did-method-web/ // Documentation can be found here: https://w3c-ccg.github.io/did-method-web/
func (dt *DIDTransformerFuncs) urlToDID(uri *url.URL) *DID { func (dw *DIDWebFuncs) urlToDID(uri *url.URL) *DID {
p := strings.TrimSuffix(uri.Path, "did.json") p := strings.TrimSuffix(uri.Path, "did.json")
sp := strings.Split(p, urlSeparator) sp := strings.Split(p, urlSeparator)
......
...@@ -53,11 +53,11 @@ func TestToURLFunc(t *testing.T) { ...@@ -53,11 +53,11 @@ func TestToURLFunc(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
DIDTransformerFuncs := regofunc.NewDIDTransformerFuncs() DIDTransformerFuncs := regofunc.NewDIDWebFuncs()
r := rego.New( r := rego.New(
rego.Query(test.regoQuery), rego.Query(test.regoQuery),
rego.Function1(DIDTransformerFuncs.ToURLFunc()), rego.Function1(DIDTransformerFuncs.DIDToURLFunc()),
rego.StrictBuiltinErrors(true), rego.StrictBuiltinErrors(true),
) )
resultSet, err := r.Eval(context.Background()) resultSet, err := r.Eval(context.Background())
...@@ -121,11 +121,11 @@ func TestFromURLFunc(t *testing.T) { ...@@ -121,11 +121,11 @@ func TestFromURLFunc(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
DIDTransformerFuncs := regofunc.NewDIDTransformerFuncs() DIDTransformerFuncs := regofunc.NewDIDWebFuncs()
r := rego.New( r := rego.New(
rego.Query(test.regoQuery), rego.Query(test.regoQuery),
rego.Function1(DIDTransformerFuncs.FromURLFunc()), rego.Function1(DIDTransformerFuncs.URLToDIDFunc()),
rego.StrictBuiltinErrors(true), rego.StrictBuiltinErrors(true),
) )
resultSet, err := r.Eval(context.Background()) resultSet, err := r.Eval(context.Background())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment