happyDomain/model/domain.go

85 lines
2.6 KiB
Go
Raw Permalink Normal View History

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
2020-04-22 08:17:16 +00:00
package happydns
import (
2020-07-28 15:34:55 +00:00
"github.com/miekg/dns"
2020-04-22 08:17:16 +00:00
)
2023-08-05 16:15:52 +00:00
// DomainMinimal is used for swagger documentation as Domain add.
type DomainMinimal struct {
// IsProvider is the identifier of the Provider used to access and edit the
// Domain.
IdProvider Identifier `json:"id_provider" swaggertype:"string"`
// DomainName is the FQDN of the managed Domain.
DomainName string `json:"domain"`
}
2020-07-28 15:34:55 +00:00
// Domain holds information about a domain name own by a User.
2020-04-22 08:17:16 +00:00
type Domain struct {
2020-07-28 15:34:55 +00:00
// Id is the Domain's identifier in the database.
2023-08-05 16:15:52 +00:00
Id Identifier `json:"id" swaggertype:"string"`
2020-07-28 15:34:55 +00:00
// IdUser is the identifier of the Domain's Owner.
2023-08-05 16:15:52 +00:00
IdUser Identifier `json:"id_owner" swaggertype:"string"`
2020-07-28 15:34:55 +00:00
// IsProvider is the identifier of the Provider used to access and edit the
2020-07-28 15:34:55 +00:00
// Domain.
2023-08-05 16:15:52 +00:00
IdProvider Identifier `json:"id_provider" swaggertype:"string"`
2020-07-28 15:34:55 +00:00
// DomainName is the FQDN of the managed Domain.
DomainName string `json:"domain"`
// Group is a hint string aims to group domains.
Group string `json:"group,omitempty"`
2020-07-28 15:34:55 +00:00
// ZoneHistory are the identifiers to the Zone attached to the current
// Domain.
2023-08-05 16:15:52 +00:00
ZoneHistory []Identifier `json:"zone_history" swaggertype:"array,string"`
2020-04-22 08:17:16 +00:00
}
2020-07-28 15:34:55 +00:00
// Domains is an array of Domain.
2020-04-22 08:17:16 +00:00
type Domains []*Domain
2020-07-28 15:34:55 +00:00
// HasZone checks if the given Zone's identifier is part of this Domain
// history.
2022-10-25 16:16:34 +00:00
func (d *Domain) HasZone(zoneId Identifier) (found bool) {
for _, v := range d.ZoneHistory {
2022-10-25 16:16:34 +00:00
if v.Equals(zoneId) {
return true
}
}
return
}
2020-07-28 15:34:55 +00:00
// NewDomain fills a new Domain structure.
func NewDomain(u *User, st *ProviderMeta, dn string) (d *Domain) {
2020-04-22 08:17:16 +00:00
d = &Domain{
2020-04-22 11:12:27 +00:00
IdUser: u.Id,
IdProvider: st.Id,
2020-07-28 15:34:55 +00:00
DomainName: dns.Fqdn(dn),
2020-04-22 08:17:16 +00:00
}
return
}