當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ec2metadata.EC2Metadata類代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/aws/ec2metadata.EC2Metadata的典型用法代碼示例。如果您正苦於以下問題:Golang EC2Metadata類的具體用法?Golang EC2Metadata怎麽用?Golang EC2Metadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EC2Metadata類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: showHelp

func showHelp(meta *ec2metadata.EC2Metadata) {

	fmt.Printf("usage: meta ATTRIBUTE\n\nValid attributes are:\n")
	categories, _ := meta.GetMetadata("/")
	fmt.Println(categories)
	fmt.Println("region")
}
開發者ID:louism517,項目名稱:go-ec2meta,代碼行數:7,代碼來源:main.go

示例2: requestCredList

// requestCredList requests a list of credentials from the EC2 service.
// If there are no credentials, or there is an error making or receiving the request
func requestCredList(client *ec2metadata.EC2Metadata) ([]string, error) {
	resp, err := client.GetMetadata(iamSecurityCredsPath)
	if err != nil {
		return nil, awserr.New("EC2RoleRequestError", "failed to list EC2 Roles", err)
	}

	credsList := []string{}
	s := bufio.NewScanner(strings.NewReader(resp))
	for s.Scan() {
		credsList = append(credsList, s.Text())
	}

	if err := s.Err(); err != nil {
		return nil, awserr.New("SerializationError", "failed to read list of EC2 Roles", err)
	}

	return credsList, nil
}
開發者ID:ZenoRewn,項目名稱:origin,代碼行數:20,代碼來源:ec2_role_provider.go

示例3: requestCred

// requestCred requests the credentials for a specific credentials from the EC2 service.
//
// If the credentials cannot be found, or there is an error reading the response
// and error will be returned.
func requestCred(client *ec2metadata.EC2Metadata, credsName string) (ec2RoleCredRespBody, error) {
	resp, err := client.GetMetadata(path.Join(iamSecurityCredsPath, credsName))
	if err != nil {
		return ec2RoleCredRespBody{},
			awserr.New("EC2RoleRequestError",
				fmt.Sprintf("failed to get %s EC2 Role credentials", credsName),
				err)
	}

	respCreds := ec2RoleCredRespBody{}
	if err := json.NewDecoder(strings.NewReader(resp)).Decode(&respCreds); err != nil {
		return ec2RoleCredRespBody{},
			awserr.New("SerializationError",
				fmt.Sprintf("failed to decode %s EC2 Role credentials", credsName),
				err)
	}

	if respCreds.Code != "Success" {
		// If an error code was returned something failed requesting the role.
		return ec2RoleCredRespBody{}, awserr.New(respCreds.Code, respCreds.Message, nil)
	}

	return respCreds, nil
}
開發者ID:ZenoRewn,項目名稱:origin,代碼行數:28,代碼來源:ec2_role_provider.go


注:本文中的github.com/aws/aws-sdk-go/aws/ec2metadata.EC2Metadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。