mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-31 23:26:42 +02:00
remove UTC from some not store related operations
This commit is contained in:
parent
489892553a
commit
6aba28ccb7
@ -249,7 +249,7 @@ func mapPeers(peers []*proto.PeerState) peersStateOutput {
|
|||||||
IP: pbPeerState.GetIP(),
|
IP: pbPeerState.GetIP(),
|
||||||
PubKey: pbPeerState.GetPubKey(),
|
PubKey: pbPeerState.GetPubKey(),
|
||||||
Status: pbPeerState.GetConnStatus(),
|
Status: pbPeerState.GetConnStatus(),
|
||||||
LastStatusUpdate: timeLocal.UTC(),
|
LastStatusUpdate: timeLocal,
|
||||||
ConnType: connType,
|
ConnType: connType,
|
||||||
Direct: pbPeerState.GetDirect(),
|
Direct: pbPeerState.GetDirect(),
|
||||||
IceCandidateType: iceCandidateType{
|
IceCandidateType: iceCandidateType{
|
||||||
|
@ -227,7 +227,7 @@ func (s *FileStore) persist(file string) error {
|
|||||||
// AcquireGlobalLock acquires global lock across all the accounts and returns a function that releases the lock
|
// AcquireGlobalLock acquires global lock across all the accounts and returns a function that releases the lock
|
||||||
func (s *FileStore) AcquireGlobalLock() (unlock func()) {
|
func (s *FileStore) AcquireGlobalLock() (unlock func()) {
|
||||||
log.Debugf("acquiring global lock")
|
log.Debugf("acquiring global lock")
|
||||||
start := time.Now().UTC()
|
start := time.Now()
|
||||||
s.globalAccountLock.Lock()
|
s.globalAccountLock.Lock()
|
||||||
|
|
||||||
unlock = func() {
|
unlock = func() {
|
||||||
@ -241,7 +241,7 @@ func (s *FileStore) AcquireGlobalLock() (unlock func()) {
|
|||||||
// AcquireAccountLock acquires account lock and returns a function that releases the lock
|
// AcquireAccountLock acquires account lock and returns a function that releases the lock
|
||||||
func (s *FileStore) AcquireAccountLock(accountID string) (unlock func()) {
|
func (s *FileStore) AcquireAccountLock(accountID string) (unlock func()) {
|
||||||
log.Debugf("acquiring lock for account %s", accountID)
|
log.Debugf("acquiring lock for account %s", accountID)
|
||||||
start := time.Now().UTC()
|
start := time.Now()
|
||||||
value, _ := s.accountLocks.LoadOrStore(accountID, &sync.Mutex{})
|
value, _ := s.accountLocks.LoadOrStore(accountID, &sync.Mutex{})
|
||||||
mtx := value.(*sync.Mutex)
|
mtx := value.(*sync.Mutex)
|
||||||
mtx.Lock()
|
mtx.Lock()
|
||||||
|
@ -98,7 +98,7 @@ func (s *GRPCServer) GetServerKey(ctx context.Context, req *proto.Empty) (*proto
|
|||||||
if s.appMetrics != nil {
|
if s.appMetrics != nil {
|
||||||
s.appMetrics.GRPCMetrics().CountGetKeyRequest()
|
s.appMetrics.GRPCMetrics().CountGetKeyRequest()
|
||||||
}
|
}
|
||||||
now := time.Now().UTC().Add(24 * time.Hour)
|
now := time.Now().Add(24 * time.Hour)
|
||||||
secs := int64(now.Second())
|
secs := int64(now.Second())
|
||||||
nanos := int32(now.Nanosecond())
|
nanos := int32(now.Nanosecond())
|
||||||
expiresAt := ×tamp.Timestamp{Seconds: secs, Nanos: nanos}
|
expiresAt := ×tamp.Timestamp{Seconds: secs, Nanos: nanos}
|
||||||
|
@ -117,7 +117,7 @@ func (m *AuthMiddleware) CheckPATFromRequest(w http.ResponseWriter, r *http.Requ
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid Token: %w", err)
|
return fmt.Errorf("invalid Token: %w", err)
|
||||||
}
|
}
|
||||||
if time.Now().UTC().After(pat.ExpirationDate) {
|
if time.Now().After(pat.ExpirationDate) {
|
||||||
return fmt.Errorf("token expired")
|
return fmt.Errorf("token expired")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ func NewAuth0Manager(config Auth0ClientConfig, appMetrics telemetry.AppMetrics)
|
|||||||
|
|
||||||
// jwtStillValid returns true if the token still valid and have enough time to be used and get a response from Auth0
|
// jwtStillValid returns true if the token still valid and have enough time to be used and get a response from Auth0
|
||||||
func (c *Auth0Credentials) jwtStillValid() bool {
|
func (c *Auth0Credentials) jwtStillValid() bool {
|
||||||
return !c.jwtToken.expiresInTime.IsZero() && time.Now().UTC().Add(5*time.Second).Before(c.jwtToken.expiresInTime)
|
return !c.jwtToken.expiresInTime.IsZero() && time.Now().Add(5*time.Second).Before(c.jwtToken.expiresInTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestJWTToken performs request to get jwt token
|
// requestJWTToken performs request to get jwt token
|
||||||
|
@ -65,7 +65,7 @@ func (mc *mockAuth0Credentials) Authenticate() (JWTToken, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newTestJWT(t *testing.T, expInt int) string {
|
func newTestJWT(t *testing.T, expInt int) string {
|
||||||
now := time.Now().UTC()
|
now := time.Now()
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||||
"iat": now.Unix(),
|
"iat": now.Unix(),
|
||||||
"exp": now.Add(time.Duration(expInt) * time.Second).Unix(),
|
"exp": now.Add(time.Duration(expInt) * time.Second).Unix(),
|
||||||
@ -209,13 +209,13 @@ func TestAuth0_JwtStillValid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
jwtStillValidTestCase1 := jwtStillValidTest{
|
jwtStillValidTestCase1 := jwtStillValidTest{
|
||||||
name: "JWT still valid",
|
name: "JWT still valid",
|
||||||
inputTime: time.Now().UTC().Add(10 * time.Second),
|
inputTime: time.Now().Add(10 * time.Second),
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
message: "should be true",
|
message: "should be true",
|
||||||
}
|
}
|
||||||
jwtStillValidTestCase2 := jwtStillValidTest{
|
jwtStillValidTestCase2 := jwtStillValidTest{
|
||||||
name: "JWT is invalid",
|
name: "JWT is invalid",
|
||||||
inputTime: time.Now().UTC(),
|
inputTime: time.Now(),
|
||||||
expectedResult: false,
|
expectedResult: false,
|
||||||
message: "should be false",
|
message: "should be false",
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ func TestAuth0_Authenticate(t *testing.T) {
|
|||||||
|
|
||||||
authenticateTestCase1 := authenticateTest{
|
authenticateTestCase1 := authenticateTest{
|
||||||
name: "Get Cached token",
|
name: "Get Cached token",
|
||||||
inputExpireToken: time.Now().UTC().Add(30 * time.Second),
|
inputExpireToken: time.Now().Add(30 * time.Second),
|
||||||
helper: JsonParser{},
|
helper: JsonParser{},
|
||||||
// expectedFuncExitErrDiff: fmt.Errorf("unable to get token, statusCode 400"),
|
// expectedFuncExitErrDiff: fmt.Errorf("unable to get token, statusCode 400"),
|
||||||
expectedCode: 200,
|
expectedCode: 200,
|
||||||
|
@ -119,7 +119,7 @@ func NewKeycloakManager(config KeycloakClientConfig, appMetrics telemetry.AppMet
|
|||||||
|
|
||||||
// jwtStillValid returns true if the token still valid and have enough time to be used and get a response from keycloak.
|
// jwtStillValid returns true if the token still valid and have enough time to be used and get a response from keycloak.
|
||||||
func (kc *KeycloakCredentials) jwtStillValid() bool {
|
func (kc *KeycloakCredentials) jwtStillValid() bool {
|
||||||
return !kc.jwtToken.expiresInTime.IsZero() && time.Now().UTC().Add(5*time.Second).Before(kc.jwtToken.expiresInTime)
|
return !kc.jwtToken.expiresInTime.IsZero() && time.Now().Add(5*time.Second).Before(kc.jwtToken.expiresInTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestJWTToken performs request to get jwt token.
|
// requestJWTToken performs request to get jwt token.
|
||||||
|
@ -199,13 +199,13 @@ func TestKeycloakJwtStillValid(t *testing.T) {
|
|||||||
|
|
||||||
jwtStillValidTestCase1 := jwtStillValidTest{
|
jwtStillValidTestCase1 := jwtStillValidTest{
|
||||||
name: "JWT still valid",
|
name: "JWT still valid",
|
||||||
inputTime: time.Now().UTC().Add(10 * time.Second),
|
inputTime: time.Now().Add(10 * time.Second),
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
message: "should be true",
|
message: "should be true",
|
||||||
}
|
}
|
||||||
jwtStillValidTestCase2 := jwtStillValidTest{
|
jwtStillValidTestCase2 := jwtStillValidTest{
|
||||||
name: "JWT is invalid",
|
name: "JWT is invalid",
|
||||||
inputTime: time.Now().UTC(),
|
inputTime: time.Now(),
|
||||||
expectedResult: false,
|
expectedResult: false,
|
||||||
message: "should be false",
|
message: "should be false",
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ func TestKeycloakAuthenticate(t *testing.T) {
|
|||||||
|
|
||||||
authenticateTestCase1 := authenticateTest{
|
authenticateTestCase1 := authenticateTest{
|
||||||
name: "Get Cached token",
|
name: "Get Cached token",
|
||||||
inputExpireToken: time.Now().UTC().Add(30 * time.Second),
|
inputExpireToken: time.Now().Add(30 * time.Second),
|
||||||
helper: JsonParser{},
|
helper: JsonParser{},
|
||||||
expectedFuncExitErrDiff: nil,
|
expectedFuncExitErrDiff: nil,
|
||||||
expectedCode: 200,
|
expectedCode: 200,
|
||||||
|
@ -371,7 +371,7 @@ var _ = Describe("Management service", func() {
|
|||||||
for i := 0; i < additionalPeers; i++ {
|
for i := 0; i < additionalPeers; i++ {
|
||||||
key, _ := wgtypes.GenerateKey()
|
key, _ := wgtypes.GenerateKey()
|
||||||
loginPeerWithValidSetupKey(serverPubKey, key, client)
|
loginPeerWithValidSetupKey(serverPubKey, key, client)
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
n := rand.Intn(200)
|
n := rand.Intn(200)
|
||||||
time.Sleep(time.Duration(n) * time.Millisecond)
|
time.Sleep(time.Duration(n) * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ type Worker struct {
|
|||||||
|
|
||||||
// NewWorker returns a metrics worker
|
// NewWorker returns a metrics worker
|
||||||
func NewWorker(ctx context.Context, id string, dataSource DataSource, connManager ConnManager) *Worker {
|
func NewWorker(ctx context.Context, id string, dataSource DataSource, connManager ConnManager) *Worker {
|
||||||
currentTime := time.Now().UTC()
|
currentTime := time.Now()
|
||||||
return &Worker{
|
return &Worker{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
id: id,
|
id: id,
|
||||||
@ -90,7 +90,7 @@ func (w *Worker) Run() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
w.lastRun = time.Now().UTC()
|
w.lastRun = time.Now()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ func (w *Worker) generatePayload(apiKey string) pushPayload {
|
|||||||
DistinctID: w.id,
|
DistinctID: w.id,
|
||||||
Event: PayloadEvent,
|
Event: PayloadEvent,
|
||||||
Properties: properties,
|
Properties: properties,
|
||||||
Timestamp: time.Now().UTC(),
|
Timestamp: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ func (w *Worker) generateProperties() properties {
|
|||||||
peerActiveVersions []string
|
peerActiveVersions []string
|
||||||
osUIClients map[string]int
|
osUIClients map[string]int
|
||||||
)
|
)
|
||||||
start := time.Now().UTC()
|
start := time.Now()
|
||||||
metricsProperties := make(properties)
|
metricsProperties := make(properties)
|
||||||
osPeers = make(map[string]int)
|
osPeers = make(map[string]int)
|
||||||
osUIClients = make(map[string]int)
|
osUIClients = make(map[string]int)
|
||||||
|
@ -50,7 +50,7 @@ func NewNetwork() *Network {
|
|||||||
n := iplib.NewNet4(net.ParseIP("100.64.0.0"), NetSize)
|
n := iplib.NewNet4(net.ParseIP("100.64.0.0"), NetSize)
|
||||||
sub, _ := n.Subnet(SubnetSize)
|
sub, _ := n.Subnet(SubnetSize)
|
||||||
|
|
||||||
s := rand.NewSource(time.Now().UTC().Unix())
|
s := rand.NewSource(time.Now().Unix())
|
||||||
r := rand.New(s)
|
r := rand.New(s)
|
||||||
intn := r.Intn(len(sub))
|
intn := r.Intn(len(sub))
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ func AllocatePeerIP(ipNet net.IPNet, takenIps []net.IP) (net.IP, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pick a random IP
|
// pick a random IP
|
||||||
s := rand.NewSource(time.Now().UTC().Unix())
|
s := rand.NewSource(time.Now().Unix())
|
||||||
r := rand.New(s)
|
r := rand.New(s)
|
||||||
intn := r.Intn(len(ips))
|
intn := r.Intn(len(ips))
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ func (p *Peer) LoginExpired(expiresIn time.Duration) (bool, time.Duration) {
|
|||||||
return false, 0
|
return false, 0
|
||||||
}
|
}
|
||||||
expiresAt := p.LastLogin.Add(expiresIn)
|
expiresAt := p.LastLogin.Add(expiresIn)
|
||||||
now := time.Now().UTC()
|
now := time.Now()
|
||||||
timeLeft := expiresAt.Sub(now)
|
timeLeft := expiresAt.Sub(now)
|
||||||
return timeLeft <= 0, timeLeft
|
return timeLeft <= 0, timeLeft
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func (key *SetupKey) IsRevoked() bool {
|
|||||||
|
|
||||||
// IsExpired if key was expired
|
// IsExpired if key was expired
|
||||||
func (key *SetupKey) IsExpired() bool {
|
func (key *SetupKey) IsExpired() bool {
|
||||||
return time.Now().UTC().After(key.ExpiresAt)
|
return time.Now().After(key.ExpiresAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsOverUsed if the key was used too many times. SetupKey.UsageLimit == 0 indicates the unlimited usage.
|
// IsOverUsed if the key was used too many times. SetupKey.UsageLimit == 0 indicates the unlimited usage.
|
||||||
|
@ -46,7 +46,7 @@ func NewTimeBasedAuthSecretsManager(updateManager *PeersUpdateManager, config *T
|
|||||||
func (m *TimeBasedAuthSecretsManager) GenerateCredentials() TURNCredentials {
|
func (m *TimeBasedAuthSecretsManager) GenerateCredentials() TURNCredentials {
|
||||||
mac := hmac.New(sha1.New, []byte(m.config.Secret))
|
mac := hmac.New(sha1.New, []byte(m.config.Secret))
|
||||||
|
|
||||||
timeAuth := time.Now().UTC().Add(m.config.CredentialsTTL.Duration).Unix()
|
timeAuth := time.Now().Add(m.config.CredentialsTTL.Duration).Unix()
|
||||||
|
|
||||||
username := fmt.Sprint(timeAuth)
|
username := fmt.Sprint(timeAuth)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user