-
Notifications
You must be signed in to change notification settings - Fork 38
/
gex.go
92 lines (76 loc) · 2.85 KB
/
gex.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package cli
import (
"fmt"
"net/url"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
// Set of flags used for GEX
const (
// GEXBasicAuthUsernameFlag is the GEX Basic Auth Username Flag
GEXBasicAuthUsernameFlag string = "gex-basic-auth-username"
//RA Summary: gosec - G101 - Password Management: Hardcoded Password
//RA: This line was flagged because of use of the word "password"
//RA: This line is used to identify the name of the flag. GEXBasicAuthPasswordFlag is the GEX Basic Auth Password Flag.
//RA: This value of this variable does not store an application password.
//RA Developer Status: Mitigated
//RA Validator Status: Mitigated
//RA Validator: jneuner@mitre.org
//RA Modified Severity: CAT III
// #nosec G101
// GEXBasicAuthPasswordFlag is the GEX Basic Auth Password Flag
GEXBasicAuthPasswordFlag string = "gex-basic-auth-password"
// GEXSendProdInvoiceFlag is the GEX Send Prod Invoice Flag
GEXSendProdInvoiceFlag string = "gex-send-prod-invoice"
// GEXURLFlag is the GEX URL FLag
GEXURLFlag string = "gex-url"
// SendToSyncada is the flag to control if we try sending files to syncada or not
SendToSyncada string = "send-to-syncada"
)
var gexHostnames = []string{
"gexb.gw.daas.dla.mil",
}
var gexPaths = []string{
"/msg_data/submit",
"/msg_data/submit/",
}
// InitGEXFlags initializes GEX command line flags
func InitGEXFlags(flag *pflag.FlagSet) {
flag.String(GEXBasicAuthUsernameFlag, "", "GEX api auth username")
flag.String(GEXBasicAuthPasswordFlag, "", "GEX api auth password")
flag.Bool(GEXSendProdInvoiceFlag, false, "Flag (bool) for EDI Invoices to signify if they should be sent with Production or Test indicator")
flag.Bool(SendToSyncada, false, "Flag (bool) for turning on or off sending EDI 858s to syncada, default false")
flag.String(GEXURLFlag, "", "URL for sending an HTTP POST request to GEX")
}
// CheckGEX validates GEX command line flags
func CheckGEX(v *viper.Viper) error {
gexURL := v.GetString(GEXURLFlag)
if len(gexURL) == 0 {
return nil
}
// Parse the URL and check it
u, parseErr := url.Parse(gexURL)
if parseErr != nil {
return parseErr
}
if u.Scheme != "https" {
return fmt.Errorf("invalid gexURL Scheme %s, expecting https", u.Scheme)
}
if !stringSliceContains(gexHostnames, u.Hostname()) {
return fmt.Errorf("invalid gexUrl Hostname %s, expecting one of %q", u.Hostname(), gexHostnames)
}
if !stringSliceContains(gexPaths, u.Path) {
return fmt.Errorf("invalid gexUrl Path %s, expecting one of %q", u.Path, gexPaths)
}
channel := u.Query().Get("channel")
if channel != "" {
return fmt.Errorf("invalid gex channel query parameter %s", channel)
}
if len(v.GetString(GEXBasicAuthUsernameFlag)) == 0 {
return fmt.Errorf("GEX_BASIC_AUTH_USERNAME is missing")
}
if len(v.GetString(GEXBasicAuthPasswordFlag)) == 0 {
return fmt.Errorf("GEX_BASIC_AUTH_PASSWORD is missing")
}
return nil
}