From 3aee3d73f5bf55f6521e373d7efdc662f85f80cf Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Fri, 9 Feb 2024 11:03:39 +0100 Subject: [PATCH] add ibm cloud --- detect.go | 1 + ibmcloud.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 ibmcloud.go diff --git a/detect.go b/detect.go index bfe5738..9ac1c6d 100644 --- a/detect.go +++ b/detect.go @@ -20,6 +20,7 @@ func Detect() string { detectDigitalOcean, detectGCE, detectOracle, + detectIBMCloud, detectOpenStack, detectSoftlayer, detectVultr, diff --git a/ibmcloud.go b/ibmcloud.go new file mode 100644 index 0000000..68cc92b --- /dev/null +++ b/ibmcloud.go @@ -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 "" +}