mirror of
https://github.com/netbirdio/libdetectcloud.git
synced 2026-05-22 17:09:55 -07:00
add ibm cloud
This commit is contained in:
@@ -20,6 +20,7 @@ func Detect() string {
|
||||
detectDigitalOcean,
|
||||
detectGCE,
|
||||
detectOracle,
|
||||
detectIBMCloud,
|
||||
detectOpenStack,
|
||||
detectSoftlayer,
|
||||
detectVultr,
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package libdetectcloud
|
||||
|
||||
import "net/http"
|
||||
|
||||
func detectIBMCloud() string {
|
||||
req, err := http.NewRequest("PUT", "http://api.metadata.cloud.ibm.com/instance_identity/v1/token", nil)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
req, err = http.NewRequest("PUT", "https://api.metadata.cloud.ibm.com/instance_identity/v1/token", nil)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
resp, err = hc.Do(req)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return "IBM Cloud"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user