-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.go
77 lines (61 loc) · 1.28 KB
/
verify.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
package cloudverify
import (
"sync"
"time"
"github.com/kamushadenes/cloud-verify/aws"
"github.com/kamushadenes/cloud-verify/azure"
"github.com/kamushadenes/cloud-verify/gcp"
)
type cloudVerification struct {
Name string
RunningOnCloud bool
}
func RunningOnCloud() (bool, string) {
var ch = make(chan *cloudVerification)
var waitCh = make(chan bool)
var wg sync.WaitGroup
wg.Add(1)
go func(ch chan *cloudVerification) {
defer wg.Done()
awsv := aws.NewAWSVerifier()
ch <- &cloudVerification{
Name: "AWS",
RunningOnCloud: awsv.Verify(),
}
}(ch)
wg.Add(1)
go func(ch chan *cloudVerification) {
defer wg.Done()
gcpv := gcp.NewGCPVerifier()
ch <- &cloudVerification{
Name: "GCP",
RunningOnCloud: gcpv.Verify(),
}
}(ch)
wg.Add(1)
go func(ch chan *cloudVerification) {
defer wg.Done()
azurev := azure.NewAzureVerifier()
ch <- &cloudVerification{
Name: "Azure",
RunningOnCloud: azurev.Verify(),
}
}(ch)
go func() {
wg.Wait()
time.Sleep(200 * time.Millisecond)
close(waitCh)
}()
for {
select {
case v := <-ch:
if v.RunningOnCloud {
return true, v.Name
}
case <-waitCh:
return false, "Not Detected"
case <-time.After(5 * time.Second):
return false, "Timeout"
}
}
}