zrok/controller/metrics/cache.go

36 lines
631 B
Go
Raw Normal View History

package metrics
import (
"github.com/openziti/zrok/controller/store"
)
type cache struct {
str *store.Store
}
2023-03-15 21:14:06 +01:00
func newShareCache(str *store.Store) *cache {
return &cache{str}
}
2023-03-15 21:14:06 +01:00
func (c *cache) addZrokDetail(u *Usage) error {
tx, err := c.str.Begin()
if err != nil {
return err
}
defer func() { _ = tx.Rollback() }()
2023-03-15 21:14:06 +01:00
shr, err := c.str.FindShareWithZIdAndDeleted(u.ZitiServiceId, tx)
if err != nil {
return err
}
u.ShareToken = shr.Token
2023-03-15 21:14:06 +01:00
env, err := c.str.GetEnvironment(shr.EnvironmentId, tx)
if err != nil {
return err
}
u.EnvironmentId = int64(env.Id)
u.AccountId = int64(*env.AccountId)
return nil
}