-
Notifications
You must be signed in to change notification settings - Fork 3
Extended ds download command with specific data structure and version #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Extended ds download command with specific data structure and version #116
Conversation
…d all versions support
| // Validate mutually exclusive flags | ||
| if version != "" && allVersions { | ||
| snplog.LogFatalMsg("validation error", fmt.Errorf("--version and --all-versions are mutually exclusive")) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be expressed with cobra's MarkFlagsMutuallyExclusive
| downloadCmd.PersistentFlags().Bool("plain", false, "Don't include any comments in yaml files") | ||
|
|
||
| // New flags for specific data structure download | ||
| downloadCmd.PersistentFlags().String("vendor", "", "Vendor of the specific data structure to download (requires --name and --format)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requires --name and --format
This should be expressed as MarkFlagsRequiredTogether
|
|
||
| // GenerateDataStructureHash generates a SHA-256 hash for a data structure | ||
| // based on organization ID, vendor, name, and format as per Snowplow API documentation | ||
| func GenerateDataStructureHash(orgId, vendor, name, format string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is correct, but it's done differently on line 426. Either both should use this function, or none
| } | ||
|
|
||
| // Parse the listing response | ||
| var listingResp struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have a struct for this
| dsHash := console.GenerateDataStructureHash(org, vendor, name, formatFlag) | ||
|
|
||
| if allVersions { | ||
| // Download all versions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You could consider removing some of the inline comments—particularly around this code block and line 116 and here. The logic is already quite clear and self-explanatory, so the comments may not be necessary.
| // Set up the command | ||
| cmd.SetArgs(args) | ||
|
|
||
| // Execute the command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same for these comments. thanks!
|
Hi @ivan-afanasiev Could you please describe the use-case that you have for the single version download? Im not against implementing it, but so far this tool was build to assist with git-ops, where your versions would be stored in the git history. I understand that there is a case when you first switch to git and don't have the history, but I don't see how the single version download helps there |
| Short: "Download data structures from BDP Console", | ||
| Args: cobra.MaximumNArgs(1), | ||
| Long: `Downloads the latest versions of all data structures from BDP Console. | ||
| Long: `Downloads data structures from BDP Console. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update any references from "BDP" to just "Console"? We’ve recently completed a rename at Company level. Thanks a lot for your help with this!
|
Thanks for the PR and the effort! Just a suggestion—I’d love to hear your thoughts on trying out a slightly less verbose API and using the flags we have already when possible: |
Hi @gleb-lobov — thanks for the quick review! My use case is a bit different: I'm building a code-generation tool for Snowplow event specifications because Snowtype doesn't match our workflow. Specifications can reference specific versions of events and entities, so I need a way to fetch a single version of a particular data structure so the generator can produce code for that exact schema. While calling the Console API directly is possible, I thought it makes sense to add such kind of functionality into the CLI to simplify our code generator logic. I'm not a Go expert, so please feel free to challenge the implementation and suggest improvements — happy to iterate. Thanks again! |
|
@ivan-afanasiev Thanks for your message. Regarding this point:
In Snowtype, you can target specific data structures (including their exact versions) by defining them in your snowtype.config.json file. For example: {
"dataStructures": [
"xxx/aaa/jsonschema/3-0-1",
"xxx/aaa/jsonschema/3-0-2"
]
}I hope it helps. |
🚀 Add Version-Specific Data Structure Download Functionality
📋 Summary
This PR extends the
snowplow-cli ds downloadcommand with comprehensive version-specific download capabilities, allowing users to download specific versions, all versions, or filter by environment. The implementation includes proper file naming conventions, robust error handling, and maintains full backward compatibility.✨ Features Added
🎯 Core Functionality
🔧 New Command-Line Flags
🎯 Use Cases
1. Download Specific Version
2. Download All Versions
3. Environment-Specific Downloads
# Download only production versions snowplow-cli ds download --vendor com.example --name user --format jsonschema --all-versions --env PROD4. Latest Version (Existing Behavior)
🏗️ Technical Implementation
📁 Files Modified
Core Logic
cmd/ds/download.go: Extended command with new flags and download logicinternal/console/requests_ds.go: Added version-specific API functionsinternal/util/files.go: Enhanced file creation with version namingNew Functions Added
🔄 API Integration
The implementation uses a two-step API approach for reliable version retrieval:
/data-structures/v1/{hash}- Get metadata and deployments/data-structures/v1/schemas/versions- Get actual schema contentThis approach ensures we can retrieve any version, not just the latest, by matching the requested version from the comprehensive versions list.
🎨 Smart File Naming
The system automatically determines when to include version suffixes:
{name}_{version}.{ext}user_2-0-0.yaml{name}_{version}.{ext}user_1-0-0.yaml,user_2-0-0.yaml{name}.{ext}user.yaml{name}.{ext}user.yaml🧪 Comprehensive Testing
📊 Test Coverage
🧪 Test Categories
1. File Operations (
internal/util)2. API Functions (
internal/console)3. Command Logic (
cmd/ds)🔧 Test Features
🛡️ Error Handling & Validation
✅ Input Validation
--versionand--all-versionscannot be used together--vendor,--name, and--formatmust be provided together--envaccepts only DEV/PROD values🚨 Error Scenarios Handled
📝 User-Friendly Messages
🔄 Backward Compatibility
✅ Existing Functionality Preserved
📝 Documentation Updates
📖 Help Text Enhanced