本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/kms.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Configure
//Configure ... configures using global settings
func Configure(cfg *GlobalConfig) {
svc = kms.New(session.New(
&aws.Config{
Region: aws.String(cfg.AWSRegion),
},
))
}
示例2: stackConfig
func (c Cluster) stackConfig(opts StackTemplateOptions, compressUserData bool) (*stackConfig, error) {
assets, err := ReadTLSAssets(opts.TLSAssetsDir)
if err != nil {
return nil, err
}
stackConfig := stackConfig{}
if stackConfig.Config, err = c.Config(); err != nil {
return nil, err
}
awsConfig := aws.NewConfig()
awsConfig = awsConfig.WithRegion(stackConfig.Config.Region)
kmsSvc := kms.New(session.New(awsConfig))
compactAssets, err := assets.compact(stackConfig.Config, kmsSvc)
if err != nil {
return nil, fmt.Errorf("failed to compress TLS assets: %v", err)
}
stackConfig.Config.TLSConfig = compactAssets
if stackConfig.UserDataWorker, err = execute(opts.WorkerTmplFile, stackConfig.Config, compressUserData); err != nil {
return nil, fmt.Errorf("failed to render worker cloud config: %v", err)
}
if stackConfig.UserDataController, err = execute(opts.ControllerTmplFile, stackConfig.Config, compressUserData); err != nil {
return nil, fmt.Errorf("failed to render controller cloud config: %v", err)
}
return &stackConfig, nil
}
示例3: loadSneakerManager
// loadSneakerManager returns a sneaker manager if one is configured on the env.
func loadSneakerManager() *sneaker.Manager {
path := String("SNEAKER_S3_PATH")
if path == "" {
return nil
}
u, err := url.Parse(path)
if err != nil {
log.WithField("path", path).Fatal("Invalid SNEAKER_S3_PATH")
return nil
}
if u.Path != "" && u.Path[0] == '/' {
u.Path = u.Path[1:]
}
sess := session.New()
config := aws.NewConfig().WithRegion(String("SNEAKER_S3_REGION", "us-west-2")).WithMaxRetries(3)
return &sneaker.Manager{
Objects: s3.New(sess, config),
Envelope: sneaker.Envelope{
KMS: kms.New(sess, config),
},
Bucket: u.Host,
Prefix: u.Path,
KeyId: String("SNEAKER_MASTER_KEY"),
}
}
示例4: getAliasInformation
func getAliasInformation(alias, region string) (string, error) {
arn := ""
svc := kms.New(session.New(&aws.Config{
Region: ®ion,
}))
truncated := true
var marker *string
for truncated {
out, err := svc.ListAliases(&kms.ListAliasesInput{
Marker: marker,
})
if err != nil {
return arn, err
}
for _, aliasEntry := range out.Aliases {
if *aliasEntry.AliasName == "alias/"+alias {
return *aliasEntry.AliasArn, nil
}
}
truncated = *out.Truncated
marker = out.NextMarker
}
return "", errors.New("The alias " + alias + " does not exist in your account. Please add the proper alias to a key")
}
示例5: ExampleKMS_RetireGrant
func ExampleKMS_RetireGrant() {
svc := kms.New(nil)
params := &kms.RetireGrantInput{
GrantId: aws.String("GrantIdType"),
GrantToken: aws.String("GrantTokenType"),
KeyId: aws.String("KeyIdType"),
}
resp, err := svc.RetireGrant(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例6: ExampleKMS_CreateAlias
func ExampleKMS_CreateAlias() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.CreateAliasInput{
AliasName: aws.String("AliasNameType"), // Required
TargetKeyId: aws.String("KeyIdType"), // Required
}
resp, err := svc.CreateAlias(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例7: ExampleKMS_CreateKey
func ExampleKMS_CreateKey() {
svc := kms.New(nil)
params := &kms.CreateKeyInput{
Description: aws.String("DescriptionType"),
KeyUsage: aws.String("KeyUsageType"),
Policy: aws.String("PolicyType"),
}
resp, err := svc.CreateKey(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例8: ExampleKMS_ScheduleKeyDeletion
func ExampleKMS_ScheduleKeyDeletion() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.ScheduleKeyDeletionInput{
KeyId: aws.String("KeyIdType"), // Required
PendingWindowInDays: aws.Int64(1),
}
resp, err := svc.ScheduleKeyDeletion(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例9: ExampleKMS_PutKeyPolicy
func ExampleKMS_PutKeyPolicy() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.PutKeyPolicyInput{
KeyId: aws.String("KeyIdType"), // Required
Policy: aws.String("PolicyType"), // Required
PolicyName: aws.String("PolicyNameType"), // Required
BypassPolicyLockoutSafetyCheck: aws.Bool(true),
}
resp, err := svc.PutKeyPolicy(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例10: ExampleKMS_RetireGrant
func ExampleKMS_RetireGrant() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.RetireGrantInput{
GrantId: aws.String("GrantIdType"),
GrantToken: aws.String("GrantTokenType"),
KeyId: aws.String("KeyIdType"),
}
resp, err := svc.RetireGrant(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例11: ExampleKMS_Encrypt
func ExampleKMS_Encrypt() {
svc := kms.New(nil)
params := &kms.EncryptInput{
KeyID: aws.String("KeyIdType"), // Required
Plaintext: []byte("PAYLOAD"), // Required
EncryptionContext: map[string]*string{
"Key": aws.String("EncryptionContextValue"), // Required
// More values...
},
GrantTokens: []*string{
aws.String("GrantTokenType"), // Required
// More values...
},
}
resp, err := svc.Encrypt(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例12: ExampleKMS_ListRetirableGrants
func ExampleKMS_ListRetirableGrants() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.ListRetirableGrantsInput{
RetiringPrincipal: aws.String("PrincipalIdType"), // Required
Limit: aws.Int64(1),
Marker: aws.String("MarkerType"),
}
resp, err := svc.ListRetirableGrants(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例13: loadManager
func loadManager() *sneaker.Manager {
u, err := url.Parse(os.Getenv("SNEAKER_S3_PATH"))
if err != nil {
log.Fatalf("bad SNEAKER_S3_PATH: %s", err)
}
if u.Path != "" && u.Path[0] == '/' {
u.Path = u.Path[1:]
}
ctxt, err := parseContext(os.Getenv("SNEAKER_MASTER_CONTEXT"))
if err != nil {
log.Fatalf("bad SNEAKER_MASTER_CONTEXT: %s", err)
}
return &sneaker.Manager{
Objects: s3.New(nil),
Envelope: sneaker.Envelope{
KMS: kms.New(nil),
},
Bucket: u.Host,
Prefix: u.Path,
EncryptionContext: ctxt,
KeyID: os.Getenv("SNEAKER_MASTER_KEY"),
}
}
示例14: ExampleKMS_GetParametersForImport
func ExampleKMS_GetParametersForImport() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.GetParametersForImportInput{
KeyId: aws.String("KeyIdType"), // Required
WrappingAlgorithm: aws.String("AlgorithmSpec"), // Required
WrappingKeySpec: aws.String("WrappingKeySpec"), // Required
}
resp, err := svc.GetParametersForImport(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例15: ExampleKMS_Encrypt
func ExampleKMS_Encrypt() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kms.New(sess)
params := &kms.EncryptInput{
KeyId: aws.String("KeyIdType"), // Required
Plaintext: []byte("PAYLOAD"), // Required
EncryptionContext: map[string]*string{
"Key": aws.String("EncryptionContextValue"), // Required
// More values...
},
GrantTokens: []*string{
aws.String("GrantTokenType"), // Required
// More values...
},
}
resp, err := svc.Encrypt(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}