Jobs & Workflows
https://armen.surge.sh
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.8 KiB
81 lines
1.8 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### data ####### Copyright (c) 2021 mls-361 #################################################### MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package data |
|
|
|
import ( |
|
"forge.chapril.org/mls-361/errors" |
|
|
|
"forge.chapril.org/armen/armen/internal/util" |
|
) |
|
|
|
const _defaultServerPort = 65530 |
|
|
|
// Cli AFAIRE. |
|
type Cli struct { |
|
Cert string |
|
Key string |
|
} |
|
|
|
// TLS AFAIRE. |
|
type TLS struct { |
|
Host string |
|
Cert string |
|
Key string |
|
AuthType int |
|
CA string |
|
Cli *Cli |
|
} |
|
|
|
// Server AFAIRE. |
|
type Server struct { |
|
Port int |
|
TLS *TLS |
|
} |
|
|
|
func (s *Server) validate() error { |
|
if s.Port == 0 { |
|
s.Port = _defaultServerPort |
|
} |
|
|
|
if s.TLS == nil { |
|
return nil |
|
} |
|
|
|
tls := s.TLS |
|
|
|
if cert, err := util.PathExists(tls.Cert); err != nil { |
|
return err |
|
} else if !cert { |
|
return errors.New("this file doesn't exist", "file", tls.Cert) ///////////////////////////////////////////////// |
|
} |
|
|
|
if key, err := util.PathExists(tls.Key); err != nil { |
|
return err |
|
} else if !key { |
|
return errors.New("this file doesn't exist", "file", tls.Key) ////////////////////////////////////////////////// |
|
} |
|
|
|
if tls.AuthType < 0 || tls.AuthType > 4 { |
|
return errors.New("the value of this parameter is not valid", "tls.authtype", tls.AuthType) //////////////////// |
|
} |
|
|
|
if tls.AuthType == 0 { |
|
return nil |
|
} |
|
|
|
if ca, err := util.PathExists(tls.CA); err != nil { |
|
return err |
|
} else if !ca { |
|
return errors.New("this file doesn't exist", "file", tls.CA) /////////////////////////////////////////////////// |
|
} |
|
|
|
return nil |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|