2023-03-13 21:20:56 +01:00
|
|
|
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-13 21:20:56 +01:00
|
|
|
}
|
|
|
|
|
2023-03-15 21:14:06 +01:00
|
|
|
func (c *cache) addZrokDetail(u *Usage) error {
|
|
|
|
tx, err := c.str.Begin()
|
2023-03-13 21:20:56 +01:00
|
|
|
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)
|
2023-03-13 21:20:56 +01:00
|
|
|
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)
|
2023-03-13 21:20:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
u.EnvironmentId = int64(env.Id)
|
|
|
|
u.AccountId = int64(*env.AccountId)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|