List available Leap projects.
(*, config_file, profile, json_output, output)
| 1138 | @json_output |
| 1139 | @standardized_output |
| 1140 | def list_leap_projects(*, config_file, profile, json_output, output): |
| 1141 | """List available Leap projects.""" |
| 1142 | |
| 1143 | config = validate_config_v1(load_config(config_file=config_file, profile=profile)) |
| 1144 | |
| 1145 | with LeapAuthFlow.from_config_model(config) as flow: |
| 1146 | if not flow.token or 'access_token' not in flow.token: |
| 1147 | raise CLIError('Leap API access token not found. Please run "dwave auth login".', code=100) |
| 1148 | |
| 1149 | if flow.token_expires_soon(within=60): |
| 1150 | output("Access token expired (or expires soon), refreshing it.") |
| 1151 | flow.refresh_token() |
| 1152 | |
| 1153 | with api.LeapAccount.from_config(config=flow.config, |
| 1154 | token=flow.token.get('access_token')) as account: |
| 1155 | projects = account.list_projects() |
| 1156 | output("Leap projects:", projects=[p.model_dump() for p in projects]) |
| 1157 | for project in projects: |
| 1158 | output(f" - {project.name} (code={project.code!r}, id={project.id})") |
| 1159 | |
| 1160 | |
| 1161 | @project.command(name='token') |
nothing calls this directly
no test coverage detected