Welcome to mirror list, hosted at ThFree Co, Russian Federation.

validateargs.go « validateargs « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff7484c85f0cf6f5d629e7c13add8d46e561a54e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package validateargs

import (
	"fmt"
	"strings"
)

const (
	deprecatedMessage = "command line options have been deprecated:"
	notAllowedMsg     = "invalid command line arguments:"
)

var deprecatedArgs = []string{"-sentry-dsn"}
var notAllowedArgs = []string{"-auth-client-id", "-auth-client-secret", "-auth-secret", "-auth-scope"}

// Deprecated checks if deprecated params have been used
func Deprecated(args []string) error {
	return validate(args, deprecatedArgs, deprecatedMessage)
}

// NotAllowed checks if explicitly not allowed params have been used
func NotAllowed(args []string) error {
	return validate(args, notAllowedArgs, notAllowedMsg)
}

func validate(args, invalidArgs []string, errMsg string) error {
	var foundInvalidArgs []string

	argsStr := strings.Join(args, " ")
	for _, invalidArg := range invalidArgs {
		if strings.Contains(argsStr, invalidArg) {
			foundInvalidArgs = append(foundInvalidArgs, invalidArg)
		}
	}

	if len(foundInvalidArgs) > 0 {
		return fmt.Errorf("%s %s", errMsg, strings.Join(foundInvalidArgs, ", "))
	}

	return nil
}