examples_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package kms_test
  3. import (
  4. "bytes"
  5. "fmt"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/service/kms"
  9. )
  10. var _ time.Duration
  11. var _ bytes.Buffer
  12. func ExampleKMS_CreateAlias() {
  13. svc := kms.New(nil)
  14. params := &kms.CreateAliasInput{
  15. AliasName: aws.String("AliasNameType"), // Required
  16. TargetKeyId: aws.String("KeyIdType"), // Required
  17. }
  18. resp, err := svc.CreateAlias(params)
  19. if err != nil {
  20. // Print the error, cast err to awserr.Error to get the Code and
  21. // Message from an error.
  22. fmt.Println(err.Error())
  23. return
  24. }
  25. // Pretty-print the response data.
  26. fmt.Println(resp)
  27. }
  28. func ExampleKMS_CreateGrant() {
  29. svc := kms.New(nil)
  30. params := &kms.CreateGrantInput{
  31. GranteePrincipal: aws.String("PrincipalIdType"), // Required
  32. KeyId: aws.String("KeyIdType"), // Required
  33. Constraints: &kms.GrantConstraints{
  34. EncryptionContextEquals: map[string]*string{
  35. "Key": aws.String("EncryptionContextValue"), // Required
  36. // More values...
  37. },
  38. EncryptionContextSubset: map[string]*string{
  39. "Key": aws.String("EncryptionContextValue"), // Required
  40. // More values...
  41. },
  42. },
  43. GrantTokens: []*string{
  44. aws.String("GrantTokenType"), // Required
  45. // More values...
  46. },
  47. Operations: []*string{
  48. aws.String("GrantOperation"), // Required
  49. // More values...
  50. },
  51. RetiringPrincipal: aws.String("PrincipalIdType"),
  52. }
  53. resp, err := svc.CreateGrant(params)
  54. if err != nil {
  55. // Print the error, cast err to awserr.Error to get the Code and
  56. // Message from an error.
  57. fmt.Println(err.Error())
  58. return
  59. }
  60. // Pretty-print the response data.
  61. fmt.Println(resp)
  62. }
  63. func ExampleKMS_CreateKey() {
  64. svc := kms.New(nil)
  65. params := &kms.CreateKeyInput{
  66. Description: aws.String("DescriptionType"),
  67. KeyUsage: aws.String("KeyUsageType"),
  68. Policy: aws.String("PolicyType"),
  69. }
  70. resp, err := svc.CreateKey(params)
  71. if err != nil {
  72. // Print the error, cast err to awserr.Error to get the Code and
  73. // Message from an error.
  74. fmt.Println(err.Error())
  75. return
  76. }
  77. // Pretty-print the response data.
  78. fmt.Println(resp)
  79. }
  80. func ExampleKMS_Decrypt() {
  81. svc := kms.New(nil)
  82. params := &kms.DecryptInput{
  83. CiphertextBlob: []byte("PAYLOAD"), // Required
  84. EncryptionContext: map[string]*string{
  85. "Key": aws.String("EncryptionContextValue"), // Required
  86. // More values...
  87. },
  88. GrantTokens: []*string{
  89. aws.String("GrantTokenType"), // Required
  90. // More values...
  91. },
  92. }
  93. resp, err := svc.Decrypt(params)
  94. if err != nil {
  95. // Print the error, cast err to awserr.Error to get the Code and
  96. // Message from an error.
  97. fmt.Println(err.Error())
  98. return
  99. }
  100. // Pretty-print the response data.
  101. fmt.Println(resp)
  102. }
  103. func ExampleKMS_DeleteAlias() {
  104. svc := kms.New(nil)
  105. params := &kms.DeleteAliasInput{
  106. AliasName: aws.String("AliasNameType"), // Required
  107. }
  108. resp, err := svc.DeleteAlias(params)
  109. if err != nil {
  110. // Print the error, cast err to awserr.Error to get the Code and
  111. // Message from an error.
  112. fmt.Println(err.Error())
  113. return
  114. }
  115. // Pretty-print the response data.
  116. fmt.Println(resp)
  117. }
  118. func ExampleKMS_DescribeKey() {
  119. svc := kms.New(nil)
  120. params := &kms.DescribeKeyInput{
  121. KeyId: aws.String("KeyIdType"), // Required
  122. }
  123. resp, err := svc.DescribeKey(params)
  124. if err != nil {
  125. // Print the error, cast err to awserr.Error to get the Code and
  126. // Message from an error.
  127. fmt.Println(err.Error())
  128. return
  129. }
  130. // Pretty-print the response data.
  131. fmt.Println(resp)
  132. }
  133. func ExampleKMS_DisableKey() {
  134. svc := kms.New(nil)
  135. params := &kms.DisableKeyInput{
  136. KeyId: aws.String("KeyIdType"), // Required
  137. }
  138. resp, err := svc.DisableKey(params)
  139. if err != nil {
  140. // Print the error, cast err to awserr.Error to get the Code and
  141. // Message from an error.
  142. fmt.Println(err.Error())
  143. return
  144. }
  145. // Pretty-print the response data.
  146. fmt.Println(resp)
  147. }
  148. func ExampleKMS_DisableKeyRotation() {
  149. svc := kms.New(nil)
  150. params := &kms.DisableKeyRotationInput{
  151. KeyId: aws.String("KeyIdType"), // Required
  152. }
  153. resp, err := svc.DisableKeyRotation(params)
  154. if err != nil {
  155. // Print the error, cast err to awserr.Error to get the Code and
  156. // Message from an error.
  157. fmt.Println(err.Error())
  158. return
  159. }
  160. // Pretty-print the response data.
  161. fmt.Println(resp)
  162. }
  163. func ExampleKMS_EnableKey() {
  164. svc := kms.New(nil)
  165. params := &kms.EnableKeyInput{
  166. KeyId: aws.String("KeyIdType"), // Required
  167. }
  168. resp, err := svc.EnableKey(params)
  169. if err != nil {
  170. // Print the error, cast err to awserr.Error to get the Code and
  171. // Message from an error.
  172. fmt.Println(err.Error())
  173. return
  174. }
  175. // Pretty-print the response data.
  176. fmt.Println(resp)
  177. }
  178. func ExampleKMS_EnableKeyRotation() {
  179. svc := kms.New(nil)
  180. params := &kms.EnableKeyRotationInput{
  181. KeyId: aws.String("KeyIdType"), // Required
  182. }
  183. resp, err := svc.EnableKeyRotation(params)
  184. if err != nil {
  185. // Print the error, cast err to awserr.Error to get the Code and
  186. // Message from an error.
  187. fmt.Println(err.Error())
  188. return
  189. }
  190. // Pretty-print the response data.
  191. fmt.Println(resp)
  192. }
  193. func ExampleKMS_Encrypt() {
  194. svc := kms.New(nil)
  195. params := &kms.EncryptInput{
  196. KeyId: aws.String("KeyIdType"), // Required
  197. Plaintext: []byte("PAYLOAD"), // Required
  198. EncryptionContext: map[string]*string{
  199. "Key": aws.String("EncryptionContextValue"), // Required
  200. // More values...
  201. },
  202. GrantTokens: []*string{
  203. aws.String("GrantTokenType"), // Required
  204. // More values...
  205. },
  206. }
  207. resp, err := svc.Encrypt(params)
  208. if err != nil {
  209. // Print the error, cast err to awserr.Error to get the Code and
  210. // Message from an error.
  211. fmt.Println(err.Error())
  212. return
  213. }
  214. // Pretty-print the response data.
  215. fmt.Println(resp)
  216. }
  217. func ExampleKMS_GenerateDataKey() {
  218. svc := kms.New(nil)
  219. params := &kms.GenerateDataKeyInput{
  220. KeyId: aws.String("KeyIdType"), // Required
  221. EncryptionContext: map[string]*string{
  222. "Key": aws.String("EncryptionContextValue"), // Required
  223. // More values...
  224. },
  225. GrantTokens: []*string{
  226. aws.String("GrantTokenType"), // Required
  227. // More values...
  228. },
  229. KeySpec: aws.String("DataKeySpec"),
  230. NumberOfBytes: aws.Int64(1),
  231. }
  232. resp, err := svc.GenerateDataKey(params)
  233. if err != nil {
  234. // Print the error, cast err to awserr.Error to get the Code and
  235. // Message from an error.
  236. fmt.Println(err.Error())
  237. return
  238. }
  239. // Pretty-print the response data.
  240. fmt.Println(resp)
  241. }
  242. func ExampleKMS_GenerateDataKeyWithoutPlaintext() {
  243. svc := kms.New(nil)
  244. params := &kms.GenerateDataKeyWithoutPlaintextInput{
  245. KeyId: aws.String("KeyIdType"), // Required
  246. EncryptionContext: map[string]*string{
  247. "Key": aws.String("EncryptionContextValue"), // Required
  248. // More values...
  249. },
  250. GrantTokens: []*string{
  251. aws.String("GrantTokenType"), // Required
  252. // More values...
  253. },
  254. KeySpec: aws.String("DataKeySpec"),
  255. NumberOfBytes: aws.Int64(1),
  256. }
  257. resp, err := svc.GenerateDataKeyWithoutPlaintext(params)
  258. if err != nil {
  259. // Print the error, cast err to awserr.Error to get the Code and
  260. // Message from an error.
  261. fmt.Println(err.Error())
  262. return
  263. }
  264. // Pretty-print the response data.
  265. fmt.Println(resp)
  266. }
  267. func ExampleKMS_GenerateRandom() {
  268. svc := kms.New(nil)
  269. params := &kms.GenerateRandomInput{
  270. NumberOfBytes: aws.Int64(1),
  271. }
  272. resp, err := svc.GenerateRandom(params)
  273. if err != nil {
  274. // Print the error, cast err to awserr.Error to get the Code and
  275. // Message from an error.
  276. fmt.Println(err.Error())
  277. return
  278. }
  279. // Pretty-print the response data.
  280. fmt.Println(resp)
  281. }
  282. func ExampleKMS_GetKeyPolicy() {
  283. svc := kms.New(nil)
  284. params := &kms.GetKeyPolicyInput{
  285. KeyId: aws.String("KeyIdType"), // Required
  286. PolicyName: aws.String("PolicyNameType"), // Required
  287. }
  288. resp, err := svc.GetKeyPolicy(params)
  289. if err != nil {
  290. // Print the error, cast err to awserr.Error to get the Code and
  291. // Message from an error.
  292. fmt.Println(err.Error())
  293. return
  294. }
  295. // Pretty-print the response data.
  296. fmt.Println(resp)
  297. }
  298. func ExampleKMS_GetKeyRotationStatus() {
  299. svc := kms.New(nil)
  300. params := &kms.GetKeyRotationStatusInput{
  301. KeyId: aws.String("KeyIdType"), // Required
  302. }
  303. resp, err := svc.GetKeyRotationStatus(params)
  304. if err != nil {
  305. // Print the error, cast err to awserr.Error to get the Code and
  306. // Message from an error.
  307. fmt.Println(err.Error())
  308. return
  309. }
  310. // Pretty-print the response data.
  311. fmt.Println(resp)
  312. }
  313. func ExampleKMS_ListAliases() {
  314. svc := kms.New(nil)
  315. params := &kms.ListAliasesInput{
  316. Limit: aws.Int64(1),
  317. Marker: aws.String("MarkerType"),
  318. }
  319. resp, err := svc.ListAliases(params)
  320. if err != nil {
  321. // Print the error, cast err to awserr.Error to get the Code and
  322. // Message from an error.
  323. fmt.Println(err.Error())
  324. return
  325. }
  326. // Pretty-print the response data.
  327. fmt.Println(resp)
  328. }
  329. func ExampleKMS_ListGrants() {
  330. svc := kms.New(nil)
  331. params := &kms.ListGrantsInput{
  332. KeyId: aws.String("KeyIdType"), // Required
  333. Limit: aws.Int64(1),
  334. Marker: aws.String("MarkerType"),
  335. }
  336. resp, err := svc.ListGrants(params)
  337. if err != nil {
  338. // Print the error, cast err to awserr.Error to get the Code and
  339. // Message from an error.
  340. fmt.Println(err.Error())
  341. return
  342. }
  343. // Pretty-print the response data.
  344. fmt.Println(resp)
  345. }
  346. func ExampleKMS_ListKeyPolicies() {
  347. svc := kms.New(nil)
  348. params := &kms.ListKeyPoliciesInput{
  349. KeyId: aws.String("KeyIdType"), // Required
  350. Limit: aws.Int64(1),
  351. Marker: aws.String("MarkerType"),
  352. }
  353. resp, err := svc.ListKeyPolicies(params)
  354. if err != nil {
  355. // Print the error, cast err to awserr.Error to get the Code and
  356. // Message from an error.
  357. fmt.Println(err.Error())
  358. return
  359. }
  360. // Pretty-print the response data.
  361. fmt.Println(resp)
  362. }
  363. func ExampleKMS_ListKeys() {
  364. svc := kms.New(nil)
  365. params := &kms.ListKeysInput{
  366. Limit: aws.Int64(1),
  367. Marker: aws.String("MarkerType"),
  368. }
  369. resp, err := svc.ListKeys(params)
  370. if err != nil {
  371. // Print the error, cast err to awserr.Error to get the Code and
  372. // Message from an error.
  373. fmt.Println(err.Error())
  374. return
  375. }
  376. // Pretty-print the response data.
  377. fmt.Println(resp)
  378. }
  379. func ExampleKMS_PutKeyPolicy() {
  380. svc := kms.New(nil)
  381. params := &kms.PutKeyPolicyInput{
  382. KeyId: aws.String("KeyIdType"), // Required
  383. Policy: aws.String("PolicyType"), // Required
  384. PolicyName: aws.String("PolicyNameType"), // Required
  385. }
  386. resp, err := svc.PutKeyPolicy(params)
  387. if err != nil {
  388. // Print the error, cast err to awserr.Error to get the Code and
  389. // Message from an error.
  390. fmt.Println(err.Error())
  391. return
  392. }
  393. // Pretty-print the response data.
  394. fmt.Println(resp)
  395. }
  396. func ExampleKMS_ReEncrypt() {
  397. svc := kms.New(nil)
  398. params := &kms.ReEncryptInput{
  399. CiphertextBlob: []byte("PAYLOAD"), // Required
  400. DestinationKeyId: aws.String("KeyIdType"), // Required
  401. DestinationEncryptionContext: map[string]*string{
  402. "Key": aws.String("EncryptionContextValue"), // Required
  403. // More values...
  404. },
  405. GrantTokens: []*string{
  406. aws.String("GrantTokenType"), // Required
  407. // More values...
  408. },
  409. SourceEncryptionContext: map[string]*string{
  410. "Key": aws.String("EncryptionContextValue"), // Required
  411. // More values...
  412. },
  413. }
  414. resp, err := svc.ReEncrypt(params)
  415. if err != nil {
  416. // Print the error, cast err to awserr.Error to get the Code and
  417. // Message from an error.
  418. fmt.Println(err.Error())
  419. return
  420. }
  421. // Pretty-print the response data.
  422. fmt.Println(resp)
  423. }
  424. func ExampleKMS_RetireGrant() {
  425. svc := kms.New(nil)
  426. params := &kms.RetireGrantInput{
  427. GrantId: aws.String("GrantIdType"),
  428. GrantToken: aws.String("GrantTokenType"),
  429. KeyId: aws.String("KeyIdType"),
  430. }
  431. resp, err := svc.RetireGrant(params)
  432. if err != nil {
  433. // Print the error, cast err to awserr.Error to get the Code and
  434. // Message from an error.
  435. fmt.Println(err.Error())
  436. return
  437. }
  438. // Pretty-print the response data.
  439. fmt.Println(resp)
  440. }
  441. func ExampleKMS_RevokeGrant() {
  442. svc := kms.New(nil)
  443. params := &kms.RevokeGrantInput{
  444. GrantId: aws.String("GrantIdType"), // Required
  445. KeyId: aws.String("KeyIdType"), // Required
  446. }
  447. resp, err := svc.RevokeGrant(params)
  448. if err != nil {
  449. // Print the error, cast err to awserr.Error to get the Code and
  450. // Message from an error.
  451. fmt.Println(err.Error())
  452. return
  453. }
  454. // Pretty-print the response data.
  455. fmt.Println(resp)
  456. }
  457. func ExampleKMS_UpdateAlias() {
  458. svc := kms.New(nil)
  459. params := &kms.UpdateAliasInput{
  460. AliasName: aws.String("AliasNameType"), // Required
  461. TargetKeyId: aws.String("KeyIdType"), // Required
  462. }
  463. resp, err := svc.UpdateAlias(params)
  464. if err != nil {
  465. // Print the error, cast err to awserr.Error to get the Code and
  466. // Message from an error.
  467. fmt.Println(err.Error())
  468. return
  469. }
  470. // Pretty-print the response data.
  471. fmt.Println(resp)
  472. }
  473. func ExampleKMS_UpdateKeyDescription() {
  474. svc := kms.New(nil)
  475. params := &kms.UpdateKeyDescriptionInput{
  476. Description: aws.String("DescriptionType"), // Required
  477. KeyId: aws.String("KeyIdType"), // Required
  478. }
  479. resp, err := svc.UpdateKeyDescription(params)
  480. if err != nil {
  481. // Print the error, cast err to awserr.Error to get the Code and
  482. // Message from an error.
  483. fmt.Println(err.Error())
  484. return
  485. }
  486. // Pretty-print the response data.
  487. fmt.Println(resp)
  488. }