Files
FitTrack_GarminSync/specs/006-cli-auth-sync-mfa/tasks.md
sstent fb6417b1a3 Implement CLI app for API interaction with MFA
- Create full CLI application with authentication, sync triggering, and status checking
- Implement MFA support for secure authentication
- Add token management with secure local storage
- Create API client for backend communication
- Implement data models for User Session, Sync Job, and Authentication Token
- Add command-line interface with auth and sync commands
- Include unit and integration tests
- Follow project constitution standards for Python 3.13, type hints, and code quality
- Support multiple output formats (table, JSON, CSV)
2025-12-18 15:23:56 -08:00

134 lines
7.7 KiB
Markdown

# Tasks: CLI App for API Interaction with MFA
**Branch**: `006-cli-auth-sync-mfa` | **Date**: Thursday, December 18, 2025 | **Spec**: /home/sstent/Projects/FitTrack/GarminSync/specs/006-cli-auth-sync-mfa/spec.md
## Summary
This plan outlines the implementation of a text-based command-line interface that allows users to authenticate with the API (with MFA support), trigger sync operations, and check sync status. The implementation follows the project's constitution standards using Python 3.13 with appropriate libraries for CLI interface, authentication, and API communication.
## Phase 1: Setup Tasks (Project Initialization)
- [x] T001 Create project structure in cli/ directory following implementation plan
- [x] T002 Set up Python 3.13 virtual environment and install required dependencies (Click, httpx, pydantic, pytest)
- [x] T003 Create requirements.txt with pinned dependencies following constitution standards
- [x] T004 Create pyproject.toml with Black, Flake8, Mypy, Isort configurations
- [x] T005 [P] Create initial directory structure (src/, models/, services/, commands/, utils/, tests/)
## Phase 2: Foundational Tasks (Blocking Prerequisites)
- [x] T006 Create base data models for User Session, Sync Job, and Authentication Token
- [x] T007 [P] Implement API client to interact with backend API endpoints
- [x] T008 [P] Create configuration management utilities for YAML config
- [x] T009 [P] Implement token management with secure local storage
- [x] T010 Create output formatting utilities (JSON, table, CSV)
- [x] T011 [P] Implement CLI entry point with base command structure
## Phase 3: User Story 1 - Text-Based Authentication with MFA (Priority: P1) 🎯 MVP
**Goal**: Implement authentication functionality via text-based interface with MFA support so users can securely access the system.
**Independent Test**: Can be fully tested by running the authentication command with both standard credentials and MFA-enabled accounts, and verifying the system properly validates credentials and handles MFA flows.
### Implementation for User Story 1
- [x] T012 [US1] Create AuthManager class to handle authentication flows with MFA support
- [x] T013 [US1] Implement MFA handling functionality in AuthManager
- [x] T014 [US1] Create authentication command implementation in commands/auth_cmd.py
- [x] T015 [US1] Add interactive authentication mode with secure input prompts
- [x] T016 [US1] Implement token validation and refresh logic
- [x] T017 [US1] Add error handling for authentication failures
- [x] T018 [US1] [P] Write unit tests for authentication manager
- [x] T019 [US1] [P] Write integration tests for authentication flows
**Checkpoint**: At this point, users should be able to authenticate via CLI with and without MFA.
## Phase 4: User Story 2 - Trigger Sync Operations via Text Interface (Priority: P2)
**Goal**: Implement functionality to trigger sync operations from text-based interface so users can initiate data synchronization without using the web interface.
**Independent Test**: Can be fully tested by authenticating and then running the sync trigger command, and verifying that the sync process is initiated in the backend system.
### Implementation for User Story 2
- [x] T020 [US2] Create SyncCommand class to handle sync triggering functionality
- [x] T021 [US2] Implement sync trigger API call functionality
- [x] T022 [US2] Add support for different sync types (activities, health, workouts)
- [x] T023 [US2] Implement date range and full sync options
- [x] T024 [US2] Add authentication validation before sync triggers
- [x] T025 [US2] Handle sync conflict detection (concurrent sync requests)
- [x] T026 [US2] [P] Write unit tests for sync command functionality
- [x] T027 [US2] [P] Write integration tests for sync triggering
**Checkpoint**: At this point, users should be able to authenticate and trigger sync operations via CLI.
## Phase 5: User Story 3 - Check Sync Status via Text Interface (Priority: P3)
**Goal**: Implement functionality to check sync operation status from text-based interface so users can monitor data synchronization progress.
**Independent Test**: Can be fully tested by triggering a sync and then checking its status via the text interface, with various sync states being properly reported.
### Implementation for User Story 3
- [x] T028 [US3] Create StatusCommand class to handle sync status checking
- [x] T029 [US3] Implement sync status API call functionality
- [x] T030 [US3] Add support for retrieving specific job status by ID
- [x] T031 [US3] Format status output in multiple formats (table, JSON, CSV)
- [x] T032 [US3] Handle status requests for non-existent sync jobs
- [x] T033 [US3] [P] Write unit tests for status command functionality
- [x] T034 [US3] [P] Write integration tests for status checking
**Checkpoint**: At this point, users should be able to authenticate, trigger syncs, and check sync status via CLI.
## Final Phase: Polish & Cross-Cutting Concerns
- [x] T035 Implement comprehensive error handling and user-friendly messages (FR-007)
- [x] T036 Add token expiration and refresh automation (FR-008)
- [x] T037 Implement secure credential storage with appropriate file permissions (FR-005)
- [x] T038 Add support for non-interactive (scriptable) authentication mode (FR-006)
- [x] T039 Implement all output formats (table, JSON, CSV) consistently across commands
- [x] T040 Add command-line help text and documentation
- [x] T041 Run project linters (Black, Flake8, Mypy, Isort) and fix issues
- [x] T042 Run all unit and integration tests to ensure no regressions
- [x] T043 Verify all functional requirements from spec are met (FR-001 through FR-008)
- [x] T044 Update quickstart guide with actual implementation details
## Dependencies & Execution Order
### Phase Dependencies
- **Setup (Phase 1)**: No dependencies.
- **Foundational (Phase 2)**: Depends on Setup completion.
- **User Story 1 (Phase 3)**: Depends on Setup and Foundational completion.
- **User Story 2 (Phase 4)**: Depends on User Story 1 completion (requires authentication).
- **User Story 3 (Phase 5)**: Depends on User Story 1 completion (requires authentication).
- **Polish (Final Phase)**: Depends on all user stories being complete.
### User Story Dependencies
- **User Story 1 (P1)**: No dependencies on other stories (MVP).
- **User Story 2 (P2)**: Depends on User Story 1 completion (needs authentication).
- **User Story 3 (P3)**: Depends on User Story 1 completion (needs authentication).
- **User Stories 2 and 3** are independent of each other and can potentially be developed in parallel after US1 completion.
### Within Each User Story
- Tasks within each user story should generally be executed sequentially, unless marked [P] for parallel.
### Parallel Opportunities
- Tasks within different user stories can run in parallel if they work with different modules (e.g., US2 and US3 development after US1).
- Test tasks [P] can run in parallel with implementation tasks in the same user story.
- Multiple API client implementations can run in parallel [P].
## Implementation Strategy
We will follow an incremental delivery approach, starting with User Story 1 (authentication) as the MVP. This will provide a functional CLI that users can authenticate with, even before sync functionality is implemented.
The implementation will prioritize security considerations (secure token storage, proper MFA handling) and user experience (clear feedback messages, appropriate error handling) throughout all phases.
## Test Strategy
- Unit tests will be implemented alongside functionality (TDD approach)
- Integration tests will verify complete flows within each user story
- Contract tests will verify API interactions align with defined contracts
- Security tests will validate proper credential handling