Skip to content

feat: credentials framework #212

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

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

g-linville
Copy link
Member

@g-linville g-linville commented Apr 3, 2024

You can read more about it in the doc I am adding in this PR, but basically this adds a "credentials framework" so that we have an easy way to supply secret values in environment variables to tools that need them. First you need to have a credential provider tool that prints a JSON object in the following format: {"env":{"ENV_VAR_1": "value1", "ENV_VAR_2": "value2"}}. Then, you can reference the credential tool in a script like this:

name: my-tool
credential: my-credential-tool.gpt

(tool body here)

The key-value pairs of environment variables that my-credential-tool.gpt returns will be added to the environment for the main tool's execution.

func (c Credential) String() string {
return c.ToolName
func toolNameWithCtx(toolName, credCtx string) string {
return toolName + "///" + credCtx
Copy link
Member Author

Choose a reason for hiding this comment

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

Open for suggestions for something better than this. I need a way of combining toolName and credCtx such that it still creates a valid URL.

@g-linville g-linville changed the title feat: credentials framework (WIP) feat: credentials framework Apr 10, 2024
@g-linville g-linville force-pushed the credentials-framework branch 2 times, most recently from e418b25 to 8d03ffe Compare April 10, 2024 19:59
@g-linville g-linville marked this pull request as ready for review April 10, 2024 20:01
Chdir string `usage:"Change current working directory" short:"C"`
Daemon bool `usage:"Run tool as a daemon" local:"true" hidden:"true"`
Ports string `usage:"The port range to use for ephemeral daemon ports (ex: 11000-12000)" hidden:"true"`
CredentialContext string `usage:"Context name in which to store credentials" default:"default" short:"c"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use -c. Just make it long and verbose right now. -c might be useful for something else more important later

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

}

func NewCredential(root *GPTScript) *cobra.Command {
c := cmd.Command(&Credential{root: root}, cobra.Command{
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been using the Customize interface approach to change the default cobra.Command fields. I feel like that is slightly less confusing pattern. I'm going to probably drop support for this style of passing it as a second arg.

https://github.com/gptscript-ai/gptscript/blob/main/pkg/cli/gptscript.go#L102

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed


type Credential struct {
root *GPTScript
AllContexts bool `short:"A" usage:"List credentials for all contexts" local:"true"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't do -A. Either have no short or if you really want a short value then -a. The -A is very kubernetes-y.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville force-pushed the credentials-framework branch from c2929e5 to f383f86 Compare April 11, 2024 20:04
@g-linville g-linville merged commit f4284f4 into gptscript-ai:main Apr 11, 2024
@g-linville
Copy link
Member Author

(I got verbal approval from Darren to merge.)

@g-linville g-linville deleted the credentials-framework branch April 11, 2024 21:04
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.

3 participants