2023-12-24 10:18:08 +00:00
|
|
|
// This file is part of the happyDomain (R) project.
|
|
|
|
// Copyright (c) 2020-2024 happyDomain
|
|
|
|
// Authors: Pierre-Olivier Mercier, et al.
|
2020-05-04 14:58:02 +00:00
|
|
|
//
|
2023-12-24 10:18:08 +00:00
|
|
|
// This program is offered under a commercial and under the AGPL license.
|
|
|
|
// For commercial licensing, contact us at <contact@happydomain.org>.
|
2020-05-04 14:58:02 +00:00
|
|
|
//
|
2023-12-24 10:18:08 +00:00
|
|
|
// For AGPL licensing:
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2020-05-04 14:58:02 +00:00
|
|
|
//
|
2023-12-24 10:18:08 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
2020-05-04 14:58:02 +00:00
|
|
|
//
|
2023-12-24 10:18:08 +00:00
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-05-04 14:58:02 +00:00
|
|
|
|
2023-09-07 10:04:55 +00:00
|
|
|
package storage // import "git.happydns.org/happyDomain/storage"
|
2020-04-05 11:07:42 +00:00
|
|
|
|
|
|
|
import (
|
2023-09-07 09:37:18 +00:00
|
|
|
"git.happydns.org/happyDomain/model"
|
2020-04-05 11:07:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Storage interface {
|
2020-07-28 15:34:55 +00:00
|
|
|
// DoMigration is the first function called.
|
2020-04-05 11:07:42 +00:00
|
|
|
DoMigration() error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// Tidy should optimize the database, looking for orphan records, ...
|
2020-06-24 15:20:01 +00:00
|
|
|
Tidy() error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// Close shutdown the connection with the database and releases all structure.
|
2020-04-05 11:07:42 +00:00
|
|
|
Close() error
|
|
|
|
|
2021-12-16 14:53:58 +00:00
|
|
|
// AUTH -------------------------------------------------------
|
|
|
|
|
|
|
|
// GetAuthUsers retrieves the list of known Users.
|
|
|
|
GetAuthUsers() (happydns.UserAuths, error)
|
|
|
|
|
|
|
|
// GetAuthUser retrieves the User with the given identifier.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetAuthUser(id happydns.Identifier) (*happydns.UserAuth, error)
|
2021-12-16 14:53:58 +00:00
|
|
|
|
|
|
|
// GetAuthUserByEmail retrives the User with the given email address.
|
|
|
|
GetAuthUserByEmail(email string) (*happydns.UserAuth, error)
|
|
|
|
|
|
|
|
// AuthUserExists checks if the given email address is already associated to an User.
|
|
|
|
AuthUserExists(email string) bool
|
|
|
|
|
|
|
|
// CreateAuthUser creates a record in the database for the given User.
|
|
|
|
CreateAuthUser(user *happydns.UserAuth) error
|
|
|
|
|
|
|
|
// UpdateAuthUser updates the fields of the given User.
|
|
|
|
UpdateAuthUser(user *happydns.UserAuth) error
|
|
|
|
|
|
|
|
// DeleteAuthUser removes the given User from the database.
|
|
|
|
DeleteAuthUser(user *happydns.UserAuth) error
|
|
|
|
|
|
|
|
// ClearAuthUsers deletes all AuthUsers present in the database.
|
|
|
|
ClearAuthUsers() error
|
|
|
|
|
2020-07-28 15:34:55 +00:00
|
|
|
// DOMAINS ----------------------------------------------------
|
|
|
|
|
|
|
|
// GetDomains retrieves all Domains associated to the given User.
|
2020-04-22 08:17:16 +00:00
|
|
|
GetDomains(u *happydns.User) (happydns.Domains, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// GetDomain retrieves the Domain with the given id and owned by the given User.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetDomain(u *happydns.User, id happydns.Identifier) (*happydns.Domain, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// GetDomainByDN is like GetDomain but look for the domain name instead of identifier.
|
2020-04-22 08:17:16 +00:00
|
|
|
GetDomainByDN(u *happydns.User, dn string) (*happydns.Domain, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// DomainExists looks if the given domain name alread exists in the database.
|
2020-04-22 08:17:16 +00:00
|
|
|
DomainExists(dn string) bool
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// CreateDomain creates a record in the database for the given Domain.
|
2020-04-22 08:17:16 +00:00
|
|
|
CreateDomain(u *happydns.User, z *happydns.Domain) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// UpdateDomain updates the fields of the given Domain.
|
2020-04-22 08:17:16 +00:00
|
|
|
UpdateDomain(z *happydns.Domain) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// UpdateDomainOwner updates the owner of the given Domain.
|
2020-04-22 08:17:16 +00:00
|
|
|
UpdateDomainOwner(z *happydns.Domain, newOwner *happydns.User) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// DeleteDomain removes the given Domain from the database.
|
2020-04-22 08:17:16 +00:00
|
|
|
DeleteDomain(z *happydns.Domain) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// ClearDomains deletes all Domains present in the database.
|
2020-04-22 08:17:16 +00:00
|
|
|
ClearDomains() error
|
|
|
|
|
2023-11-24 03:18:36 +00:00
|
|
|
// DOMAIN LOGS --------------------------------------------------
|
|
|
|
|
|
|
|
GetDomainLogs(*happydns.Domain) ([]*happydns.DomainLog, error)
|
|
|
|
|
|
|
|
CreateDomainLog(*happydns.Domain, *happydns.DomainLog) error
|
|
|
|
|
|
|
|
UpdateDomainLog(*happydns.Domain, *happydns.DomainLog) error
|
|
|
|
|
|
|
|
DeleteDomainLog(*happydns.Domain, *happydns.DomainLog) error
|
|
|
|
|
2021-07-05 15:11:17 +00:00
|
|
|
// PROVIDERS ----------------------------------------------------
|
|
|
|
|
|
|
|
// GetProviderMetas retrieves provider's metadatas of all providers own by the given User.
|
|
|
|
GetProviderMetas(u *happydns.User) ([]happydns.ProviderMeta, error)
|
|
|
|
|
|
|
|
// GetProviderMeta retrieves the metadatas for the Provider with the given identifier and owner.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetProviderMeta(u *happydns.User, id happydns.Identifier) (*happydns.ProviderMeta, error)
|
2021-07-05 15:11:17 +00:00
|
|
|
|
|
|
|
// GetProvider retrieves the full Provider with the given identifier and owner.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetProvider(u *happydns.User, id happydns.Identifier) (*happydns.ProviderCombined, error)
|
2021-07-05 15:11:17 +00:00
|
|
|
|
|
|
|
// CreateProvider creates a record in the database for the given Provider.
|
|
|
|
CreateProvider(u *happydns.User, s happydns.Provider, comment string) (*happydns.ProviderCombined, error)
|
|
|
|
|
|
|
|
// UpdateProvider updates the fields of the given Provider.
|
|
|
|
UpdateProvider(s *happydns.ProviderCombined) error
|
|
|
|
|
|
|
|
// UpdateProviderOwner updates the owner of the given Provider.
|
|
|
|
UpdateProviderOwner(s *happydns.ProviderCombined, newOwner *happydns.User) error
|
|
|
|
|
|
|
|
// DeleteProvider removes the given Provider from the database.
|
|
|
|
DeleteProvider(s *happydns.ProviderMeta) error
|
|
|
|
|
|
|
|
// ClearProviders deletes all Providers present in the database.
|
|
|
|
ClearProviders() error
|
|
|
|
|
2020-07-28 15:34:55 +00:00
|
|
|
// SESSIONS ---------------------------------------------------
|
|
|
|
|
|
|
|
// GetSession retrieves the Session with the given identifier.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetSession(id happydns.Identifier) (*happydns.Session, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
2021-12-16 14:53:58 +00:00
|
|
|
// GetAuthUserSessions retrieves all Session for the given AuthUser.
|
|
|
|
GetAuthUserSessions(user *happydns.UserAuth) ([]*happydns.Session, error)
|
|
|
|
|
2020-12-10 15:43:37 +00:00
|
|
|
// GetUserSessions retrieves all Session for the given User.
|
|
|
|
GetUserSessions(user *happydns.User) ([]*happydns.Session, error)
|
|
|
|
|
2020-07-28 15:34:55 +00:00
|
|
|
// CreateSession creates a record in the database for the given Session.
|
2020-04-05 11:07:42 +00:00
|
|
|
CreateSession(session *happydns.Session) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// UpdateSession updates the fields of the given Session.
|
2020-04-05 11:07:42 +00:00
|
|
|
UpdateSession(session *happydns.Session) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// DeleteSession removes the given Session from the database.
|
2020-04-05 11:07:42 +00:00
|
|
|
DeleteSession(session *happydns.Session) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// ClearSessions deletes all Sessions present in the database.
|
2020-04-20 10:47:41 +00:00
|
|
|
ClearSessions() error
|
2020-04-05 11:07:42 +00:00
|
|
|
|
2020-07-28 15:34:55 +00:00
|
|
|
// USERS ------------------------------------------------------
|
|
|
|
|
|
|
|
// GetUsers retrieves the list of known Users.
|
2020-04-05 11:07:42 +00:00
|
|
|
GetUsers() (happydns.Users, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// GetUser retrieves the User with the given identifier.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetUser(id happydns.Identifier) (*happydns.User, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// GetUserByEmail retrives the User with the given email address.
|
2020-04-05 11:07:42 +00:00
|
|
|
GetUserByEmail(email string) (*happydns.User, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// CreateUser creates a record in the database for the given User.
|
2020-04-05 11:07:42 +00:00
|
|
|
CreateUser(user *happydns.User) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// UpdateUser updates the fields of the given User.
|
2020-04-05 11:07:42 +00:00
|
|
|
UpdateUser(user *happydns.User) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// DeleteUser removes the given User from the database.
|
2020-04-05 11:07:42 +00:00
|
|
|
DeleteUser(user *happydns.User) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// ClearUsers deletes all Users present in the database.
|
2020-04-05 11:07:42 +00:00
|
|
|
ClearUsers() error
|
2020-06-08 23:25:15 +00:00
|
|
|
|
2020-07-28 15:34:55 +00:00
|
|
|
// ZONES ------------------------------------------------------
|
|
|
|
|
|
|
|
// GetZoneMeta retrives metadatas of the Zone with the given identifier.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetZoneMeta(id happydns.Identifier) (*happydns.ZoneMeta, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// GetZone retrieves the full Zone (including Services and metadatas) which have the given identifier.
|
2022-10-25 16:16:34 +00:00
|
|
|
GetZone(id happydns.Identifier) (*happydns.Zone, error)
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// CreateZone creates a record in the database for the given Zone.
|
2020-06-08 23:25:15 +00:00
|
|
|
CreateZone(zone *happydns.Zone) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// UpdateZone updates the fields of the given Zone.
|
2020-06-08 23:25:15 +00:00
|
|
|
UpdateZone(zone *happydns.Zone) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// DeleteZone removes the given Zone from the database.
|
2020-06-08 23:25:15 +00:00
|
|
|
DeleteZone(zone *happydns.Zone) error
|
2020-07-28 15:34:55 +00:00
|
|
|
|
|
|
|
// ClearZones deletes all Zones present in the database.
|
2020-06-08 23:25:15 +00:00
|
|
|
ClearZones() error
|
2020-04-05 11:07:42 +00:00
|
|
|
}
|