mirror of
https://github.com/rancher/os.git
synced 2025-09-13 21:51:33 +00:00
Add aliyun datasource (#2169)
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -84,3 +86,25 @@ func (ms Service) MetadataURL() string {
|
||||
func (ms Service) UserdataURL() string {
|
||||
return (ms.Root + ms.UserdataPath)
|
||||
}
|
||||
|
||||
func (ms Service) FetchAttributes(key string) ([]string, error) {
|
||||
url := ms.MetadataURL() + key
|
||||
resp, err := ms.FetchData(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(resp))
|
||||
data := make([]string, 0)
|
||||
for scanner.Scan() {
|
||||
data = append(data, scanner.Text())
|
||||
}
|
||||
return data, scanner.Err()
|
||||
}
|
||||
|
||||
func (ms Service) FetchAttribute(key string) (string, error) {
|
||||
attrs, err := ms.FetchAttributes(key)
|
||||
if err == nil && len(attrs) > 0 {
|
||||
return attrs[0], nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
Reference in New Issue
Block a user