|
14 | 14 |
|
15 | 15 |
|
16 | 16 | def _get_cycode_client( |
17 | | - create_client_func: callable, client_id: Optional[str], client_secret: Optional[str], hide_response_log: bool |
| 17 | + create_client_func: callable, |
| 18 | + client_id: Optional[str], |
| 19 | + client_secret: Optional[str], |
| 20 | + hide_response_log: bool, |
| 21 | + id_token: Optional[str] = None, |
18 | 22 | ) -> Union['ScanClient', 'ReportClient']: |
| 23 | + if client_id and id_token: |
| 24 | + return create_client_func(client_id, None, hide_response_log, id_token) |
| 25 | + |
| 26 | + if not client_id or not id_token: |
| 27 | + oidc_client_id, oidc_id_token = _get_configured_oidc_credentials() |
| 28 | + if oidc_client_id and oidc_id_token: |
| 29 | + return create_client_func(oidc_client_id, None, hide_response_log, oidc_id_token) |
| 30 | + if oidc_id_token and not oidc_client_id: |
| 31 | + raise click.ClickException('Cycode client id needed for OIDC authentication.') |
| 32 | + |
19 | 33 | if not client_id or not client_secret: |
20 | 34 | client_id, client_secret = _get_configured_credentials() |
21 | 35 | if not client_id: |
22 | 36 | raise click.ClickException('Cycode client id needed.') |
23 | 37 | if not client_secret: |
24 | 38 | raise click.ClickException('Cycode client secret is needed.') |
25 | 39 |
|
26 | | - return create_client_func(client_id, client_secret, hide_response_log) |
| 40 | + return create_client_func(client_id, client_secret, hide_response_log, None) |
27 | 41 |
|
28 | 42 |
|
29 | 43 | def get_scan_cycode_client(ctx: 'typer.Context') -> 'ScanClient': |
30 | 44 | client_id = ctx.obj.get('client_id') |
31 | 45 | client_secret = ctx.obj.get('client_secret') |
| 46 | + id_token = ctx.obj.get('id_token') |
32 | 47 | hide_response_log = not ctx.obj.get('show_secret', False) |
33 | | - return _get_cycode_client(create_scan_client, client_id, client_secret, hide_response_log) |
| 48 | + return _get_cycode_client(create_scan_client, client_id, client_secret, hide_response_log, id_token) |
34 | 49 |
|
35 | 50 |
|
36 | 51 | def get_report_cycode_client(ctx: 'typer.Context', hide_response_log: bool = True) -> 'ReportClient': |
37 | 52 | client_id = ctx.obj.get('client_id') |
38 | 53 | client_secret = ctx.obj.get('client_secret') |
39 | | - return _get_cycode_client(create_report_client, client_id, client_secret, hide_response_log) |
| 54 | + id_token = ctx.obj.get('id_token') |
| 55 | + return _get_cycode_client(create_report_client, client_id, client_secret, hide_response_log, id_token) |
40 | 56 |
|
41 | 57 |
|
42 | 58 | def get_import_sbom_cycode_client(ctx: 'typer.Context', hide_response_log: bool = True) -> 'ImportSbomClient': |
43 | 59 | client_id = ctx.obj.get('client_id') |
44 | 60 | client_secret = ctx.obj.get('client_secret') |
45 | | - return _get_cycode_client(create_import_sbom_client, client_id, client_secret, hide_response_log) |
| 61 | + id_token = ctx.obj.get('id_token') |
| 62 | + return _get_cycode_client(create_import_sbom_client, client_id, client_secret, hide_response_log, id_token) |
46 | 63 |
|
47 | 64 |
|
48 | 65 | def _get_configured_credentials() -> tuple[str, str]: |
49 | 66 | credentials_manager = CredentialsManager() |
50 | 67 | return credentials_manager.get_credentials() |
| 68 | + |
| 69 | + |
| 70 | +def _get_configured_oidc_credentials() -> tuple[Optional[str], Optional[str]]: |
| 71 | + credentials_manager = CredentialsManager() |
| 72 | + return credentials_manager.get_oidc_credentials() |
0 commit comments