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

feat: Add plugin for prefect #284

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

avinash-santhanagopalan
Copy link

@avinash-santhanagopalan avinash-santhanagopalan commented Jun 9, 2023

Overview

Adds a plugin for prefect cli

Type of change

  • Created a new plugin
  • Improved an existing plugin
  • Fixed a bug in an existing plugin
  • Improved contributor utilities or experience

Related Issue(s)

  • Resolves: #
  • Relates: #

How To Test

Install prefect:

pip install prefect

Test the plugin:

op plugin init prefect      
####################################################################################
# WARNING: 'prefect' is not from the official registry.                            #
# Only proceed if you are the developer of 'prefect'.                              #
# Otherwise, delete the file at /Users/1password/.config/op/plugins/local/prefect. #
####################################################################################

Prefect [test build]
Authenticate with Prefect Access Key.

? Locate your Prefect Access Key: Search in 1Password...

? Locate your Prefect Access Key: <Prefect credentials>

? Configure when the chosen credential(s) will be used to authenticate: Prompt me for each new terminal session

The last step is to set up an alias for prefect.
You can do so by running the following command:

  echo "source /Users/1password/.config/op/plugins.sh" >> ~/.zshrc && source ~/.zshrc

Afterwards, run any prefect command to see it in action!
                                                                                                                                                   
29.395s 1password ❯ echo "source /Users/1password/.config/op/plugins.sh" >> ~/.zshrc && source ~/.zshrc
                                                                                                                                                  
154ms 1password ❯ prefect deployment ls
####################################################################################
# WARNING: 'prefect' is not from the official registry.                            #
# Only proceed if you are the developer of 'prefect'.                              #
# Otherwise, delete the file at /Users/1password/.config/op/plugins/local/prefect. #
####################################################################################
                                                   Deployments                                                    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Name                                                                    ┃ ID                                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ The list of deployments
└─────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────┘

Changelog

Authenticate Prefect using 1Password Shell Plugin

@arunsathiya arunsathiya added the in-progress this PR is being worked on/comments are in the process of being addressed by the contributor label Jun 12, 2023
@AndyTitu
Copy link
Contributor

@avinash-santhanagopalan There are some commits you should sign, otherwise this cannot be merged

@AndyTitu
Copy link
Contributor

Ping me after TODOs around config file importing are removed, and all commits are signed. I think this PR would be getting close to the finish line, after those are resolved.

Signed-off-by: Avinash Santhanagopalan <avinash.santhanagopalan@agilebits.com>
Signed-off-by: Avinash Santhanagopalan <avinash.santhanagopalan@agilebits.com>
Signed-off-by: Avinash Santhanagopalan <avinash.santhanagopalan@agilebits.com>
@avinash-santhanagopalan
Copy link
Author

@AndyTitu I've signed previous commits and removed the file importer portions. Let me know if there are further changes required.

Copy link
Member

@jpcoenen jpcoenen left a comment

Choose a reason for hiding this comment

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

Hey Avinash! Thanks for building this plugin 🙌 Overall it looks good. I've left a few comments to increase the test coverage and make some things a bit more future compatible.

Once these points are addressed, this is good to go in my opinion 🚀

plugins/prefect/access_key.go Outdated Show resolved Hide resolved
Comment on lines 36 to 44
Composition: &schema.ValueComposition{
Length: 124,
Prefix: "https://api.prefect.cloud/api/accounts/",
Charset: schema.Charset{
Uppercase: false,
Lowercase: true,
Digits: true,
},
},
Copy link
Member

Choose a reason for hiding this comment

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

It looks like Prefect also supports custom deployments. In that case, the API URL will be completely unpredictable. So I'd suggest we remove this composition field to assure maximum compatibility.

Suggested change
Composition: &schema.ValueComposition{
Length: 124,
Prefix: "https://api.prefect.cloud/api/accounts/",
Charset: schema.Charset{
Uppercase: false,
Lowercase: true,
Digits: true,
},
},

Choose a reason for hiding this comment

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

Ah I wasn't aware the API URL can change completely. One minor point is that the format of the URL will definitely have an account UUID and a workspace UUID following uuid4 format. Not sure if there is a way to specifically check that. I've had trouble in the past where I missed a single character while initiating and prefect's failure to authenticate messages were less than helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

@avinash-santhanagopalan Shell Plugins' importer SDK handles the importing of the API URL (which has the UUID segments) seamlessly. I think your overall concern is how to create/use UUID only in the tests. You can use a random UUID from https://uuid.rocks/ for that purpose.

Copy link
Member

Choose a reason for hiding this comment

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

One minor point is that the format of the URL will definitely have an account UUID and a workspace UUID following uuid4 format. Not sure if there is a way to specifically check that. I've had trouble in the past where I missed a single character while initiating and prefect's failure to authenticate messages were less than helpful.

Hmm. That's a good point. However, I don't think we have a good way to check for that right now. I can imagine us introducing more flexible validators for credentials at some point, which could help here. However, such a thing is not currently planned. So I think the best we can do for now, is rely on Prefect's error messaging here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@avinash-santhanagopalan We are less interested in determining composition for an URL-type field. Also there's no way currently to define an exact structure the field could take. So I agree with Joris that specifying this value composition could do more harm than good in this case, so we can just remove it altogether.

plugins/prefect/access_key_test.go Outdated Show resolved Hide resolved
plugins/prefect/access_key_test.go Outdated Show resolved Hide resolved
plugins/prefect/prefect.go Outdated Show resolved Hide resolved
@AndyTitu
Copy link
Contributor

@avinash-santhanagopalan is there anything we can do to help move this forward?

@hculea
Copy link
Member

hculea commented Sep 19, 2023

@avinash-santhanagopalan Let us know if there's anything that we can do to help move this forward!

@avinash-santhanagopalan
Copy link
Author

@hculea @AndyTitu Thank you for reaching out. I am not too familiar with Go test cases and I'm having some trouble getting them to pass. If you can help out that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-progress this PR is being worked on/comments are in the process of being addressed by the contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants