Browse Source

En cours de développement

master
mls-361 9 months ago
parent
commit
b5fd39decc
  1. 2
      doc/DOC.md
  2. 40
      internal/config/data/server.go
  3. 26
      internal/util/util.go

2
doc/DOC.md

@ -1,4 +1,4 @@
*Ce guide est en cours de construction.*
*Ce guide est en cours de rédaction.*
# armen

40
internal/config/data/server.go

@ -6,6 +6,12 @@
package data
import (
"forge.chapril.org/mls-361/errors"
"forge.chapril.org/armen/armen/internal/util"
)
const _defaultServerPort = 65530
// Cli AFAIRE.
@ -17,10 +23,10 @@ type Cli struct {
// TLS AFAIRE.
type TLS struct {
Host string
CA string
Cert string
Key string
AuthType int
CA string
Cli *Cli
}
@ -35,6 +41,38 @@ func (s *Server) validate() error {
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
}

26
internal/util/util.go

@ -0,0 +1,26 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### util ####### Copyright (c) 2021 mls-361 #################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package util
import "os"
// PathExists AFAIRE.
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save