-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathverify_egress.go
85 lines (75 loc) · 2.75 KB
/
verify_egress.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
package aws
// --- Example file on how to call egress inluding exampoe on proxy config ---
import (
"context"
"fmt"
"os"
"time"
"github.com/openshift/osd-network-verifier/pkg/data/cloud"
"github.com/openshift/osd-network-verifier/pkg/data/cpu"
"github.com/openshift/osd-network-verifier/pkg/probes/curl"
"github.com/openshift/osd-network-verifier/pkg/proxy"
"github.com/openshift/osd-network-verifier/pkg/verifier"
awsverifier "github.com/openshift/osd-network-verifier/pkg/verifier/aws"
)
func extendValidateEgress() {
//---------Initialize required args---------
// Read AWS creds from environment
key, _ := os.LookupEnv("AWS_ACCESS_KEY_ID")
secret, _ := os.LookupEnv("AWS_SECRET_ACCESS_KEY")
session, _ := os.LookupEnv("AWS_SESSION_TOKEN")
// Create the Verifier Client pass in cred to client builder
awsVerifier, err := awsverifier.NewAwsVerifier(key, secret, session, "us-east-1", "", true)
if err != nil {
fmt.Printf("Oh no I have an error Err: %s", err)
os.Exit(1)
}
//---------egress verifier usage---------
//---------Proxy setup if necessary------
p := proxy.ProxyConfig{
HttpProxy: "http://user:pass@x.x.x.x:8888",
HttpsProxy: "https://user:pass@x.x.x.x:8888",
Cacert: `-----BEGIN RSA PRIVATE KEY-----
EXAMPLEcertificatestartingwithcharsKCAQEAtyzg96LnZG9GIICiZmJbCtFvYwZNtzblGBFgcqBHlWMy0wjd
0mLSC6SJzmbZAiA4XU5pT/BfqKZiZzQ1cjVFmXvp2yo82ZFgccXj61Mx2zQd8eDk
4nYz790DWRauWCr+7cpkAwcKv8WYHuQwBd+q/lTw3z2/Qk8d/7rvzcQ=
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
YlsK0W9jBk23NuUYEWByoEeVYzLTCN3SYtILpInOZtkCIDhdTmlP8F+opmJnNDVy
NUWZe+nbKjzZkWBxxePrUzHbNB3x4OSmqobaNzuxTBHzm27BQN8gfiFxWsgStfbq
zL2f2OsBvvcmBdLgpwcvK9VYN0mpNXhJm5K0e7aQdjhYTQ93Dw4BG15xOs11CuaS
i87hWoaGmS4Bx8gdUx0yZnxU9D7sd9/5Nz6s1J4riLWsz/InVw7Rr1NGTpLDojjX
9hieOYBpwE763AECJrtxyRYHhXZ1DiKEfZWAYWICf8NUGdEohNpWKuUeFbBMlEWW
TRVfvGGNFuJkfkh4rR09wHvlmyzSVJ6le6iaQ0wlp2S0j9oC2A==
-----END CERTIFICATE-----`,
NoTls: false,
}
// Create the egress input
vei := verifier.ValidateEgressInput{
Ctx: context.TODO(),
SubnetID: "vpcSubnetID",
CloudImageID: "cloudImageID",
Timeout: 3 * time.Second,
Tags: map[string]string{"key1": "val1"},
InstanceType: "m5.2xlarge",
Proxy: p,
AWS: verifier.AwsEgressConfig{
KmsKeyID: "kmskeyID",
SecurityGroupIDs: []string{"SecurityGroupID1", "OptionalSecurityGroupID2"},
},
PlatformType: cloud.AWSClassic,
Probe: curl.Probe{},
CPUArchitecture: cpu.ArchX86,
}
// Call egress function with either gcp or aws client
out := verifier.
ValidateEgress(awsVerifier, vei)
if !out.IsSuccessful() {
// Retrieve errors
failures, exceptions, errors := out.Parse()
// Use returned exceptions
fmt.Println(failures)
fmt.Println(exceptions)
fmt.Println(errors)
}
}