2020-05-09 11:14:29 +00:00
// Copyright or © or Copr. happyDNS (2020)
//
// contact@happydns.org
//
// This software is a computer program whose purpose is to provide a modern
// interface to interact with DNS systems.
//
// This software is governed by the CeCILL license under French law and abiding
// by the rules of distribution of free software. You can use, modify and/or
// redistribute the software under the terms of the CeCILL license as
// circulated by CEA, CNRS and INRIA at the following URL
// "http://www.cecill.info".
//
// As a counterpart to the access to the source code and rights to copy, modify
// and redistribute granted by the license, users are provided only with a
// limited warranty and the software's author, the holder of the economic
// rights, and the successive licensors have only limited liability.
//
// In this respect, the user's attention is drawn to the risks associated with
// loading, using, modifying and/or developing or reproducing the software by
// the user in light of its specific status of free software, that may mean
// that it is complicated to manipulate, and that also therefore means that it
// is reserved for developers and experienced professionals having in-depth
// computer knowledge. Users are therefore encouraged to load and test the
// software's suitability as regards their requirements in conditions enabling
// the security of their systems and/or data to be ensured and, more generally,
// to use and operate it in the same conditions as regards security.
//
// The fact that you are presently reading this means that you have had
// knowledge of the CeCILL license and that you accept its terms.
package svcs
2020-06-08 23:25:15 +00:00
import (
"encoding/json"
2020-10-10 16:44:17 +00:00
"fmt"
2020-06-08 23:25:15 +00:00
"git.happydns.org/happydns/model"
)
2020-05-09 11:14:29 +00:00
2020-07-06 09:07:37 +00:00
type ServiceRestrictions struct {
// Alone restricts the service to be the only one for a given subdomain.
Alone bool ` json:"alone,omitempty" `
// ExclusiveRR restricts the service to be present along with others given types.
ExclusiveRR [ ] string ` json:"exclusive,omitempty" `
// GLUE allows a service to be present under Leaf, as GLUE record.
GLUE bool ` json:"glue,omitempty" `
// Leaf restricts the creation of subdomains under this kind of service (blocks NearAlone).
Leaf bool ` json:"leaf,omitempty" `
// NearAlone allows a service to be present along with Alone restricted services (eg. services that will create sub-subdomain from their given subdomain).
NearAlone bool ` json:"nearAlone,omitempty" `
2020-07-26 18:54:53 +00:00
// NeedTypes restricts the service to sources that are compatibles with ALL the given types.
NeedTypes [ ] uint16 ` json:"needTypes,omitempty" `
2020-07-06 09:07:37 +00:00
// RootOnly restricts the service to be present at the root of the domain only.
RootOnly bool ` json:"rootOnly,omitempty" `
// Single restricts the service to be present only once per subdomain.
Single bool ` json:"single,omitempty" `
}
2020-05-09 11:14:29 +00:00
type ServiceInfos struct {
2020-07-06 09:07:37 +00:00
Name string ` json:"name" `
Description string ` json:"description" `
2020-10-10 16:44:17 +00:00
Family string ` json:"family" `
2020-07-06 09:07:37 +00:00
Categories [ ] string ` json:"categories" `
Tabs bool ` json:"tabs,omitempty" `
Restrictions ServiceRestrictions ` json:"restrictions,omitempty" `
2020-05-09 11:14:29 +00:00
}
2020-06-08 23:25:15 +00:00
type serviceCombined struct {
Service happydns . Service
}
2020-10-10 16:44:17 +00:00
type ServiceNotFoundError struct {
name string
}
func ( err ServiceNotFoundError ) Error ( ) string {
return fmt . Sprintf ( "Unable to find corresponding service for `%s`." , err . name )
}
2020-07-28 15:34:55 +00:00
// UnmarshalServiceJSON implements the UnmarshalJSON function for the
// encoding/json module.
2020-06-08 23:25:15 +00:00
func UnmarshalServiceJSON ( svc * happydns . ServiceCombined , b [ ] byte ) ( err error ) {
2020-07-28 15:34:55 +00:00
var svcType happydns . ServiceMeta
2020-06-08 23:25:15 +00:00
err = json . Unmarshal ( b , & svcType )
if err != nil {
return
}
var tsvc happydns . Service
tsvc , err = FindService ( svcType . Type )
2020-10-10 16:44:17 +00:00
if err != nil {
return
}
2020-06-08 23:25:15 +00:00
mySvc := & serviceCombined {
tsvc ,
}
err = json . Unmarshal ( b , mySvc )
svc . Service = tsvc
2020-07-28 15:34:55 +00:00
svc . ServiceMeta = svcType
2020-06-08 23:25:15 +00:00
return
}
func init ( ) {
2020-07-28 15:34:55 +00:00
// Register the UnmarshalServiceJSON variable thats points to the
// Service's UnmarshalJSON implementation that can't be made in model
// module due to cyclic dependancy.
2020-06-08 23:25:15 +00:00
happydns . UnmarshalServiceJSON = UnmarshalServiceJSON
}