summaryrefslogtreecommitdiff
path: root/python-aws-sso-lib.spec
blob: 0cfe0b446f7a93b79d9d20ff2cc7f2d9eea96d51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
%global _empty_manifest_terminate_build 0
Name:		python-aws-sso-lib
Version:	1.14.0
Release:	1
Summary:	Library to make AWS SSO easier
License:	Apache-2.0
URL:		https://github.com/benkehoe/aws-sso-util/blob/master/lib/README.md
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/3d/df/302bafc5e7182212eec091269c4731bb4469041a1db5e6c3643d089d135d/aws_sso_lib-1.14.0.tar.gz
BuildArch:	noarch

Requires:	python3-boto3
Requires:	python3-aws-error-utils

%description
# `aws-sso-lib`

`aws-sso-lib` allows you to programmatically interact with AWS IAM Identity Center (formerly AWS SSO).

The primary functions that will be of interest are available at the package level:
* `get_boto3_session`: Get a boto3 session for a specific account and role.
* `login`: ensure the user is logged in to Identity Center, with dispatch to the browser.
* `list_available_accounts` and `list_available_roles`: discover the access the user has.
* `list_assignments`: for admin purposes, iterate over all assignments in Identity Center, which is currently hard to do through the API.

`aws-sso-util` is a command-line utility built on `aws-sso-lib` for interacting with Identity Center; see the details of that project [here](https://github.com/benkehoe/aws-sso-util).

## Install

```
pip install --user aws-sso-lib
python -c "import aws_sso_lib; aws_sso_lib.login('https://my-start-url.awsapps.com/start', 'us-east-2')"
```

## `get_boto3_session`

Often when writing a script, you know the exact account and role you want the script to use.
You could configure a profile in your `~/.aws/config` for this (perhaps using `aws-sso-util configure profile`), but especially if multiple people may be using the script, it's more convenient to have the configuration baked into the script itself.
`get_boto3_session()` is the function to do that with.

```python
get_boto3_session(start_url, sso_region, account_id, role_name, *, region,
    login=False,
    sso_cache=None,
    credential_cache=None)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `account_id`: [REQUIRED] The AWS account ID to use.
* `role_name`: [REQUIRED] The Identity Center role (aka PermissionSet) name to use.
* `region`: [REQUIRED] The AWS region for the boto3 session (note, required but keyword-only).
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* `sso_cache`: A dict or dict-like object for Identity Center credential caching to replace the default file cache in `~/.aws/sso/cache`.
* `credential_cache`: A dict or dict-like object to cache the role credentials in to replace the default in-memory cache.
* Returns a [boto3 Session object](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) configured for the account and role.

For more control over the login process, use the `login` function separately.

## `login`

While the functions that require the user to be logged in let you specify `login=True` to interactively log in the user if they are not already logged in, you can have more control over the process, or retrieve the access token, using `login()`.

If the user is not logged in or `force_refresh` is `True`, it will attempt to log in.
If the user is logged in and `force_refresh` is `False`, no action is taken.

Normally, it will attempt to automatically open the user's browser to log in, as well as printing the URL and code to stderr as a fallback. However, if `disable_browser` is `True`, or if `disable_browser` is `None` (the default) and the environment variable `AWS_SSO_DISABLE_BROWSER` is set to `1` or `true`, only the message with the URL and code will be printed.

A custom message can be printed by setting `message` to a template string using `{url}` and `{code}` as placeholders.
The message can be suppressed by setting `message` to `False`.

To fully control the communication with the user, use the `user_auth_handler` parameter.
It must be a callable taking four keyword arguments: `verificationUri`, `userCode`, `verificationUriComplete`, and `expiresAt` (a datetime).
Provide `verificationUri` and `userCode` to the user if they are expected to type them in manually (e.g., on a separate device); `verificationUriComplete` has the userCode embedded in it, suitable for copying, linking, or a browser popup.
The function must return promptly or it will block the login process.

```python
login(start_url, sso_region, *,
    force_refresh=False,
    expiry_window=None,
    disable_browser=None,
    message=None,
    outfile=None,
    user_auth_handler=None,
    sso_cache=None)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `force_refresh`: Set to `True` to always go through the authentication process.
* `expiry_window`: A datetime.timedelta (or number of seconds), or callable returning such, specifying the minimum duration any existing token must be valid for.
* `disable_browser`: Set to `True` to skip the browser popup and only print a message with the URL and code.
* `message`: A message template to print with the fallback URL and code, or `False` to suppress the message.
* `outfile`: The file-like object to print the message to (stderr by default)
* `user_auth_handler`: override browser popup and message printing and use the given function instead.
* `sso_cache`: A dict or dict-like object for Identity Center credential caching, to override the default file cache in `~/.aws/sso/cache`.
* Returns the token dict as returned by [sso-oidc:CreateToken](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html), which contains the actual authorization token, as well as the expiration.

## `list_available_accounts` and `list_available_roles`

Identity Center provides programmatic access to the permissions that a user has.
You can access this through `list_available_accounts()` and `list_available_roles()`.

With both, you can set `login=True` to interactively log in the user if they are not already logged in.

Note that these functions return iterators; they don't return a list, because the number of roles may be very large and you shouldn't have to wait for the entire list to be created to start processing.
You can always get a list by, for example, `list(list_available_roles(...))`.

```python
list_available_accounts(start_url, sso_region, *, login=False)
```

* `start_url`: The start URL for the Identity Center instance.
* `sso_region`: The AWS region for the Identity Center instance.
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* Returns an iterator that yields account id and account name.

```python
list_available_roles(start_url, sso_region, account_id=None, *, login=False)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `account_id`: Optional account id or list of account ids to check.
  * If not set, all accounts available to the user are used.
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* Returns an iterator that yields account id, account name, and role name.

## `list_assignments`

The Identity Center API only allows you to [list assignments for a specific account _and_ permission set](https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_ListAccountAssignments.html).
To find all your assignments, you need to iterate over all accounts, and then interate over all permission sets.
`list_assignments()` does this work for you.

Unlike the other functions list above, this uses admin APIs, which require AWS credentials, rather than taking as input a start URL and region.

`list_assignments` returns an iterator over `Assignment` named tuples, which have the following fields:

* `instance_arn`
* `principal_type`
* `principal_id`
* `principal_name`
* `permission_set_arn`
* `permission_set_name`
* `target_type`
* `target_id`
* `target_name`

The name fields may be `None`, if the names are not known or looked up.
By default, principal and permission set names are not retrieved, nor are account names for accounts that have been provided as explicit targets.

If you don't specify `instance_arn` and/or `identity_store_id`, these will be looked up using the [ListInstances API](https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_ListInstances.html), which today returns at most one instance (with associated identity store).

An assignment is the combination of a principal (a user or a group), a permission set, and a target (an AWS account).
For each of these values, you can provide either an explicit specification, or a filter function.

You can provide an OU as a target, which will use all accounts in that OU, and optionally all accounts recursively in child OUs as well.

```python
list_assignments(
    session,
    instance_arn=None,
    identity_store_id=None,
    principal=None,
    principal_filter=None,
    permission_set=None,
    permission_set_filter=None,
    target=None,
    target_filter=None,
    get_principal_names=False,
    get_permission_set_names=False,
    get_target_names=False,
    ou_recursive=False)
```

* `session`: [REQUIRED] boto3 session to use
* `instance_arn`: The Identity Center instance to use, or it will be looked up using ListInstances
* `identity_store_id`: The identity store to use if principal names are being retrieved or it will be looked up using ListInstances
* `principal`: A principal specification or list of principal specifications.
    * A principal specification is a principal id or a 2-tuple of principal type and id.
* `principal_filter`: A callable taking principal type, principal id, and principal name (which may be `None`), and returning `True` if the principal should be included.
* `permission_set`: A permission set arn or id, or a list of the same.
* `permission_set_filter`: A callable taking permission set arn and name (name may be `None`), returning True if the permission set should be included.
* `target`: A target specification or list of target specifications.
    * A target specification is an account or OU id, or a 2-tuple of target type, which is either AWS_ACCOUNT or AWS_OU, and target id.
* `target_filter`: A callable taking target type, target id, and target name (which may be `None`), and returning `True` if the target should be included.
* `get_principal_names`: Set to `True` to retrieve names for principals in assignments.
* ` get_permission_set_names`: Set to `True` to retrieve names for permission sets in assignments.
* `get_target_names`: Set to `True` to retrieve names for targets in assignments, when they are explicitly provided as targets. For OUs as targets or if no targets are specified, the account names will be retrieved automatically during the enumeration process.
* `ou_recursive`: Set to `True` if an OU is provided as a target to get all accounts including those in child OUs.
* Returns an iterator over `Assignment` tuples


%package -n python3-aws-sso-lib
Summary:	Library to make AWS SSO easier
Provides:	python-aws-sso-lib
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-aws-sso-lib
# `aws-sso-lib`

`aws-sso-lib` allows you to programmatically interact with AWS IAM Identity Center (formerly AWS SSO).

The primary functions that will be of interest are available at the package level:
* `get_boto3_session`: Get a boto3 session for a specific account and role.
* `login`: ensure the user is logged in to Identity Center, with dispatch to the browser.
* `list_available_accounts` and `list_available_roles`: discover the access the user has.
* `list_assignments`: for admin purposes, iterate over all assignments in Identity Center, which is currently hard to do through the API.

`aws-sso-util` is a command-line utility built on `aws-sso-lib` for interacting with Identity Center; see the details of that project [here](https://github.com/benkehoe/aws-sso-util).

## Install

```
pip install --user aws-sso-lib
python -c "import aws_sso_lib; aws_sso_lib.login('https://my-start-url.awsapps.com/start', 'us-east-2')"
```

## `get_boto3_session`

Often when writing a script, you know the exact account and role you want the script to use.
You could configure a profile in your `~/.aws/config` for this (perhaps using `aws-sso-util configure profile`), but especially if multiple people may be using the script, it's more convenient to have the configuration baked into the script itself.
`get_boto3_session()` is the function to do that with.

```python
get_boto3_session(start_url, sso_region, account_id, role_name, *, region,
    login=False,
    sso_cache=None,
    credential_cache=None)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `account_id`: [REQUIRED] The AWS account ID to use.
* `role_name`: [REQUIRED] The Identity Center role (aka PermissionSet) name to use.
* `region`: [REQUIRED] The AWS region for the boto3 session (note, required but keyword-only).
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* `sso_cache`: A dict or dict-like object for Identity Center credential caching to replace the default file cache in `~/.aws/sso/cache`.
* `credential_cache`: A dict or dict-like object to cache the role credentials in to replace the default in-memory cache.
* Returns a [boto3 Session object](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) configured for the account and role.

For more control over the login process, use the `login` function separately.

## `login`

While the functions that require the user to be logged in let you specify `login=True` to interactively log in the user if they are not already logged in, you can have more control over the process, or retrieve the access token, using `login()`.

If the user is not logged in or `force_refresh` is `True`, it will attempt to log in.
If the user is logged in and `force_refresh` is `False`, no action is taken.

Normally, it will attempt to automatically open the user's browser to log in, as well as printing the URL and code to stderr as a fallback. However, if `disable_browser` is `True`, or if `disable_browser` is `None` (the default) and the environment variable `AWS_SSO_DISABLE_BROWSER` is set to `1` or `true`, only the message with the URL and code will be printed.

A custom message can be printed by setting `message` to a template string using `{url}` and `{code}` as placeholders.
The message can be suppressed by setting `message` to `False`.

To fully control the communication with the user, use the `user_auth_handler` parameter.
It must be a callable taking four keyword arguments: `verificationUri`, `userCode`, `verificationUriComplete`, and `expiresAt` (a datetime).
Provide `verificationUri` and `userCode` to the user if they are expected to type them in manually (e.g., on a separate device); `verificationUriComplete` has the userCode embedded in it, suitable for copying, linking, or a browser popup.
The function must return promptly or it will block the login process.

```python
login(start_url, sso_region, *,
    force_refresh=False,
    expiry_window=None,
    disable_browser=None,
    message=None,
    outfile=None,
    user_auth_handler=None,
    sso_cache=None)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `force_refresh`: Set to `True` to always go through the authentication process.
* `expiry_window`: A datetime.timedelta (or number of seconds), or callable returning such, specifying the minimum duration any existing token must be valid for.
* `disable_browser`: Set to `True` to skip the browser popup and only print a message with the URL and code.
* `message`: A message template to print with the fallback URL and code, or `False` to suppress the message.
* `outfile`: The file-like object to print the message to (stderr by default)
* `user_auth_handler`: override browser popup and message printing and use the given function instead.
* `sso_cache`: A dict or dict-like object for Identity Center credential caching, to override the default file cache in `~/.aws/sso/cache`.
* Returns the token dict as returned by [sso-oidc:CreateToken](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html), which contains the actual authorization token, as well as the expiration.

## `list_available_accounts` and `list_available_roles`

Identity Center provides programmatic access to the permissions that a user has.
You can access this through `list_available_accounts()` and `list_available_roles()`.

With both, you can set `login=True` to interactively log in the user if they are not already logged in.

Note that these functions return iterators; they don't return a list, because the number of roles may be very large and you shouldn't have to wait for the entire list to be created to start processing.
You can always get a list by, for example, `list(list_available_roles(...))`.

```python
list_available_accounts(start_url, sso_region, *, login=False)
```

* `start_url`: The start URL for the Identity Center instance.
* `sso_region`: The AWS region for the Identity Center instance.
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* Returns an iterator that yields account id and account name.

```python
list_available_roles(start_url, sso_region, account_id=None, *, login=False)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `account_id`: Optional account id or list of account ids to check.
  * If not set, all accounts available to the user are used.
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* Returns an iterator that yields account id, account name, and role name.

## `list_assignments`

The Identity Center API only allows you to [list assignments for a specific account _and_ permission set](https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_ListAccountAssignments.html).
To find all your assignments, you need to iterate over all accounts, and then interate over all permission sets.
`list_assignments()` does this work for you.

Unlike the other functions list above, this uses admin APIs, which require AWS credentials, rather than taking as input a start URL and region.

`list_assignments` returns an iterator over `Assignment` named tuples, which have the following fields:

* `instance_arn`
* `principal_type`
* `principal_id`
* `principal_name`
* `permission_set_arn`
* `permission_set_name`
* `target_type`
* `target_id`
* `target_name`

The name fields may be `None`, if the names are not known or looked up.
By default, principal and permission set names are not retrieved, nor are account names for accounts that have been provided as explicit targets.

If you don't specify `instance_arn` and/or `identity_store_id`, these will be looked up using the [ListInstances API](https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_ListInstances.html), which today returns at most one instance (with associated identity store).

An assignment is the combination of a principal (a user or a group), a permission set, and a target (an AWS account).
For each of these values, you can provide either an explicit specification, or a filter function.

You can provide an OU as a target, which will use all accounts in that OU, and optionally all accounts recursively in child OUs as well.

```python
list_assignments(
    session,
    instance_arn=None,
    identity_store_id=None,
    principal=None,
    principal_filter=None,
    permission_set=None,
    permission_set_filter=None,
    target=None,
    target_filter=None,
    get_principal_names=False,
    get_permission_set_names=False,
    get_target_names=False,
    ou_recursive=False)
```

* `session`: [REQUIRED] boto3 session to use
* `instance_arn`: The Identity Center instance to use, or it will be looked up using ListInstances
* `identity_store_id`: The identity store to use if principal names are being retrieved or it will be looked up using ListInstances
* `principal`: A principal specification or list of principal specifications.
    * A principal specification is a principal id or a 2-tuple of principal type and id.
* `principal_filter`: A callable taking principal type, principal id, and principal name (which may be `None`), and returning `True` if the principal should be included.
* `permission_set`: A permission set arn or id, or a list of the same.
* `permission_set_filter`: A callable taking permission set arn and name (name may be `None`), returning True if the permission set should be included.
* `target`: A target specification or list of target specifications.
    * A target specification is an account or OU id, or a 2-tuple of target type, which is either AWS_ACCOUNT or AWS_OU, and target id.
* `target_filter`: A callable taking target type, target id, and target name (which may be `None`), and returning `True` if the target should be included.
* `get_principal_names`: Set to `True` to retrieve names for principals in assignments.
* ` get_permission_set_names`: Set to `True` to retrieve names for permission sets in assignments.
* `get_target_names`: Set to `True` to retrieve names for targets in assignments, when they are explicitly provided as targets. For OUs as targets or if no targets are specified, the account names will be retrieved automatically during the enumeration process.
* `ou_recursive`: Set to `True` if an OU is provided as a target to get all accounts including those in child OUs.
* Returns an iterator over `Assignment` tuples


%package help
Summary:	Development documents and examples for aws-sso-lib
Provides:	python3-aws-sso-lib-doc
%description help
# `aws-sso-lib`

`aws-sso-lib` allows you to programmatically interact with AWS IAM Identity Center (formerly AWS SSO).

The primary functions that will be of interest are available at the package level:
* `get_boto3_session`: Get a boto3 session for a specific account and role.
* `login`: ensure the user is logged in to Identity Center, with dispatch to the browser.
* `list_available_accounts` and `list_available_roles`: discover the access the user has.
* `list_assignments`: for admin purposes, iterate over all assignments in Identity Center, which is currently hard to do through the API.

`aws-sso-util` is a command-line utility built on `aws-sso-lib` for interacting with Identity Center; see the details of that project [here](https://github.com/benkehoe/aws-sso-util).

## Install

```
pip install --user aws-sso-lib
python -c "import aws_sso_lib; aws_sso_lib.login('https://my-start-url.awsapps.com/start', 'us-east-2')"
```

## `get_boto3_session`

Often when writing a script, you know the exact account and role you want the script to use.
You could configure a profile in your `~/.aws/config` for this (perhaps using `aws-sso-util configure profile`), but especially if multiple people may be using the script, it's more convenient to have the configuration baked into the script itself.
`get_boto3_session()` is the function to do that with.

```python
get_boto3_session(start_url, sso_region, account_id, role_name, *, region,
    login=False,
    sso_cache=None,
    credential_cache=None)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `account_id`: [REQUIRED] The AWS account ID to use.
* `role_name`: [REQUIRED] The Identity Center role (aka PermissionSet) name to use.
* `region`: [REQUIRED] The AWS region for the boto3 session (note, required but keyword-only).
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* `sso_cache`: A dict or dict-like object for Identity Center credential caching to replace the default file cache in `~/.aws/sso/cache`.
* `credential_cache`: A dict or dict-like object to cache the role credentials in to replace the default in-memory cache.
* Returns a [boto3 Session object](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) configured for the account and role.

For more control over the login process, use the `login` function separately.

## `login`

While the functions that require the user to be logged in let you specify `login=True` to interactively log in the user if they are not already logged in, you can have more control over the process, or retrieve the access token, using `login()`.

If the user is not logged in or `force_refresh` is `True`, it will attempt to log in.
If the user is logged in and `force_refresh` is `False`, no action is taken.

Normally, it will attempt to automatically open the user's browser to log in, as well as printing the URL and code to stderr as a fallback. However, if `disable_browser` is `True`, or if `disable_browser` is `None` (the default) and the environment variable `AWS_SSO_DISABLE_BROWSER` is set to `1` or `true`, only the message with the URL and code will be printed.

A custom message can be printed by setting `message` to a template string using `{url}` and `{code}` as placeholders.
The message can be suppressed by setting `message` to `False`.

To fully control the communication with the user, use the `user_auth_handler` parameter.
It must be a callable taking four keyword arguments: `verificationUri`, `userCode`, `verificationUriComplete`, and `expiresAt` (a datetime).
Provide `verificationUri` and `userCode` to the user if they are expected to type them in manually (e.g., on a separate device); `verificationUriComplete` has the userCode embedded in it, suitable for copying, linking, or a browser popup.
The function must return promptly or it will block the login process.

```python
login(start_url, sso_region, *,
    force_refresh=False,
    expiry_window=None,
    disable_browser=None,
    message=None,
    outfile=None,
    user_auth_handler=None,
    sso_cache=None)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `force_refresh`: Set to `True` to always go through the authentication process.
* `expiry_window`: A datetime.timedelta (or number of seconds), or callable returning such, specifying the minimum duration any existing token must be valid for.
* `disable_browser`: Set to `True` to skip the browser popup and only print a message with the URL and code.
* `message`: A message template to print with the fallback URL and code, or `False` to suppress the message.
* `outfile`: The file-like object to print the message to (stderr by default)
* `user_auth_handler`: override browser popup and message printing and use the given function instead.
* `sso_cache`: A dict or dict-like object for Identity Center credential caching, to override the default file cache in `~/.aws/sso/cache`.
* Returns the token dict as returned by [sso-oidc:CreateToken](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html), which contains the actual authorization token, as well as the expiration.

## `list_available_accounts` and `list_available_roles`

Identity Center provides programmatic access to the permissions that a user has.
You can access this through `list_available_accounts()` and `list_available_roles()`.

With both, you can set `login=True` to interactively log in the user if they are not already logged in.

Note that these functions return iterators; they don't return a list, because the number of roles may be very large and you shouldn't have to wait for the entire list to be created to start processing.
You can always get a list by, for example, `list(list_available_roles(...))`.

```python
list_available_accounts(start_url, sso_region, *, login=False)
```

* `start_url`: The start URL for the Identity Center instance.
* `sso_region`: The AWS region for the Identity Center instance.
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* Returns an iterator that yields account id and account name.

```python
list_available_roles(start_url, sso_region, account_id=None, *, login=False)
```

* `start_url`: [REQUIRED] The start URL for the Identity Center instance.
* `sso_region`: [REQUIRED] The AWS region for the Identity Center instance.
* `account_id`: Optional account id or list of account ids to check.
  * If not set, all accounts available to the user are used.
* `login`: Set to `True` to interactively log in the user if their Identity Center credentials have expired.
* Returns an iterator that yields account id, account name, and role name.

## `list_assignments`

The Identity Center API only allows you to [list assignments for a specific account _and_ permission set](https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_ListAccountAssignments.html).
To find all your assignments, you need to iterate over all accounts, and then interate over all permission sets.
`list_assignments()` does this work for you.

Unlike the other functions list above, this uses admin APIs, which require AWS credentials, rather than taking as input a start URL and region.

`list_assignments` returns an iterator over `Assignment` named tuples, which have the following fields:

* `instance_arn`
* `principal_type`
* `principal_id`
* `principal_name`
* `permission_set_arn`
* `permission_set_name`
* `target_type`
* `target_id`
* `target_name`

The name fields may be `None`, if the names are not known or looked up.
By default, principal and permission set names are not retrieved, nor are account names for accounts that have been provided as explicit targets.

If you don't specify `instance_arn` and/or `identity_store_id`, these will be looked up using the [ListInstances API](https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_ListInstances.html), which today returns at most one instance (with associated identity store).

An assignment is the combination of a principal (a user or a group), a permission set, and a target (an AWS account).
For each of these values, you can provide either an explicit specification, or a filter function.

You can provide an OU as a target, which will use all accounts in that OU, and optionally all accounts recursively in child OUs as well.

```python
list_assignments(
    session,
    instance_arn=None,
    identity_store_id=None,
    principal=None,
    principal_filter=None,
    permission_set=None,
    permission_set_filter=None,
    target=None,
    target_filter=None,
    get_principal_names=False,
    get_permission_set_names=False,
    get_target_names=False,
    ou_recursive=False)
```

* `session`: [REQUIRED] boto3 session to use
* `instance_arn`: The Identity Center instance to use, or it will be looked up using ListInstances
* `identity_store_id`: The identity store to use if principal names are being retrieved or it will be looked up using ListInstances
* `principal`: A principal specification or list of principal specifications.
    * A principal specification is a principal id or a 2-tuple of principal type and id.
* `principal_filter`: A callable taking principal type, principal id, and principal name (which may be `None`), and returning `True` if the principal should be included.
* `permission_set`: A permission set arn or id, or a list of the same.
* `permission_set_filter`: A callable taking permission set arn and name (name may be `None`), returning True if the permission set should be included.
* `target`: A target specification or list of target specifications.
    * A target specification is an account or OU id, or a 2-tuple of target type, which is either AWS_ACCOUNT or AWS_OU, and target id.
* `target_filter`: A callable taking target type, target id, and target name (which may be `None`), and returning `True` if the target should be included.
* `get_principal_names`: Set to `True` to retrieve names for principals in assignments.
* ` get_permission_set_names`: Set to `True` to retrieve names for permission sets in assignments.
* `get_target_names`: Set to `True` to retrieve names for targets in assignments, when they are explicitly provided as targets. For OUs as targets or if no targets are specified, the account names will be retrieved automatically during the enumeration process.
* `ou_recursive`: Set to `True` if an OU is provided as a target to get all accounts including those in child OUs.
* Returns an iterator over `Assignment` tuples


%prep
%autosetup -n aws-sso-lib-1.14.0

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-aws-sso-lib -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 1.14.0-1
- Package Spec generated