Skip to content
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

Allow simple string replace #124

Closed
applike-ss opened this issue May 28, 2024 · 5 comments
Closed

Allow simple string replace #124

applike-ss opened this issue May 28, 2024 · 5 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed new transform

Comments

@applike-ss
Copy link

As per this comment: crossplane/crossplane#3025 (comment) i assume that this is the right place to post this request.

I would like to see a simple string replacement implementation, that could be used like this:

  - type: CombineFromComposite
    combine:
      variables:
        - fromFieldPath: status.availability
        - fromFieldPath: spec.claimRef.namespace
        - fromFieldPath: spec.parameters.name
      strategy: string
      string:
        fmt: "%s.%s.%s"
        replace:
          search: 'public'
          replace: 'pub'
    toFieldPath: spec.forProvider.topic.name 

Originally taken from: crossplane/crossplane#3026 but slightly adjusted.

The code snippet is just a rough example and may not be perfectly matching how inputs for the function should be specified.

@negz negz added help wanted Extra attention is needed good first issue Good for newcomers new transform labels May 31, 2024
@gschei
Copy link
Contributor

gschei commented Jul 21, 2024

I think the right way to solve this would be to add a string-transform of type "replace". It would follow the P&T concept of

  • first using different type of patches
  • then using different type of transforms
    so it could be applied to FromCompositeFieldPath as well. Here would be a revisited example:
  - type: CombineFromComposite
    combine:
      variables:
        - fromFieldPath: status.availability
        - fromFieldPath: spec.claimRef.namespace
        - fromFieldPath: spec.parameters.name
      strategy: string
      string:
        fmt: "%s.%s.%s"
    toFieldPath: spec.forProvider.topic.name 
    transforms:
      - type: string
        string:
          type: Replace
          replace:
            search: "public"
            replace: "pub"

So the replace would happen after the combine (the original ticket would also support replace to the "fromField" before the combine).

If this makes sense I would implement it.

@applike-ss
Copy link
Author

Sounds logical 👍 Thanks for the feedback!

@gschei
Copy link
Contributor

gschei commented Jul 30, 2024

It PR was merged and this should be available in the next released version. @negz @jeanduplessis I also added documentation for it, but don't know if it makes sense, as this is now only available with the P&T composition function: crossplane/docs#796

@jeanduplessis
Copy link
Collaborator

I think it makes sense to land that PR once the docs have been updated to be "function-first": crossplane/docs#791

@gschei
Copy link
Contributor

gschei commented Aug 12, 2024

this was implemented and released with v0.7.0, issue can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed new transform
Projects
None yet
Development

No branches or pull requests

4 participants