frostfs-node/cmd/frostfs-node/session.go
Alex Vanin 20de74a505 Rename package name
Due to source code relocation from GitHub.

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2023-03-07 16:38:26 +03:00

66 lines
2.1 KiB
Go

package main
import (
"context"
"fmt"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
sessionGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
nodeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/node"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
sessionTransportGRPC "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network/transport/session/grpc"
sessionSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session/storage"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session/storage/persistent"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session/storage/temporary"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
)
type sessionStorage interface {
Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error)
Get(ownerID user.ID, tokenID []byte) *storage.PrivateToken
RemoveOld(epoch uint64)
Close() error
}
func initSessionService(c *cfg) {
if persistentSessionPath := nodeconfig.PersistentSessions(c.appCfg).Path(); persistentSessionPath != "" {
persisessions, err := persistent.NewTokenStore(persistentSessionPath,
persistent.WithLogger(c.log),
persistent.WithTimeout(100*time.Millisecond),
persistent.WithEncryptionKey(&c.key.PrivateKey),
)
if err != nil {
panic(fmt.Errorf("could not create persistent session token storage: %w", err))
}
c.privateTokenStore = persisessions
} else {
c.privateTokenStore = temporary.NewTokenStore()
}
c.onShutdown(func() {
_ = c.privateTokenStore.Close()
})
addNewEpochNotificationHandler(c, func(ev event.Event) {
c.privateTokenStore.RemoveOld(ev.(netmap.NewEpoch).EpochNumber())
})
server := sessionTransportGRPC.New(
sessionSvc.NewSignService(
&c.key.PrivateKey,
sessionSvc.NewResponseService(
sessionSvc.NewExecutionService(c.privateTokenStore, c.log),
c.respSvc,
),
),
)
for _, srv := range c.cfgGRPC.servers {
sessionGRPC.RegisterSessionServiceServer(srv, server)
}
}