add oracle cloud

This commit is contained in:
Pascal Fischer
2024-02-08 17:49:31 +01:00
parent 0dc326620d
commit 526cd68586
3 changed files with 58 additions and 4 deletions
+4 -4
View File
@@ -9,11 +9,11 @@ func detectAWS() string {
v2ResultChan := make(chan bool, 1)
go func() {
v1ResultChan <- detectIDMSv1()
v1ResultChan <- detectAWSIDMSv1()
}()
go func() {
v2ResultChan <- detectIDMSv2()
v2ResultChan <- detectAWSIDMSv2()
}()
v1Result, v2Result := <-v1ResultChan, <-v2ResultChan
@@ -24,7 +24,7 @@ func detectAWS() string {
return ""
}
func detectIDMSv1() bool {
func detectAWSIDMSv1() bool {
resp, err := hc.Get("http://169.254.169.254/latest/")
if err != nil {
return false
@@ -33,7 +33,7 @@ func detectIDMSv1() bool {
return resp.StatusCode == http.StatusOK
}
func detectIDMSv2() bool {
func detectAWSIDMSv2() bool {
req, err := http.NewRequest("PUT", "http://169.254.169.254/latest/api/token", nil)
if err != nil {
return false
+1
View File
@@ -19,6 +19,7 @@ func Detect() string {
detectAzure,
detectDigitalOcean,
detectGCE,
detectOracle,
detectOpenStack,
detectSoftlayer,
detectVultr,
+53
View File
@@ -0,0 +1,53 @@
package libdetectcloud
import "net/http"
func detectOracle() string {
v1ResultChan := make(chan bool, 1)
v2ResultChan := make(chan bool, 1)
go func() {
v1ResultChan <- detectOracleIDMSv1()
}()
go func() {
v2ResultChan <- detectOracleIDMSv2()
}()
v1Result, v2Result := <-v1ResultChan, <-v2ResultChan
if v1Result || v2Result {
return "Oracle"
}
return ""
}
func detectOracleIDMSv1() bool {
req, err := http.NewRequest("GET", "http://169.254.169.254/opc/v1/instance/", nil)
if err != nil {
return false
}
req.Header.Add("Authorization", "Bearer Oracle")
resp, err := hc.Do(req)
if err != nil {
return false
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
}
func detectOracleIDMSv2() bool {
req, err := http.NewRequest("GET", "http://169.254.169.254/opc/v2/instance/", nil)
if err != nil {
return false
}
req.Header.Add("Authorization", "Bearer Oracle")
resp, err := hc.Do(req)
if err != nil {
return false
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
}