Files
ocis/ocis-pkg/shared/errors.go
T
Roman PerekhodandClaude Opus 5.5 3c56d2cffc fix: [OCSRE-1629] apply the scope rules to the NATS username and fix the NATS checks
- A service-specific username or password now takes precedence over the
  global NATS JWT credentials. Before, OCIS_NATS_CREDS_FILE always
  replaced a value like GRAPH_CACHE_AUTH_USERNAME. The service registry
  uses the same rule for MICRO_REGISTRY_AUTH_USERNAME and
  MICRO_REGISTRY_AUTH_PASSWORD.
- The NATS health check keeps one connection and uses it again for each
  probe. Before, each probe read the .creds file and opened a new
  connection. A probe could read a rotated file before the write was
  complete. The proxy, ocs and gateway services now build the check once.
- The startup check of the store credentials runs only for the nats-js
  and nats-js-kv store types. Other store types do not use the
  credentials.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 19:25:09 +01:00

113 lines
5.0 KiB
Go

package shared
import (
"fmt"
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
"github.com/owncloud/reva/v2/pkg/natsauth"
revastore "github.com/owncloud/reva/v2/pkg/store"
)
func MissingMachineAuthApiKeyError(service string) error {
return fmt.Errorf("The Machineauth API key has not been configured for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingSystemUserApiKeyError(service string) error {
return fmt.Errorf("The SystemUser API key has not been configured for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingJWTTokenError(service string) error {
return fmt.Errorf("The jwt_secret has not been set properly in your config for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingRevaTransferSecretError(service string) error {
return fmt.Errorf("The transfer_secret has not been set properly in your config for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingLDAPBindPassword(service string) error {
return fmt.Errorf("The ldap bind_password has not been set properly in your config for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingServiceUserPassword(service, serviceUser string) error {
return fmt.Errorf("The password of service user %s has not been set properly in your config for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
serviceUser, service, defaults.BaseConfigPath())
}
func MissingSystemUserID(service string) error {
return fmt.Errorf("The system user ID has not been configured for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingAdminUserID(service string) error {
return fmt.Errorf("The admin user ID has not been configured for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingServiceAccountID(service string) error {
return fmt.Errorf("The service account id has not been configured for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingServiceAccountSecret(service string) error {
return fmt.Errorf("The service account secret has not been configured for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
func MissingWOPISecretError(service string) error {
return fmt.Errorf("The WOPI secret has not been set properly in your config for %s. "+
"Make sure your %s config contains the proper values "+
"(e.g. by using 'ocis init --diff' and applying the patch or setting a value manually in "+
"the config/corresponding environment variable).",
service, defaults.BaseConfigPath())
}
// CheckNatsCredentials checks the NATS JWT credentials of a store at startup. The reva
// store cannot return an error for invalid credentials. It only logs the error, and each
// store operation fails later. It returns no error when both values are empty.
// Only the nats-js and nats-js-kv stores use the credentials. For other store types,
// it does not check the credentials.
func CheckNatsCredentials(service, store, credsFile, creds string) error {
if store != revastore.TypeNatsJS && store != revastore.TypeNatsJSKV {
return nil
}
if err := natsauth.Check(credsFile, creds); err != nil {
return fmt.Errorf("The NATS credentials for %s are not valid: %w", service, err)
}
return nil
}