Skip to content

Conversation

@fhacloid
Copy link
Contributor

This PR add support for a URI scheme able to easily fetch any resources from cycloid.

The schema is as follows:

cy://rest/path?param=value

The path must respect the API schema, but some shortcuts has been made to make it easily writable:

cred, credential   -> credentials
project            -> projects
env, environment   -> environments
component          -> components

There are two usecases for this feature:

  1. Interpolate at runtime credentials and more in stack files, mainly ment for kubernetes file created via templating using the cy uri interpolate command.
  2. Fetch any resource from the API, even if the route is not implemented in the CLI using the cy uri get commmand.

The implementation is made as such:

The new package interpolator contains all the logic related to uri interpolation. The logic is decoupled in those components:

  • resources.Reference will parse an URI to extract the path and the parameters in a struct format that will be used by resolvers.
  • resolvers are responsible of fetching the data from a ref. There are one implementation of the interface that is the httpresolver to fetch from the API. Another one that will use mocks for testing will be made.
  • formatters will serialize data in a specified format (json and yaml have been implemented, could also be hcl, ini, whatever). The formatters must return a string. Formatter will parse option parameters whose key match their format name format=option(=value)?), available format and option parsing is implemented here. If any formatter receive a single final value (string, bool, int, etc...) it should return it as a simple string.
  • transformers are function responsible to help the user to transform the text for use in the interpolation. Examples that are already implemented are:
    • lpad: add indentation to the output (replace helm indent filter)
    • nlpad: add a newline before calling lpad (replace helm nindent)
    • base64: encode the output in base64 (useful for kubernetes secrets)

out, err := resolver.Interpolate(uri)
if err != nil {
fmt.Println(err.Error())
err = nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the usecase, but is there a point to resetting the err here to nil? If we need to log potential errors here, we could perhaps collect them to an array and log them in one line before returning the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm still thinking about how to handle errors in this one.

I think I may need to return a list of errors to the caller indeed

Copy link
Contributor Author

@fhacloid fhacloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review @ijozic-cycloid i'll update that this afternoon

out, err := resolver.Interpolate(uri)
if err != nil {
fmt.Println(err.Error())
err = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm still thinking about how to handle errors in this one.

I think I may need to return a list of errors to the caller indeed

@fhacloid fhacloid force-pushed the uri_schema branch 4 times, most recently from 5abbde6 to c8ff142 Compare September 22, 2025 09:02
@ijozic-cycloid ijozic-cycloid self-requested a review September 22, 2025 12:00
@fhacloid fhacloid force-pushed the uri_schema branch 4 times, most recently from 17dd220 to 26e2556 Compare September 30, 2025 10:22
@fhacloid fhacloid marked this pull request as ready for review October 1, 2025 13:54
Copy link
Contributor

@kerak19 kerak19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix all fmt.Errorf to provide errors as %w

@kerak19
Copy link
Contributor

kerak19 commented Oct 2, 2025

rebase

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for a new Cycloid URI schema (cy://) that enables easy fetching and interpolation of resources from the Cycloid API. The implementation introduces runtime interpolation capabilities for stack files and provides a flexible way to access any API resource through URIs with shortcuts and formatting options.

  • Introduces a comprehensive URI interpolation system with resolvers, formatters, and transformers
  • Adds two new CLI commands: cy uri get for direct resource fetching and cy uri interpolate for file processing
  • Implements JSON and YAML formatters with various output options and transformers for text manipulation

Reviewed Changes

Copilot reviewed 65 out of 65 changed files in this pull request and generated 8 comments.

File Description
interpolator/ Core interpolation package with URI parsing, HTTP resolvers, formatters (JSON/YAML), and transformers
cmd/cycloid/uri/ New CLI commands for URI operations including get and interpolate functionality
e2e/uri_test.go End-to-end tests validating URI functionality and interpolation
Various files Code cleanup including error message improvements, import organization, and removal of debug code
Comments suppressed due to low confidence (1)

cmd/cycloid/uri/interpolate.go:1

  • The MarkFlagsMutuallyExclusive call is incomplete - it should specify both flags that are mutually exclusive, not just one flag name.
package uri

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kerak19
Copy link
Contributor

kerak19 commented Oct 2, 2025

Btw I see many backticks weren't applied, no?

@fhacloid fhacloid requested a review from kerak19 October 2, 2025 12:25
@fhacloid fhacloid force-pushed the uri_schema branch 3 times, most recently from f4afaf8 to adb6362 Compare October 2, 2025 21:13
Copy link
Contributor

@kerak19 kerak19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably last thing

@fhacloid fhacloid dismissed ijozic-cycloid’s stale review October 3, 2025 09:32

Outdated and resolved

@fhacloid fhacloid merged commit 2c7ddd7 into develop Oct 3, 2025
1 check passed
@fhacloid fhacloid deleted the uri_schema branch October 3, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants