当前位置: 首页>>代码示例>>Golang>>正文


Golang EC2Metadata.GetMetadata方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/aws/ec2metadata.EC2Metadata.GetMetadata方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2Metadata.GetMetadata方法的具体用法?Golang EC2Metadata.GetMetadata怎么用?Golang EC2Metadata.GetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/aws/ec2metadata.EC2Metadata的用法示例。


在下文中一共展示了EC2Metadata.GetMetadata方法的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.GetMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。