-
Notifications
You must be signed in to change notification settings - Fork 295
feat: support sqlite credential helper #857
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,22 @@ import ( | |
"github.com/docker/cli/cli/config/types" | ||
) | ||
|
||
var ( | ||
darwinHelpers = []string{"osxkeychain", "file"} | ||
windowsHelpers = []string{"wincred", "file"} | ||
linuxHelpers = []string{"secretservice", "pass", "file"} | ||
const ( | ||
Wincred = "wincred" | ||
Osxkeychain = "osxkeychain" | ||
Secretservice = "secretservice" | ||
Pass = "pass" | ||
File = "file" | ||
Sqlite = "sqlite" | ||
|
||
GPTScriptHelperPrefix = "gptscript-credential-" | ||
) | ||
|
||
const GPTScriptHelperPrefix = "gptscript-credential-" | ||
var ( | ||
darwinHelpers = []string{Osxkeychain, File, Sqlite} | ||
windowsHelpers = []string{Wincred, File} | ||
linuxHelpers = []string{Secretservice, Pass, File, Sqlite} | ||
) | ||
|
||
type AuthConfig types.AuthConfig | ||
|
||
|
@@ -150,11 +159,11 @@ func ReadCLIConfig(gptscriptConfigFile string) (*CLIConfig, error) { | |
errMsg := fmt.Sprintf("invalid credential store '%s'", result.CredentialsStore) | ||
switch runtime.GOOS { | ||
case "darwin": | ||
errMsg += " (use 'osxkeychain' or 'file')" | ||
errMsg += " (use 'osxkeychain', 'file', or 'sqlite')" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These probably won't change much, but you could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
case "windows": | ||
errMsg += " (use 'wincred' or 'file')" | ||
case "linux": | ||
errMsg += " (use 'secretservice', 'pass', or 'file')" | ||
errMsg += " (use 'secretservice', 'pass', 'file', or 'sqlite')" | ||
default: | ||
errMsg += " (use 'file')" | ||
} | ||
|
@@ -169,11 +178,11 @@ func ReadCLIConfig(gptscriptConfigFile string) (*CLIConfig, error) { | |
func (c *CLIConfig) setDefaultCredentialsStore() error { | ||
switch runtime.GOOS { | ||
case "darwin": | ||
c.CredentialsStore = "osxkeychain" | ||
c.CredentialsStore = Osxkeychain | ||
case "windows": | ||
c.CredentialsStore = "wincred" | ||
c.CredentialsStore = Wincred | ||
default: | ||
c.CredentialsStore = "file" | ||
c.CredentialsStore = File | ||
} | ||
return c.Save() | ||
} | ||
|
@@ -187,7 +196,7 @@ func isValidCredentialHelper(helper string) bool { | |
case "linux": | ||
return slices.Contains(linuxHelpers, helper) | ||
default: | ||
return helper == "file" | ||
return helper == File | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ func NewStore(cfg *config.CLIConfig, credentialBuilder CredentialBuilder, credCt | |
return Store{ | ||
credCtxs: credCtxs, | ||
credBuilder: credentialBuilder, | ||
credHelperDirs: GetCredentialHelperDirs(cacheDir), | ||
credHelperDirs: GetCredentialHelperDirs(cacheDir, cfg.CredentialsStore), | ||
cfg: cfg, | ||
}, nil | ||
} | ||
|
@@ -178,7 +178,7 @@ func (s *Store) getStore(ctx context.Context) (credentials.Store, error) { | |
} | ||
|
||
func (s *Store) getStoreByHelper(ctx context.Context, helper string) (credentials.Store, error) { | ||
if helper == "" || helper == config.GPTScriptHelperPrefix+"file" { | ||
if helper == "" || helper == config.GPTScriptHelperPrefix+config.File { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This solidifies my desire to change the names of those constants: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return credentials.NewFileStore(s.cfg), nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
package credentials | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/gptscript-ai/gptscript/pkg/config" | ||
runtimeEnv "github.com/gptscript-ai/gptscript/pkg/env" | ||
) | ||
|
||
type CredentialHelperDirs struct { | ||
RevisionFile, LastCheckedFile, BinDir string | ||
} | ||
|
||
func GetCredentialHelperDirs(cacheDir string) CredentialHelperDirs { | ||
func RepoNameForCredentialStore(store string) string { | ||
switch store { | ||
case config.Sqlite: | ||
return "gptscript-credential-sqlite" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might change this at a later point. Don't want to go through the process of getting approvals on this one again just for that change |
||
default: | ||
return "gptscript-credential-helpers" | ||
} | ||
} | ||
|
||
func GitURLForRepoName(repoName string) (string, error) { | ||
switch repoName { | ||
case "gptscript-credential-sqlite": | ||
return runtimeEnv.VarOrDefault("GPTSCRIPT_CRED_SQLITE_ROOT", "https://github.com/gptscript-ai/gptscript-credential-sqlite.git"), nil | ||
case "gptscript-credential-helpers": | ||
return runtimeEnv.VarOrDefault("GPTSCRIPT_CRED_HELPERS_ROOT", "https://github.com/gptscript-ai/gptscript-credential-helpers.git"), nil | ||
default: | ||
return "", fmt.Errorf("unknown repo name: %s", repoName) | ||
} | ||
} | ||
|
||
func GetCredentialHelperDirs(cacheDir, store string) CredentialHelperDirs { | ||
repoName := RepoNameForCredentialStore(store) | ||
return CredentialHelperDirs{ | ||
RevisionFile: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "revision"), | ||
LastCheckedFile: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "last-checked"), | ||
BinDir: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "bin"), | ||
RevisionFile: filepath.Join(cacheDir, "repos", repoName, "revision"), | ||
LastCheckedFile: filepath.Join(cacheDir, "repos", repoName, "last-checked"), | ||
BinDir: filepath.Join(cacheDir, "repos", repoName, "bin"), | ||
} | ||
} | ||
|
||
|
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.
I think appending
CredHelper
to each of these would give them a more descriptive name.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.
Fixed