remove UTC from some not store related operations

This commit is contained in:
Pascal Fischer 2023-04-10 10:54:23 +02:00
parent 489892553a
commit 6aba28ccb7
14 changed files with 24 additions and 24 deletions

View File

@ -249,7 +249,7 @@ func mapPeers(peers []*proto.PeerState) peersStateOutput {
IP: pbPeerState.GetIP(),
PubKey: pbPeerState.GetPubKey(),
Status: pbPeerState.GetConnStatus(),
LastStatusUpdate: timeLocal.UTC(),
LastStatusUpdate: timeLocal,
ConnType: connType,
Direct: pbPeerState.GetDirect(),
IceCandidateType: iceCandidateType{

View File

@ -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
func (s *FileStore) AcquireGlobalLock() (unlock func()) {
log.Debugf("acquiring global lock")
start := time.Now().UTC()
start := time.Now()
s.globalAccountLock.Lock()
unlock = func() {
@ -241,7 +241,7 @@ func (s *FileStore) AcquireGlobalLock() (unlock func()) {
// AcquireAccountLock acquires account lock and returns a function that releases the lock
func (s *FileStore) AcquireAccountLock(accountID string) (unlock func()) {
log.Debugf("acquiring lock for account %s", accountID)
start := time.Now().UTC()
start := time.Now()
value, _ := s.accountLocks.LoadOrStore(accountID, &sync.Mutex{})
mtx := value.(*sync.Mutex)
mtx.Lock()

View File

@ -98,7 +98,7 @@ func (s *GRPCServer) GetServerKey(ctx context.Context, req *proto.Empty) (*proto
if s.appMetrics != nil {
s.appMetrics.GRPCMetrics().CountGetKeyRequest()
}
now := time.Now().UTC().Add(24 * time.Hour)
now := time.Now().Add(24 * time.Hour)
secs := int64(now.Second())
nanos := int32(now.Nanosecond())
expiresAt := &timestamp.Timestamp{Seconds: secs, Nanos: nanos}

View File

@ -117,7 +117,7 @@ func (m *AuthMiddleware) CheckPATFromRequest(w http.ResponseWriter, r *http.Requ
if err != nil {
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")
}

View File

@ -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
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

View File

@ -65,7 +65,7 @@ func (mc *mockAuth0Credentials) Authenticate() (JWTToken, error) {
}
func newTestJWT(t *testing.T, expInt int) string {
now := time.Now().UTC()
now := time.Now()
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"iat": now.Unix(),
"exp": now.Add(time.Duration(expInt) * time.Second).Unix(),
@ -209,13 +209,13 @@ func TestAuth0_JwtStillValid(t *testing.T) {
}
jwtStillValidTestCase1 := jwtStillValidTest{
name: "JWT still valid",
inputTime: time.Now().UTC().Add(10 * time.Second),
inputTime: time.Now().Add(10 * time.Second),
expectedResult: true,
message: "should be true",
}
jwtStillValidTestCase2 := jwtStillValidTest{
name: "JWT is invalid",
inputTime: time.Now().UTC(),
inputTime: time.Now(),
expectedResult: false,
message: "should be false",
}
@ -251,7 +251,7 @@ func TestAuth0_Authenticate(t *testing.T) {
authenticateTestCase1 := authenticateTest{
name: "Get Cached token",
inputExpireToken: time.Now().UTC().Add(30 * time.Second),
inputExpireToken: time.Now().Add(30 * time.Second),
helper: JsonParser{},
// expectedFuncExitErrDiff: fmt.Errorf("unable to get token, statusCode 400"),
expectedCode: 200,

View File

@ -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.
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.

View File

@ -199,13 +199,13 @@ func TestKeycloakJwtStillValid(t *testing.T) {
jwtStillValidTestCase1 := jwtStillValidTest{
name: "JWT still valid",
inputTime: time.Now().UTC().Add(10 * time.Second),
inputTime: time.Now().Add(10 * time.Second),
expectedResult: true,
message: "should be true",
}
jwtStillValidTestCase2 := jwtStillValidTest{
name: "JWT is invalid",
inputTime: time.Now().UTC(),
inputTime: time.Now(),
expectedResult: false,
message: "should be false",
}
@ -240,7 +240,7 @@ func TestKeycloakAuthenticate(t *testing.T) {
authenticateTestCase1 := authenticateTest{
name: "Get Cached token",
inputExpireToken: time.Now().UTC().Add(30 * time.Second),
inputExpireToken: time.Now().Add(30 * time.Second),
helper: JsonParser{},
expectedFuncExitErrDiff: nil,
expectedCode: 200,

View File

@ -371,7 +371,7 @@ var _ = Describe("Management service", func() {
for i := 0; i < additionalPeers; i++ {
key, _ := wgtypes.GenerateKey()
loginPeerWithValidSetupKey(serverPubKey, key, client)
rand.Seed(time.Now().UTC().UnixNano())
rand.Seed(time.Now().UnixNano())
n := rand.Intn(200)
time.Sleep(time.Duration(n) * time.Millisecond)
}

View File

@ -67,7 +67,7 @@ type Worker struct {
// NewWorker returns a metrics worker
func NewWorker(ctx context.Context, id string, dataSource DataSource, connManager ConnManager) *Worker {
currentTime := time.Now().UTC()
currentTime := time.Now()
return &Worker{
ctx: ctx,
id: id,
@ -90,7 +90,7 @@ func (w *Worker) Run() {
if err != nil {
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,
Event: PayloadEvent,
Properties: properties,
Timestamp: time.Now().UTC(),
Timestamp: time.Now(),
}
}
@ -172,7 +172,7 @@ func (w *Worker) generateProperties() properties {
peerActiveVersions []string
osUIClients map[string]int
)
start := time.Now().UTC()
start := time.Now()
metricsProperties := make(properties)
osPeers = make(map[string]int)
osUIClients = make(map[string]int)

View File

@ -50,7 +50,7 @@ func NewNetwork() *Network {
n := iplib.NewNet4(net.ParseIP("100.64.0.0"), NetSize)
sub, _ := n.Subnet(SubnetSize)
s := rand.NewSource(time.Now().UTC().Unix())
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
intn := r.Intn(len(sub))
@ -101,7 +101,7 @@ func AllocatePeerIP(ipNet net.IPNet, takenIps []net.IP) (net.IP, error) {
}
// pick a random IP
s := rand.NewSource(time.Now().UTC().Unix())
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
intn := r.Intn(len(ips))

View File

@ -144,7 +144,7 @@ func (p *Peer) LoginExpired(expiresIn time.Duration) (bool, time.Duration) {
return false, 0
}
expiresAt := p.LastLogin.Add(expiresIn)
now := time.Now().UTC()
now := time.Now()
timeLeft := expiresAt.Sub(now)
return timeLeft <= 0, timeLeft
}

View File

@ -148,7 +148,7 @@ func (key *SetupKey) IsRevoked() bool {
// IsExpired if key was expired
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.

View File

@ -46,7 +46,7 @@ func NewTimeBasedAuthSecretsManager(updateManager *PeersUpdateManager, config *T
func (m *TimeBasedAuthSecretsManager) GenerateCredentials() TURNCredentials {
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)