docs: Update 3 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 53s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m34s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 6s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 7s
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 53s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m34s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 6s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 7s
This commit is contained in:
325
.kiro/specs/multi-server-support/design.md
Normal file
325
.kiro/specs/multi-server-support/design.md
Normal file
@ -0,0 +1,325 @@
|
||||
# Design Document
|
||||
|
||||
## Overview
|
||||
|
||||
This design extends getpkg to support multiple package servers while maintaining full backward compatibility. The solution introduces a server configuration system, updates the client architecture to handle multiple servers, and reorganizes package metadata storage. The design prioritizes minimal disruption to existing functionality while providing powerful multi-server capabilities.
|
||||
|
||||
## Architecture
|
||||
|
||||
### High-Level Architecture
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
CLI[CLI Commands] --> SM[ServerManager]
|
||||
CLI --> PM[PackageManager]
|
||||
PM --> SM
|
||||
PM --> GC[GetbinClient]
|
||||
SM --> CF[servers.json]
|
||||
PM --> PF[packages/*.json]
|
||||
GC --> S1[Server 1]
|
||||
GC --> S2[Server 2]
|
||||
GC --> SN[Server N]
|
||||
```
|
||||
|
||||
### Server Management Flow
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User
|
||||
participant CLI
|
||||
participant ServerManager
|
||||
participant Config
|
||||
|
||||
User->>CLI: getpkg server add example.com
|
||||
CLI->>ServerManager: addServer("example.com")
|
||||
ServerManager->>Config: load servers.json
|
||||
ServerManager->>ServerManager: validate URL
|
||||
ServerManager->>Config: save updated servers.json
|
||||
ServerManager->>CLI: success confirmation
|
||||
CLI->>User: Server added successfully
|
||||
```
|
||||
|
||||
### Package Installation Flow
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User
|
||||
participant CLI
|
||||
participant PackageManager
|
||||
participant GetbinClient
|
||||
participant Server1
|
||||
participant Server2
|
||||
|
||||
User->>CLI: getpkg install tool
|
||||
CLI->>PackageManager: install("tool")
|
||||
PackageManager->>GetbinClient: download("tool", servers[0])
|
||||
GetbinClient->>Server1: GET /object/tool:arch
|
||||
alt Package found
|
||||
Server1-->>GetbinClient: 200 + package data
|
||||
GetbinClient-->>PackageManager: success
|
||||
else Package not found
|
||||
Server1-->>GetbinClient: 404
|
||||
GetbinClient->>Server2: GET /object/tool:arch
|
||||
Server2-->>GetbinClient: 200 + package data
|
||||
GetbinClient-->>PackageManager: success
|
||||
end
|
||||
PackageManager->>PackageManager: install package
|
||||
PackageManager->>CLI: installation complete
|
||||
```
|
||||
|
||||
## Components and Interfaces
|
||||
|
||||
### ServerManager Class
|
||||
|
||||
**Purpose**: Manages server configuration, write tokens, and provides server list to other components.
|
||||
|
||||
**Interface**:
|
||||
```cpp
|
||||
class ServerManager {
|
||||
public:
|
||||
ServerManager();
|
||||
|
||||
// Server management
|
||||
bool addServer(const std::string& serverUrl, const std::string& writeToken = "");
|
||||
bool removeServer(const std::string& serverUrl);
|
||||
std::vector<std::string> getServers() const;
|
||||
std::string getDefaultServer() const;
|
||||
std::string getDefaultPublishServer() const; // First server with write token
|
||||
|
||||
// Token management
|
||||
bool setWriteToken(const std::string& serverUrl, const std::string& token);
|
||||
std::string getWriteToken(const std::string& serverUrl) const;
|
||||
bool hasWriteToken(const std::string& serverUrl) const;
|
||||
std::vector<std::string> getServersWithTokens() const;
|
||||
|
||||
// Configuration
|
||||
bool loadConfiguration();
|
||||
bool saveConfiguration();
|
||||
void ensureDefaultConfiguration();
|
||||
|
||||
// Migration
|
||||
bool migrateFromLegacy();
|
||||
|
||||
private:
|
||||
std::vector<ServerConfig> servers_;
|
||||
std::filesystem::path configPath_;
|
||||
|
||||
bool validateServerUrl(const std::string& url) const;
|
||||
bool isServerReachable(const std::string& url) const;
|
||||
ServerConfig* findServer(const std::string& url);
|
||||
};
|
||||
```
|
||||
|
||||
### Enhanced GetbinClient Class
|
||||
|
||||
**Purpose**: Extended to support multiple servers with fallback logic.
|
||||
|
||||
**Interface Changes**:
|
||||
```cpp
|
||||
class GetbinClient {
|
||||
public:
|
||||
GetbinClient(const std::vector<std::string>& servers);
|
||||
|
||||
// Existing methods with server selection
|
||||
bool download(const std::string& toolName, const std::string& arch,
|
||||
const std::string& outPath, ProgressCallback progressCallback = nullptr);
|
||||
bool downloadFromServer(const std::string& serverUrl, const std::string& toolName,
|
||||
const std::string& arch, const std::string& outPath,
|
||||
ProgressCallback progressCallback = nullptr);
|
||||
|
||||
// Server-specific operations
|
||||
bool upload(const std::string& serverUrl, const std::string& archivePath,
|
||||
std::string& outUrl, std::string& outHash, const std::string& token,
|
||||
ProgressCallback progressCallback = nullptr);
|
||||
bool getHash(const std::string& serverUrl, const std::string& toolName,
|
||||
const std::string& arch, std::string& outHash);
|
||||
|
||||
// Multi-server operations
|
||||
bool findPackageServer(const std::string& toolName, const std::string& arch,
|
||||
std::string& foundServer) const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> servers_;
|
||||
std::string buildUrl(const std::string& serverUrl, const std::string& endpoint) const;
|
||||
};
|
||||
```
|
||||
|
||||
### PackageMetadata Structure
|
||||
|
||||
**Purpose**: Enhanced metadata structure to track server source.
|
||||
|
||||
**Structure**:
|
||||
```cpp
|
||||
struct PackageMetadata {
|
||||
std::string name;
|
||||
std::string version;
|
||||
std::string hash;
|
||||
std::string arch;
|
||||
std::string sourceServer; // New field
|
||||
std::string installDate; // New field for better tracking
|
||||
|
||||
// Serialization
|
||||
nlohmann::json toJson() const;
|
||||
static PackageMetadata fromJson(const nlohmann::json& j);
|
||||
|
||||
// Migration support
|
||||
static PackageMetadata fromLegacyJson(const nlohmann::json& j, const std::string& defaultServer);
|
||||
};
|
||||
```
|
||||
|
||||
### Migration Manager
|
||||
|
||||
**Purpose**: Handles migration from single-server to multi-server configuration.
|
||||
|
||||
**Interface**:
|
||||
```cpp
|
||||
class MigrationManager {
|
||||
public:
|
||||
MigrationManager();
|
||||
|
||||
bool needsMigration() const;
|
||||
bool performMigration();
|
||||
|
||||
private:
|
||||
bool migrateServerConfiguration();
|
||||
bool migratePackageMetadata();
|
||||
bool movePackageFiles();
|
||||
bool updatePackageMetadata();
|
||||
|
||||
std::filesystem::path oldConfigDir_;
|
||||
std::filesystem::path newConfigDir_;
|
||||
std::filesystem::path packagesDir_;
|
||||
};
|
||||
```
|
||||
|
||||
## Data Models
|
||||
|
||||
### Server Configuration Format
|
||||
|
||||
**File**: `~/.config/getpkg/servers.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "1.0",
|
||||
"servers": [
|
||||
{
|
||||
"url": "getpkg.xyz",
|
||||
"name": "Official getpkg Registry",
|
||||
"default": true,
|
||||
"writeToken": "",
|
||||
"added": "2024-01-15T10:30:00Z"
|
||||
},
|
||||
{
|
||||
"url": "packages.example.com",
|
||||
"name": "Example Corporate Registry",
|
||||
"default": false,
|
||||
"writeToken": "abc123token456",
|
||||
"added": "2024-01-16T14:20:00Z"
|
||||
}
|
||||
],
|
||||
"lastUpdated": "2024-01-16T14:20:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
### Enhanced Package Metadata Format
|
||||
|
||||
**File**: `~/.config/getpkg/packages/<tool_name>.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "example-tool",
|
||||
"version": "2024.0115.1430",
|
||||
"hash": "1234567890123456",
|
||||
"arch": "x86_64",
|
||||
"sourceServer": "getpkg.xyz",
|
||||
"installDate": "2024-01-15T14:30:00Z",
|
||||
"lastUpdated": "2024-01-15T14:30:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
### Directory Structure Changes
|
||||
|
||||
```
|
||||
~/.config/getpkg/
|
||||
├── servers.json # New: Server configuration with embedded tokens
|
||||
├── packages/ # New: Package metadata directory
|
||||
│ ├── tool1.json
|
||||
│ ├── tool2.json
|
||||
│ └── ...
|
||||
└── getpkg.xyz/ # Legacy: Will be migrated to servers.json
|
||||
└── write_token.txt # Legacy: Will be migrated
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Server Connectivity Issues
|
||||
|
||||
1. **Network Failures**: Graceful fallback to next server in list
|
||||
2. **Invalid Responses**: Clear error messages with server identification
|
||||
3. **Authentication Failures**: Server-specific error handling with token guidance
|
||||
|
||||
### Configuration Corruption
|
||||
|
||||
1. **Invalid JSON**: Automatic backup and reset to default configuration
|
||||
2. **Missing Files**: Automatic creation with default settings
|
||||
3. **Permission Issues**: Clear error messages with resolution steps
|
||||
|
||||
### Migration Failures
|
||||
|
||||
1. **Partial Migration**: Rollback capability with clear status reporting
|
||||
2. **File Conflicts**: Safe handling with backup creation
|
||||
3. **Metadata Corruption**: Individual file recovery without breaking entire system
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit Tests
|
||||
|
||||
1. **ServerManager**: Configuration loading, validation, server management
|
||||
2. **GetbinClient**: Multi-server communication, fallback logic
|
||||
3. **PackageMetadata**: Serialization, migration, validation
|
||||
4. **MigrationManager**: Legacy data handling, file operations
|
||||
|
||||
### Integration Tests
|
||||
|
||||
1. **End-to-End Installation**: Multi-server package discovery and installation
|
||||
2. **Server Management**: Add/remove servers with real configuration
|
||||
3. **Migration Testing**: Legacy to new format conversion
|
||||
4. **Publish/Unpublish**: Server-specific operations
|
||||
|
||||
### Compatibility Tests
|
||||
|
||||
1. **Backward Compatibility**: Existing installations continue working
|
||||
2. **Legacy Format**: Old package files are properly migrated
|
||||
3. **Default Behavior**: No configuration changes for existing users
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
### Phase 1: Core Infrastructure
|
||||
- Implement ServerManager class
|
||||
- Create server configuration format
|
||||
- Add basic server validation
|
||||
|
||||
### Phase 2: Client Enhancement
|
||||
- Extend GetbinClient for multi-server support
|
||||
- Implement fallback logic
|
||||
- Add server-specific operations
|
||||
|
||||
### Phase 3: Package Management
|
||||
- Update package metadata format
|
||||
- Implement packages directory structure
|
||||
- Add server tracking to installations
|
||||
|
||||
### Phase 4: Migration System
|
||||
- Create MigrationManager
|
||||
- Implement automatic migration
|
||||
- Add backward compatibility layer
|
||||
|
||||
### Phase 5: CLI Integration
|
||||
- Add server management commands
|
||||
- Update existing commands for multi-server
|
||||
- Implement server selection options
|
||||
|
||||
### Phase 6: Testing and Polish
|
||||
- Comprehensive testing suite
|
||||
- Error handling refinement
|
||||
- Documentation updates
|
79
.kiro/specs/multi-server-support/requirements.md
Normal file
79
.kiro/specs/multi-server-support/requirements.md
Normal file
@ -0,0 +1,79 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
This feature extends getpkg to support multiple package servers instead of being limited to only getpkg.xyz. Users will be able to add and remove package servers, with getpkg searching across all configured servers to find packages. The system will maintain backward compatibility while providing flexible server management capabilities.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1
|
||||
|
||||
**User Story:** As a developer, I want to configure multiple package servers, so that I can access packages from different repositories and have redundancy in case one server is unavailable.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN I run `getpkg server add <server_url>` THEN the system SHALL add the server to the configuration and confirm the addition
|
||||
2. WHEN I run `getpkg server remove <server_url>` THEN the system SHALL remove the server from the configuration and confirm the removal
|
||||
3. WHEN I run `getpkg server list` THEN the system SHALL display all configured servers in the order they were added
|
||||
4. WHEN no servers are configured THEN the system SHALL default to using getpkg.xyz as the primary server
|
||||
5. WHEN I add the first custom server THEN getpkg.xyz SHALL remain as the default first server unless explicitly removed
|
||||
|
||||
### Requirement 2
|
||||
|
||||
**User Story:** As a user, I want getpkg to search across all configured servers when installing packages, so that I can access packages from any of my configured repositories.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN I run `getpkg install <tool_name>` THEN the system SHALL search servers in the order they were configured
|
||||
2. WHEN a package is found on the first server THEN the system SHALL install from that server and not check remaining servers
|
||||
3. WHEN a package is not found on the first server THEN the system SHALL try the next server in order
|
||||
4. WHEN a package is not found on any server THEN the system SHALL report that the package was not found
|
||||
5. WHEN checking for updates THEN the system SHALL use the same server where the package was originally installed
|
||||
|
||||
### Requirement 3
|
||||
|
||||
**User Story:** As a package publisher, I want to specify which server to publish to and manage write tokens per server, so that I can control where my packages are distributed and authenticate appropriately.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN I run `getpkg publish <tool_name> <folder>` without specifying a server THEN the system SHALL publish to the first configured server that has a write token
|
||||
2. WHEN I run `getpkg publish --server <server_url> <tool_name> <folder>` THEN the system SHALL publish to the specified server using its stored write token
|
||||
3. WHEN I run `getpkg unpublish <tool_name>` without specifying a server THEN the system SHALL unpublish from the first configured server that has a write token
|
||||
4. WHEN I run `getpkg unpublish --server <server_url> <tool_name>` THEN the system SHALL unpublish from the specified server using its stored write token
|
||||
5. WHEN no servers have write tokens THEN the system SHALL report an error and suggest adding a write token to a server
|
||||
|
||||
### Requirement 4
|
||||
|
||||
**User Story:** As a user, I want my package metadata to be organized by server, so that I can track which packages came from which servers and manage them appropriately.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a package is installed THEN the system SHALL store the package metadata in `~/.config/getpkg/packages/<tool_name>.json`
|
||||
2. WHEN package metadata is stored THEN it SHALL include the source server URL in addition to existing fields
|
||||
3. WHEN the packages directory doesn't exist THEN the system SHALL create it automatically
|
||||
4. WHEN migrating from the old format THEN existing package JSON files SHALL be moved to the packages subdirectory
|
||||
5. WHEN migrating from the old format THEN existing package metadata SHALL be updated to include getpkg.xyz as the source server
|
||||
|
||||
### Requirement 5
|
||||
|
||||
**User Story:** As a user, I want server configuration to be persistent and secure, so that my settings are maintained across sessions and my authentication tokens are protected.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN server configuration is modified THEN it SHALL be stored in `~/.config/getpkg/servers.json`
|
||||
2. WHEN the configuration file doesn't exist THEN the system SHALL create it with getpkg.xyz as the default server
|
||||
3. WHEN reading server configuration THEN the system SHALL validate the JSON format and handle corruption gracefully
|
||||
4. WHEN a server URL is invalid THEN the system SHALL reject the addition and provide a helpful error message
|
||||
5. WHEN authentication tokens are needed THEN they SHALL continue to be stored per-server in the existing location pattern
|
||||
|
||||
### Requirement 6
|
||||
|
||||
**User Story:** As a user, I want the multi-server functionality to be backward compatible, so that existing installations continue to work without modification.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN getpkg starts with no server configuration THEN it SHALL automatically configure getpkg.xyz as the default server
|
||||
2. WHEN existing package JSON files are found in `~/.config/getpkg/` THEN they SHALL be automatically migrated to the packages subdirectory
|
||||
3. WHEN migrated package files are processed THEN they SHALL be updated to include server source information
|
||||
4. WHEN all existing functionality is used THEN it SHALL work exactly as before for users who don't configure additional servers
|
||||
5. WHEN the migration process fails THEN the system SHALL provide clear error messages and not break existing functionality
|
94
.kiro/specs/multi-server-support/tasks.md
Normal file
94
.kiro/specs/multi-server-support/tasks.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Implementation Plan
|
||||
|
||||
Based on analysis of the current codebase, the multi-server support feature needs to be built from scratch. The current implementation has a hardcoded `SERVER_HOST = "getpkg.xyz"` in `GetbinClient` and no server management infrastructure.
|
||||
|
||||
## Core Infrastructure Tasks
|
||||
|
||||
- [-] 1. Create ServerManager class and server configuration system
|
||||
|
||||
|
||||
|
||||
- Implement ServerManager class with server add/remove/list functionality
|
||||
- Create server configuration JSON format and file handling
|
||||
- Add server URL validation and reachability checks
|
||||
- Implement write token management per server
|
||||
- _Requirements: 1.1, 1.2, 1.3, 5.1, 5.2, 5.4_
|
||||
|
||||
- [ ] 2. Enhance GetbinClient for multi-server support
|
||||
- Modify GetbinClient constructor to accept server list instead of hardcoded host
|
||||
- Implement multi-server fallback logic for downloads
|
||||
- Add server-specific upload and hash operations
|
||||
- Create findPackageServer method for package discovery
|
||||
- _Requirements: 2.1, 2.2, 2.3, 2.4_
|
||||
|
||||
- [ ] 3. Create enhanced package metadata system
|
||||
- Design PackageMetadata structure with server source tracking
|
||||
- Implement packages directory structure (~/.config/getpkg/packages/)
|
||||
- Add JSON serialization/deserialization for enhanced metadata
|
||||
- Create package metadata validation and error handling
|
||||
- _Requirements: 4.1, 4.2, 4.3_
|
||||
|
||||
## Migration and Compatibility Tasks
|
||||
|
||||
- [ ] 4. Implement migration system for existing installations
|
||||
- Create MigrationManager class for legacy data handling
|
||||
- Implement automatic migration from single-server to multi-server config
|
||||
- Migrate existing package JSON files to packages subdirectory
|
||||
- Update existing package metadata to include server source information
|
||||
- Add migration error handling and rollback capabilities
|
||||
- _Requirements: 4.4, 4.5, 6.1, 6.2, 6.3, 6.5_
|
||||
|
||||
- [ ] 5. Ensure backward compatibility
|
||||
- Implement default server configuration (getpkg.xyz) when no config exists
|
||||
- Maintain existing CLI behavior for users without custom server configuration
|
||||
- Preserve existing token storage location compatibility
|
||||
- Add graceful handling of missing or corrupted configuration files
|
||||
- _Requirements: 6.1, 6.4, 5.3_
|
||||
|
||||
## CLI Integration Tasks
|
||||
|
||||
- [ ] 6. Add server management commands to main.cpp
|
||||
- Implement `getpkg server add <url>` command
|
||||
- Implement `getpkg server remove <url>` command
|
||||
- Implement `getpkg server list` command
|
||||
- Add server URL validation and user feedback
|
||||
- _Requirements: 1.1, 1.2, 1.3_
|
||||
|
||||
- [ ] 7. Update existing commands for multi-server support
|
||||
- Modify install command to use ServerManager and multi-server GetbinClient
|
||||
- Update publish command to support --server option and default server selection
|
||||
- Update unpublish command to support --server option and default server selection
|
||||
- Ensure update command works with multi-server package tracking
|
||||
- _Requirements: 2.1, 2.2, 2.3, 2.4, 3.1, 3.2, 3.3, 3.4, 3.5_
|
||||
|
||||
## Integration and Testing Tasks
|
||||
|
||||
- [ ] 8. Integrate all components in main application flow
|
||||
- Initialize ServerManager in main.cpp startup
|
||||
- Trigger migration process on first run with new version
|
||||
- Update package installation flow to use enhanced metadata
|
||||
- Ensure proper error handling and user messaging throughout
|
||||
- _Requirements: 6.1, 6.2, 6.3, 6.4, 6.5_
|
||||
|
||||
- [ ] 9. Add comprehensive error handling and validation
|
||||
- Implement network error handling with server fallback
|
||||
- Add configuration file corruption recovery
|
||||
- Create user-friendly error messages for server connectivity issues
|
||||
- Add validation for server URLs and authentication tokens
|
||||
- _Requirements: 5.3, 5.4, 5.5_
|
||||
|
||||
- [ ] 10. Create unit tests for new components
|
||||
- Write unit tests for ServerManager class functionality
|
||||
- Test GetbinClient multi-server operations and fallback logic
|
||||
- Test PackageMetadata serialization and migration
|
||||
- Test MigrationManager with various legacy data scenarios
|
||||
- Create integration tests for complete multi-server workflows
|
||||
- _Requirements: All requirements validation_
|
||||
|
||||
## Notes
|
||||
|
||||
- Current codebase has `SERVER_HOST = "getpkg.xyz"` hardcoded in GetbinClient.cpp
|
||||
- No existing server management or configuration infrastructure
|
||||
- Package metadata is currently stored as individual JSON files in ~/.config/getpkg/
|
||||
- Token storage is in ~/.config/getpkg.xyz/write_token.txt (legacy format)
|
||||
- All functionality needs to be built from scratch while maintaining backward compatibility
|
Reference in New Issue
Block a user