// Run runs the certificate manager, this should most likely be executed as a go-routine
Run runs the certificate manager, this should most likely be executed as a go-routine
// Run runs the certificate manager this should most likely be executed as a go - routine
func (cM *CertificateManager) Run(wg *sync.WaitGroup) {
	logger.Info("running certificate manager")
	defer logger.Info("stopped certificate manager")
	defer wg.Done()
	for {
		cM.certificatesMutex.Lock()
		req, err := http.NewRequestWithContext(
			context.Background(),
			"GET",
			GoogleOAuth2CertsURL,
			nil,
		)
		if err != nil {
			logger.Error("could not make Google OAuth2 certs request", zap.Error(err))
		}
		resp, err := cM.client.Do(req)
		if err != nil {
			logger.Error("could not retrieve Google OAuth2 certs", zap.Error(err))
		}
		defer resp.Body.Close()
		var resCerts RespCertificates
		err = json.NewDecoder(resp.Body).Decode(&resCerts)
		if err != nil {
			logger.Error("could not decode Google OAuth2 certs", zap.Error(err))
		}
		for kid, encodedCert := range resCerts {
			block, _ := pem.Decode([]byte(encodedCert))
			cert, err := x509.ParseCertificate(block.Bytes)
			if err != nil {
				logger.Error("could not parse Google OAuth2 certs", zap.Error(err))
			} else {
				cM.Certificates[kid] = cert.PublicKey.(*rsa.PublicKey)
				logger.Info("stored certificate", zap.String("kid", kid))
			}
		}
		cM.certificatesMutex.Unlock()
		expiry := GetMaxAgeFromHeader(resp.Header)
		logger.Info("waiting to refresh certificates", zap.Duration("seconds", expiry))
		select {
		case <-cM.closeCh:
			return
		case <-time.After(expiry):
		}
	}
}
func ( cM * CertificateManager ) Run ( wg * sync . WaitGroup ) { logger . Info ( " " ) defer logger . Info ( " " ) defer wg . Done ( ) for { cM . certificatesMutex . Lock ( ) req , err := http . NewRequestWithContext ( context . Background ( ) , " " , GoogleOAuth2CertsURL , nil , ) if err != nil { logger . Error ( " " , zap . Error ( err ) ) } resp , err := cM . client . Do ( req ) if err != nil { logger . Error ( " " , zap . Error ( err ) ) } defer resp . Body . Close ( ) var resCerts RespCertificates err = json . NewDecoder ( resp . Body ) . Decode ( & resCerts ) if err != nil { logger . Error ( " " , zap . Error ( err ) ) } for kid , encodedCert := range resCerts { block , _ := pem . Decode ( [ ] byte ( encodedCert ) ) cert , err := x509 . ParseCertificate ( block . Bytes ) if err != nil { logger . Error ( " " , zap . Error ( err ) ) } else { cM . Certificates [ kid ] = cert . PublicKey . ( * rsa . PublicKey ) logger . Info ( " " , zap . String ( " " , kid ) ) } } cM . certificatesMutex . Unlock ( ) expiry := GetMaxAgeFromHeader ( resp . Header ) logger . Info ( " " , zap . Duration ( " " , expiry ) ) select { case <- cM . closeCh : return case <- time . After ( expiry ) : } } }
Run runs the certificate manager, this should most likely be executed as a go-routine
Run runs the certificate manager this should most likely be executed as a go - routine
// #nosec G107