fix: Add service to database when registering

This commit is contained in:
Prad Nukala
2024-08-21 14:53:03 -04:00
committed by Prad Nukala (aider)
parent 1810ee1c7f
commit 861fbf501d
8 changed files with 33 additions and 132 deletions
+10 -7
View File
@@ -45,20 +45,23 @@ func (ms msgServer) RegisterController(goCtx context.Context, msg *types.MsgRegi
if ms.k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
svc := didv1.Service{
ControllerDid: msg.Authority,
}
ms.k.OrmDB.ServiceTable().Insert(ctx, &svc)
return &types.MsgRegisterControllerResponse{}, nil
}
// RegisterService implements types.MsgServer.
func (ms msgServer) RegisterService(ctx context.Context, msg *types.MsgRegisterService) (*types.MsgRegisterServiceResponse, error) {
func (ms msgServer) RegisterService(goCtx context.Context, msg *types.MsgRegisterService) (*types.MsgRegisterServiceResponse, error) {
if ms.k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
}
// ctx := sdk.UnwrapSDKContext(goCtx)
ctx := sdk.UnwrapSDKContext(goCtx)
svc := didv1.Service{
ControllerDid: msg.Authority,
}
err := ms.k.OrmDB.ServiceTable().Insert(ctx, &svc)
if err != nil {
return nil, err
}
return &types.MsgRegisterServiceResponse{}, nil
}
-17
View File
@@ -1,7 +1,5 @@
package types
import "gopkg.in/macaroon-bakery.v2/bakery/checkers"
var (
PermissionScopeStrings = [...]string{
"profile.name",
@@ -36,18 +34,3 @@ var (
"PERMISSION_SCOPE_ADMIN_VALIDATOR": PermissionScope_PERMISSION_SCOPE_ADMIN_VALIDATOR,
}
)
func ResolvePermissionScope(scope string) (PermissionScope, bool) {
uriToPrefix := make(map[string]string)
for _, scope := range PermissionScopeStrings {
uriToPrefix["https://example.com/auth/"+scope] = scope
}
PermissionNamespace := checkers.NewNamespace(uriToPrefix)
prefix, ok := PermissionNamespace.Resolve("https://example.com/auth/" + scope)
if !ok {
return 0, false
}
permScope, ok := StringToPermissionScope[prefix]
return permScope, ok
}