Skip to content

Commit df5a739

Browse files
authored
Swift: IAM updates (#6886)
1 parent 6a5af5c commit df5a739

File tree

47 files changed

+650
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+650
-441
lines changed

.doc_gen/metadata/iam_metadata.yaml

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ iam_CreateAccessKey:
581581
- description:
582582
snippet_tags:
583583
- iam.swift.import
584-
- iam.swift.basics.iam.createaccesskey
584+
- iam.swift.basics.iam.CreateAccessKey
585585
Bash:
586586
versions:
587587
- sdk_version: 2
@@ -690,7 +690,7 @@ iam_DeleteAccessKey:
690690
- description:
691691
snippet_tags:
692692
- iam.swift.import
693-
- iam.swift.basics.iam.deleteaccesskey
693+
- iam.swift.basics.iam.DeleteAccessKey
694694
Bash:
695695
versions:
696696
- sdk_version: 2
@@ -1026,7 +1026,7 @@ iam_CreatePolicy:
10261026
- description:
10271027
snippet_tags:
10281028
- iam.swift.import
1029-
- iam.swift.basics.iam.createpolicy
1029+
- iam.swift.basics.iam.CreatePolicy
10301030
Bash:
10311031
versions:
10321032
- sdk_version: 2
@@ -1118,7 +1118,7 @@ iam_DeletePolicy:
11181118
- description:
11191119
snippet_tags:
11201120
- iam.swift.import
1121-
- iam.swift.basics.iam.deletepolicy
1121+
- iam.swift.basics.iam.DeletePolicy
11221122
Bash:
11231123
versions:
11241124
- sdk_version: 2
@@ -1216,7 +1216,7 @@ iam_ListPolicies:
12161216
- description:
12171217
snippet_tags:
12181218
- iam.swift.import
1219-
- iam.swift.listpolicies.handler.listpolicies
1219+
- iam.swift.listpolicies.handler.ListPolicies
12201220
C++:
12211221
versions:
12221222
- sdk_version: 1
@@ -1304,7 +1304,7 @@ iam_GetPolicy:
13041304
- description:
13051305
snippet_tags:
13061306
- iam.swift.import
1307-
- iam.swift.getpolicy.handler.getpolicy
1307+
- iam.swift.getpolicy.handler.GetPolicy
13081308
C++:
13091309
versions:
13101310
- sdk_version: 1
@@ -1426,7 +1426,7 @@ iam_AttachRolePolicy:
14261426
- description:
14271427
snippet_tags:
14281428
- iam.swift.import
1429-
- iam.swift.attachrolepolicy.handler.attachrolepolicy
1429+
- iam.swift.attachrolepolicy.handler.AttachRolePolicy
14301430
JavaScript:
14311431
versions:
14321432
- sdk_version: 3
@@ -1543,7 +1543,7 @@ iam_ListAttachedRolePolicies:
15431543
- description:
15441544
snippet_tags:
15451545
- iam.swift.import
1546-
- iam.swift.listattachedrolepolicies.handler.listattachedrolepolicies
1546+
- iam.swift.listattachedrolepolicies.handler.ListAttachedRolePolicies
15471547
services:
15481548
iam: {ListAttachedRolePolicies}
15491549
iam_DetachRolePolicy:
@@ -1645,7 +1645,7 @@ iam_DetachRolePolicy:
16451645
- description:
16461646
snippet_tags:
16471647
- iam.swift.import
1648-
- iam.swift.basics.iam.detachrolepolicy
1648+
- iam.swift.basics.iam.DetachRolePolicy
16491649
Bash:
16501650
versions:
16511651
- sdk_version: 2
@@ -1752,7 +1752,7 @@ iam_CreateRole:
17521752
- description:
17531753
snippet_tags:
17541754
- iam.swift.import
1755-
- iam.swift.createrole.handler.createrole
1755+
- iam.swift.createrole.handler.CreateRole
17561756
JavaScript:
17571757
versions:
17581758
- sdk_version: 3
@@ -1860,7 +1860,7 @@ iam_ListRoles:
18601860
- description:
18611861
snippet_tags:
18621862
- iam.swift.import
1863-
- iam.swift.listroles.handler.listroles
1863+
- iam.swift.listroles.handler.ListRoles
18641864
services:
18651865
iam: {ListRoles}
18661866
iam_GetRole:
@@ -1934,7 +1934,7 @@ iam_GetRole:
19341934
- description:
19351935
snippet_tags:
19361936
- iam.swift.import
1937-
- iam.swift.getrole.handler.getrole
1937+
- iam.swift.getrole.handler.GetRole
19381938
services:
19391939
iam: {GetRole}
19401940
iam_DeleteRole:
@@ -1999,7 +1999,7 @@ iam_DeleteRole:
19991999
- description:
20002000
snippet_tags:
20012001
- iam.swift.import
2002-
- iam.swift.basics.iam.deleterole
2002+
- iam.swift.basics.iam.DeleteRole
20032003
Bash:
20042004
versions:
20052005
- sdk_version: 2
@@ -2114,7 +2114,7 @@ iam_ListRolePolicies:
21142114
- description:
21152115
snippet_tags:
21162116
- iam.swift.import
2117-
- iam.swift.listrolepolicies.handler.listrolepolicies
2117+
- iam.swift.listrolepolicies.handler.ListRolePolicies
21182118
services:
21192119
iam: {ListRolePolicies}
21202120
iam_Scenario_RoleManagement:
@@ -2216,7 +2216,7 @@ iam_CreateUser:
22162216
- description:
22172217
snippet_tags:
22182218
- iam.swift.import
2219-
- iam.swift.createuser.handler.createuser
2219+
- iam.swift.createuser.handler.CreateUser
22202220
Go:
22212221
versions:
22222222
- sdk_version: 2
@@ -2360,7 +2360,7 @@ iam_DeleteUser:
23602360
- description:
23612361
snippet_tags:
23622362
- iam.swift.import
2363-
- iam.swift.basics.iam.deleteuser
2363+
- iam.swift.basics.iam.DeleteUser
23642364
Bash:
23652365
versions:
23662366
- sdk_version: 2
@@ -2411,6 +2411,15 @@ iam_GetUser:
24112411
snippet_tags:
24122412
- aws-cli.bash-linux.iam.errecho
24132413
- aws-cli.bash-linux.iam.GetUser
2414+
Swift:
2415+
versions:
2416+
- sdk_version: 1
2417+
github: swift/example_code/iam
2418+
excerpts:
2419+
- description:
2420+
snippet_tags:
2421+
- iam.swift.import
2422+
- iam.swift.basics.iam.GetUser
24142423
services:
24152424
iam: {GetUser}
24162425
iam_ListUsers:
@@ -2484,7 +2493,7 @@ iam_ListUsers:
24842493
- description:
24852494
snippet_tags:
24862495
- iam.swift.import
2487-
- iam.swift.listusers.handler.listusers
2496+
- iam.swift.listusers.handler.ListUsers
24882497
Go:
24892498
versions:
24902499
- sdk_version: 2
@@ -2693,7 +2702,7 @@ iam_PutUserPolicy:
26932702
- description:
26942703
snippet_tags:
26952704
- iam.swift.import
2696-
- iam.swift.basics.iam.putuserpolicy
2705+
- iam.swift.basics.iam.PutUserPolicy
26972706
services:
26982707
iam: {PutUserPolicy}
26992708
iam_ListUserPolicies:
@@ -2753,7 +2762,7 @@ iam_DeleteUserPolicy:
27532762
- description:
27542763
snippet_tags:
27552764
- iam.swift.import
2756-
- iam.swift.basics.iam.deleteuserpolicy
2765+
- iam.swift.basics.iam.DeleteUserPolicy
27572766
services:
27582767
iam: {DeleteUserPolicy}
27592768
iam_Scenario_UserPolicies:
@@ -3115,7 +3124,7 @@ iam_ListGroups:
31153124
- description:
31163125
snippet_tags:
31173126
- iam.swift.import
3118-
- iam.swift.listgroups.handler.listgroups
3127+
- iam.swift.listgroups.handler.ListGroups
31193128
services:
31203129
iam: {ListGroups}
31213130
iam_CreateSAMLProvider:
@@ -3202,7 +3211,7 @@ iam_CreateServiceLinkedRole:
32023211
- description:
32033212
snippet_tags:
32043213
- iam.swift.import
3205-
- iam.swift.createservicelinkedrole.handler.createservicelinkedrole
3214+
- iam.swift.createservicelinkedrole.handler.CreateServiceLinkedRole
32063215
services:
32073216
iam: {CreateServiceLinkedRole}
32083217
iam_DeleteServiceLinkedRole:

swift/example_code/iam/AttachRolePolicy/Sources/AttachRolePolicy/AttachRolePolicy.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ struct ExampleCommand: ParsableCommand {
3434
/// example.
3535
// snippet-start:[iam.swift.attachrolepolicy.command.runasync]
3636
func runAsync() async throws {
37-
let serviceHandler = await ServiceHandler()
38-
3937
do {
38+
let serviceHandler = try await ServiceHandler()
39+
4040
_ = try await serviceHandler.attachRolePolicy(role: rolename, policyArn: policyArn)
4141
} catch {
42+
print("ERROR: runAsync:", dump(error))
4243
throw error
4344
}
4445
}

swift/example_code/iam/AttachRolePolicy/Sources/ServiceHandler/ServiceHandler.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public class ServiceHandler {
3131
/// - Returns: A new ``ServiceHandler`` object, ready to be called to
3232
/// execute AWS operations.
3333
// snippet-start:[iam.swift.attachrolepolicy.handler.init]
34-
public init() async {
34+
public init() async throws {
3535
do {
36-
client = try IAMClient(region: "us-east-1")
36+
client = try await IAMClient()
3737
} catch {
3838
print("ERROR: ", dump(error, name: "Initializing Amazon IAM client"))
39-
exit(1)
39+
throw error
4040
}
4141
}
4242
// snippet-end:[iam.swift.attachrolepolicy.handler.init]
@@ -47,7 +47,7 @@ public class ServiceHandler {
4747
/// - role: The name of the role to attach the policy to.
4848
/// - policyArn: The ARN of the policy to attach.
4949
///
50-
// snippet-start:[iam.swift.attachrolepolicy.handler.attachrolepolicy]
50+
// snippet-start:[iam.swift.attachrolepolicy.handler.AttachRolePolicy]
5151
public func attachRolePolicy(role: String, policyArn: String) async throws {
5252
let input = AttachRolePolicyInput(
5353
policyArn: policyArn,
@@ -56,9 +56,10 @@ public class ServiceHandler {
5656
do {
5757
_ = try await client.attachRolePolicy(input: input)
5858
} catch {
59+
print("ERROR: Attaching a role policy:", dump(error))
5960
throw error
6061
}
6162
}
62-
// snippet-end:[iam.swift.attachrolepolicy.handler.attachrolepolicy]
63+
// snippet-end:[iam.swift.attachrolepolicy.handler.AttachRolePolicy]
6364
}
6465
// snippet-end:[iam.swift.attachrolepolicy.handler]

swift/example_code/iam/AttachRolePolicy/Tests/AttachRolePolicyTests/AttachRolePolicyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class AttachRolePolicyTests: XCTestCase {
3131
super.setUp()
3232

3333
Task() {
34-
AttachRolePolicyTests.serviceHandler = await ServiceHandler()
34+
AttachRolePolicyTests.serviceHandler = try await ServiceHandler()
3535
tdSem.signal()
3636
}
3737
tdSem.wait()

swift/example_code/iam/CreateRole/Sources/CreateRole/CreateRole.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ struct ExampleCommand: ParsableCommand {
3131
/// example.
3232
// snippet-start:[iam.swift.createrole.command.runasync]
3333
func runAsync() async throws {
34-
let serviceHandler = await ServiceHandler()
35-
3634
do {
35+
let serviceHandler = try await ServiceHandler()
36+
3737
// Get information about the user running this example. This user
3838
// will be granted the new role.
3939
let user = try await serviceHandler.getUser(name: nil)
@@ -63,6 +63,7 @@ struct ExampleCommand: ParsableCommand {
6363
let roleID = try await serviceHandler.createRole(name: rolename, policyDocument: policyDocument)
6464
print("Created new role \(rolename) with ID \(roleID)")
6565
} catch {
66+
print("ERROR: CreateRole runAsync:", dump(error))
6667
throw error
6768
}
6869
}
@@ -88,4 +89,4 @@ struct Main {
8889
}
8990
}
9091
// snippet-end:[iam.swift.createrole.main]
91-
// snippet-end:[iam.swift.createrole.example]
92+
// snippet-end:[iam.swift.createrole.example]

swift/example_code/iam/CreateRole/Sources/ServiceHandler/ServiceHandler.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public class ServiceHandler {
2727
public let client: IAMClient
2828

2929
/// Initialize and return a new ``ServiceHandler`` object, which is used
30-
/// to drive the AWS calls used for the example.
30+
/// to drive the AWS calls used for the example.
3131
///
3232
/// - Returns: A new ``ServiceHandler`` object, ready to be called to
3333
/// execute AWS operations.
3434
// snippet-start:[iam.swift.createrole.handler.init]
35-
public init() async {
35+
public init() async throws {
3636
do {
37-
client = try IAMClient(region: "us-east-1")
37+
client = try await IAMClient()
3838
} catch {
3939
print("ERROR: ", dump(error, name: "Initializing Amazon IAM client"))
40-
exit(1)
40+
throw error
4141
}
4242
}
4343
// snippet-end:[iam.swift.createrole.handler.init]
@@ -47,7 +47,7 @@ public class ServiceHandler {
4747
/// - Parameter name: The name of the new IAM role.
4848
///
4949
/// - Returns: The ID of the newly created role.
50-
// snippet-start:[iam.swift.createrole.handler.createrole]
50+
// snippet-start:[iam.swift.createrole.handler.CreateRole]
5151
public func createRole(name: String, policyDocument: String) async throws -> String {
5252
let input = CreateRoleInput(
5353
assumeRolePolicyDocument: policyDocument,
@@ -63,10 +63,11 @@ public class ServiceHandler {
6363
}
6464
return id
6565
} catch {
66+
print("ERROR: createRole:", dump(error))
6667
throw error
6768
}
6869
}
69-
// snippet-end:[iam.swift.createrole.handler.createrole]
70+
// snippet-end:[iam.swift.createrole.handler.CreateRole]
7071

7172
/// Get information about the specified user
7273
///
@@ -86,9 +87,10 @@ public class ServiceHandler {
8687
}
8788
return user
8889
} catch {
90+
print("ERROR: getUser:", dump(error))
8991
throw error
9092
}
9193
}
9294
// snippet-end:[iam.swift.createrole.handler.getuser]
9395
}
94-
// snippet-end:[iam.swift.createrole.handler]
96+
// snippet-end:[iam.swift.createrole.handler]

swift/example_code/iam/CreateRole/Tests/CreateRoleTests/CreateRoleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class CreateRoleTests: XCTestCase {
3131
super.setUp()
3232

3333
Task() {
34-
CreateRoleTests.serviceHandler = await ServiceHandler()
34+
CreateRoleTests.serviceHandler = try await ServiceHandler()
3535
tdSem.signal()
3636
}
3737
tdSem.wait()

0 commit comments

Comments
 (0)