func SetAccessToken() error {
	if GetApigeeToken() == "" && GetServiceAccount() == "" {
		SetApigeeToken(GetToken()) //read from configuration
		if GetApigeeToken() == "" {
			return fmt.Errorf("either token or service account must be provided")
		}
		if checkAccessToken() { //check if the token is still valid
			return nil
		}
		return fmt.Errorf("token expired: request a new access token or pass the service account")
	}
	if GetApigeeToken() != "" {
		//a token was passed, cache it
		if checkAccessToken() {
			_ = WriteToken(GetApigeeToken())
			return nil
		}
	} else {
		err := readServiceAccount(GetServiceAccount())
		if err != nil { // Handle errors reading the config file
			return fmt.Errorf("error reading config file: %s", err)
		}
		privateKey := getServiceAccountProperty("PrivateKey")
		if privateKey == "" {
			return fmt.Errorf("private key missing in the service account")
		}
		if getServiceAccountProperty("ClientEmail") == "" {
			return fmt.Errorf("client email missing in the service account")
		}
		_, err = generateAccessToken(privateKey)
		if err != nil {
			return fmt.Errorf("fatal error generating access token: %s", err)
		}
		return nil
	}
	return fmt.Errorf("token expired: request a new access token or pass the service account")
}
//SetAccessToken read from cache or if not found or expired will generate a new one
SetAccessToken read from cache or if not found or expired will generate a new one
// SetAccessToken read from cache or if not found or expired will generate a new one
func SetAccessToken() error {
	if GetApigeeToken() == "" && GetServiceAccount() == "" {
		SetApigeeToken(GetToken()) 
		if GetApigeeToken() == "" {
			return fmt.Errorf("either token or service account must be provided")
		}
		if checkAccessToken() { 
			return nil
		}
		return fmt.Errorf("token expired: request a new access token or pass the service account")
	}
	if GetApigeeToken() != "" {
		if checkAccessToken() {
			_ = WriteToken(GetApigeeToken())
			return nil
		}
	} else {
		err := readServiceAccount(GetServiceAccount())
		if err != nil { 
			return fmt.Errorf("error reading config file: %s", err)
		}
		privateKey := getServiceAccountProperty("PrivateKey")
		if privateKey == "" {
			return fmt.Errorf("private key missing in the service account")
		}
		if getServiceAccountProperty("ClientEmail") == "" {
			return fmt.Errorf("client email missing in the service account")
		}
		_, err = generateAccessToken(privateKey)
		if err != nil {
			return fmt.Errorf("fatal error generating access token: %s", err)
		}
		return nil
	}
	return fmt.Errorf("token expired: request a new access token or pass the service account")
}
func SetAccessToken ( ) error { if GetApigeeToken ( ) == " " && GetServiceAccount ( ) == " " { SetApigeeToken ( GetToken ( ) ) if GetApigeeToken ( ) == " " { return fmt . Errorf ( " " ) } if checkAccessToken ( ) { return nil } return fmt . Errorf ( " " ) } if GetApigeeToken ( ) != " " { if checkAccessToken ( ) { _ = WriteToken ( GetApigeeToken ( ) ) return nil } } else { err := readServiceAccount ( GetServiceAccount ( ) ) if err != nil { return fmt . Errorf ( " " , err ) } privateKey := getServiceAccountProperty ( " " ) if privateKey == " " { return fmt . Errorf ( " " ) } if getServiceAccountProperty ( " " ) == " " { return fmt . Errorf ( " " ) } _ , err = generateAccessToken ( privateKey ) if err != nil { return fmt . Errorf ( " " , err ) } return nil } return fmt . Errorf ( " " ) }
SetAccessToken read from cache or if not found or expired will generate a new one
SetAccessToken read from cache or if not found or expired will generate a new one
//read from configuration //check if the token is still valid //a token was passed, cache it // Handle errors reading the config file