src/server/enterprise/server/api_server.go
func (a *apiServer) Activate(ctx context.Context, req *ec.ActivateRequest) (resp *ec.ActivateResponse, retErr error) {
	a.LogReq(req)
	defer func(start time.Time) { a.pachLogger.Log(req, resp, retErr, time.Since(start)) }(time.Now())

	// Validate the activation code
	expiration, err := validateActivationCode(req.ActivationCode)
	if err != nil {
		return nil, fmt.Errorf("error validating activation code: %s", err.Error())
	}
	// Allow request to override expiration in the activation code, for testing
	if req.Expires != nil {
		customExpiration, err := types.TimestampFromProto(req.Expires)
		if err == nil && expiration.After(customExpiration) {
			expiration = customExpiration
		}
	}
	expirationProto, err := types.TimestampProto(expiration)
	if err != nil {
		return nil, fmt.Errorf("could not convert expiration time \"%s\" to proto: %s", expiration.String(), err.Error())
	}
	if _, err := col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
		e := a.enterpriseToken.ReadWrite(stm)
		// blind write
		return e.Put(enterpriseTokenKey, &ec.EnterpriseRecord{
			ActivationCode: req.ActivationCode,
			Expires:        expirationProto,
		})
	}); err != nil {
		return nil, err
	}

	// Wait until watcher observes the write
	if err := backoff.Retry(func() error {
		if t := a.enterpriseExpiration.Load().(time.Time); t.IsZero() {
			return fmt.Errorf("enterprise not activated")
		}
		return nil
	}, backoff.RetryEvery(time.Second)); err != nil {
		return nil, err
	}
	time.Sleep(time.Second) // give other pachd nodes time to observe the write

	return &ec.ActivateResponse{
		Info: &ec.TokenInfo{
			Expires: expirationProto,
		},
	}, nil
}
func (a *apiServer) Activate(ctx context.Context, req *ec.ActivateRequest) (resp *ec.ActivateResponse, retErr error) {
	a.LogReq(req)
	defer func(start time.Time) { a.pachLogger.Log(req, resp, retErr, time.Since(start)) }(time.Now())

	// Validate the activation code
	expiration, err := validateActivationCode(req.ActivationCode)
	if err != nil {
		return nil, fmt.Errorf("error validating activation code: %s", err.Error())
	}
	// Allow request to override expiration in the activation code, for testing
	if req.Expires != nil {
		customExpiration, err := types.TimestampFromProto(req.Expires)
		if err == nil && expiration.After(customExpiration) {
			expiration = customExpiration
		}
	}
	expirationProto, err := types.TimestampProto(expiration)
	if err != nil {
		return nil, fmt.Errorf("could not convert expiration time \"%s\" to proto: %s", expiration.String(), err.Error())
	}
	if _, err := col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
		e := a.enterpriseToken.ReadWrite(stm)
		// blind write
		return e.Put(enterpriseTokenKey, &ec.EnterpriseRecord{
			ActivationCode: req.ActivationCode,
			Expires:        expirationProto,
		})
	}); err != nil {
		return nil, err
	}

	// Wait until watcher observes the write
	if err := backoff.Retry(func() error {
		if t := a.enterpriseExpiration.Load().(time.Time); t.IsZero() {
			return fmt.Errorf("enterprise not activated")
		}
		return nil
	}, backoff.RetryEvery(time.Second)); err != nil {
		return nil, err
	}
	time.Sleep(time.Second) // give other pachd nodes time to observe the write

	return &ec.ActivateResponse{
		Info: &ec.TokenInfo{
			Expires: expirationProto,
		},
	}, nil
}
func ( a * apiServer ) Activate ( ctx context . Context , req * ec . ActivateRequest ) ( resp * ec . ActivateResponse , retErr error ) { a . LogReq ( req ) defer func ( start time . Time ) { a . pachLogger . Log ( req , resp , retErr , time . Since ( start ) ) } ( time . Now ( ) ) // Validate the activation code expiration , err := validateActivationCode ( req . ActivationCode ) if err != nil { return nil , fmt . Errorf ( " " , err . Error ( ) ) } // Allow request to override expiration in the activation code, for testing if req . Expires != nil { customExpiration , err := types . TimestampFromProto ( req . Expires ) if err == nil && expiration . After ( customExpiration ) { expiration = customExpiration } } expirationProto , err := types . TimestampProto ( expiration ) if err != nil { return nil , fmt . Errorf ( " \" \" " , expiration . String ( ) , err . Error ( ) ) } if _ , err := col . NewSTM ( ctx , a . env . GetEtcdClient ( ) , func ( stm col . STM ) error { e := a . enterpriseToken . ReadWrite ( stm ) // blind write return e . Put ( enterpriseTokenKey , & ec . EnterpriseRecord { ActivationCode : req . ActivationCode , Expires : expirationProto , } ) } ) ; err != nil { return nil , err } // Wait until watcher observes the write if err := backoff . Retry ( func ( ) error { if t := a . enterpriseExpiration . Load ( ) . ( time . Time ) ; t . IsZero ( ) { return fmt . Errorf ( " " ) } return nil } , backoff . RetryEvery ( time . Second ) ) ; err != nil { return nil , err } time . Sleep ( time . Second ) // give other pachd nodes time to observe the write return & ec . ActivateResponse { Info : & ec . TokenInfo { Expires : expirationProto , } , } , nil }
// Activate implements the Activate RPC
Activate implements the Activate RPC