Skip to content

Commit

Permalink
Implement LoginSession.userSession()
Browse files Browse the repository at this point in the history
  • Loading branch information
zenhack committed Apr 6, 2023
1 parent 5657156 commit f7f9650
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/server/main/external-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,24 @@ func (loginSessionImpl) UserInfo(context.Context, external.LoginSession_userInfo
}

func (s loginSessionImpl) UserSession(ctx context.Context, p external.LoginSession_userSession) error {
return capnp.Unimplemented("userSession() not implemented")
p.Go()
return exn.Try0(func(throw exn.Thrower) {
tx, err := s.server.db.Begin()
throw(err)
defer tx.Rollback()
ok, err := tx.CredentialHasRole(s.userSession.Credential, database.RoleUser)
throw(err)
if !ok {
throw(errors.New("Permission denied; caller does not have the 'user' role."))
}
throw(tx.Commit())

results, err := p.AllocResults()
throw(err)
results.SetSession(external.UserSession_ServerToClient(userSessionImpl{
api: s.externalApiImpl,
}))
})
}

func (s loginSessionImpl) ListGrains(ctx context.Context, p external.LoginSession_listGrains) error {
Expand Down Expand Up @@ -298,3 +315,11 @@ func (pc pkgController) Create(ctx context.Context, p external.Package_Controlle
})

}

type userSessionImpl struct {
api externalApiImpl
}

func (s userSessionImpl) InstallPackage(ctx context.Context, p external.UserSession_installPackage) error {
return capnp.Unimplemented("TODO: implement InstallPackage()")
}

0 comments on commit f7f9650

Please sign in to comment.