func (a auth) Parse(ing *extensions.Ingress) (interface{}, error) {
	at, err := parser.GetStringAnnotation("auth-type", ing)
	if err != nil {
		return nil, err
	}
	if !authTypeRegex.MatchString(at) {
		return nil, ing_errors.NewLocationDenied("invalid authentication type")
	}
	s, err := parser.GetStringAnnotation("auth-secret", ing)
	if err != nil {
		return nil, ing_errors.LocationDenied{
			Reason: errors.Wrap(err, "error reading secret name from annotation"),
		}
	}
	name := fmt.Sprintf("%v/%v", ing.Namespace, s)
	secret, err := a.r.GetSecret(name)
	if err != nil {
		return nil, ing_errors.LocationDenied{
			Reason: errors.Wrapf(err, "unexpected error reading secret %v", name),
		}
	}
	realm, _ := parser.GetStringAnnotation("auth-realm", ing)
	passFile := fmt.Sprintf("%v/%v-%v.passwd", a.authDirectory, ing.GetNamespace(), ing.GetName())
	err = dumpSecret(passFile, secret)
	if err != nil {
		return nil, err
	}
	return &Config{
		Type:    at,
		Realm:   realm,
		File:    passFile,
		Secured: true,
		FileSHA: file.SHA1(passFile),
		Secret:  name,
	}, nil
}
Parse parses the annotations contained in the ingress
rule used to add authentication in the paths defined in the rule
and generated an htpasswd compatible file to be used as source
during the authentication process
package auth
import (
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"regexp"
	"github.com/pkg/errors"
	api "k8s.io/api/core/v1"
	extensions "k8s.io/api/extensions/v1beta1"
	"github.com/NCCloud/fluid/internal/file"
	"github.com/NCCloud/fluid/internal/ingress/annotations/parser"
	ing_errors "github.com/NCCloud/fluid/internal/ingress/errors"
	"github.com/NCCloud/fluid/internal/ingress/resolver"
)
var (
	authTypeRegex = regexp.MustCompile(`basic|digest`)
	AuthDirectory = "/etc/ingress-controller/auth"
)
type Config struct {
	Type    string `json:"type"`
	Realm   string `json:"realm"`
	File    string `json:"file"`
	Secured bool   `json:"secured"`
	FileSHA string `json:"fileSha"`
	Secret  string `json:"secret"`
}
func (bd1 *Config) Equal(bd2 *Config) bool {
	if bd1 == bd2 {
		return true
	}
	if bd1 == nil || bd2 == nil {
		return false
	}
	if bd1.Type != bd2.Type {
		return false
	}
	if bd1.Realm != bd2.Realm {
		return false
	}
	if bd1.File != bd2.File {
		return false
	}
	if bd1.Secured != bd2.Secured {
		return false
	}
	if bd1.FileSHA != bd2.FileSHA {
		return false
	}
	if bd1.Secret != bd2.Secret {
		return false
	}
	return true
}
type auth struct {
	r             resolver.Resolver
	authDirectory string
}
func NewParser(authDirectory string, r resolver.Resolver) parser.IngressAnnotation {
	os.MkdirAll(authDirectory, 0755)
	currPath := authDirectory
	for currPath != "/" {
		currPath = path.Dir(currPath)
		err := os.Chmod(currPath, 0755)
		if err != nil {
			break
		}
	}
	return auth{r, authDirectory}
}