Repository navigation
Add plugin for Nimble package manager - #255
electrocally wants to merge 4 commits into
Conversation
AndyTitu
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Left a few comments. Let me know if you need additional guidance!
| } | ||
|
|
||
| func TryNimbleConfigFile() sdk.Importer { | ||
| // TODO: Try importing from ~/.nimble/github_api_token file |
There was a problem hiding this comment.
is this TODO a change to be carried on in this PR? If not, I would suggest adding an importer for a potentially already existing NIMBLE_GITHUB_API_TOKEN as a quick win, just so not to ship this with absolutely no importers.
There was a problem hiding this comment.
importer.TryEnvVarPair(defaultEnvVarMapping),
There was a problem hiding this comment.
Thanks so much for the feedback & suggestions, @AndyTitu !
I'll add in the env var importer this evening.
For the file importer, this is similar to the HashiCorp Vault plugin. I wasn't able to create a working version as the ~/.nimble/github_api_token file doesn't have any formatting/extension type, just the token in plaintext.
I was hoping to ask for suggestions - I read through the other plugins to compare, but as far as I can see, the package seems to expect a key/value.
There was a problem hiding this comment.
I've pushed TryEnvVarPair to the top of the TryAll in importers. Cheers!
There was a problem hiding this comment.
Something like this should do the trick for the file importer, provided the file only contains the token:
func TryNimbleConfigFile(path string) sdk.Importer {
return importer.TryFile(path, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
credential := contents.ToString()
fields := make(map[sdk.FieldName]string)
if len(credential) != 0 {
fields[fieldname.Token] = credential
}
out.AddCandidate(sdk.ImportCandidate{
Fields: fields,
})
})
}I didn't test this code, let us know in case this doesn't work and we can look deeper into it 😄
There was a problem hiding this comment.
Hey @hculea, thank you so much for your help on this! That seems to be working well & I've just tested that it can now import from that config file
| ), | ||
| Uses: []schema.CredentialUsage{ | ||
| { | ||
| Name: credname.PersonalAccessToken, |
There was a problem hiding this comment.
If we go on the route mentioned in the other comment, here we could just specify Plugin: github, Name: credname.PersonalAccessToken and Provisioner: the provisioner you created.
There was a problem hiding this comment.
I'm all for using the standardised plugin! The schema suggests this needs to be a string for the plugin, e.g. Plugin: "github"?
I can't seem to see other plugins using it for an example, so any help would be massively appreciated.
As I've not added a custom provisioner, would something along the lines of this be close?
...
Uses: []schema.CredentialUsage{
{
Plugin: "github",
Name: credname.PersonalAccessToken,
},
},Thanks in advance
There was a problem hiding this comment.
@electrocally Yes, this is right!
The only extra thing is that you need to define a custom provisioner for this credential usage, as you noted in this other thread's reply.
So this should work:
Uses: []schema.CredentialUsage{
{
Plugin: "github",
Name: credname.PersonalAccessToken,
Provisioner: provision.EnvVars(nimbleDefaultEnvVarMapping),
},
},
...
var nimbleDefaultEnvVarMapping = map[string]sdk.FieldName{
"NIMBLE_GITHUB_API_TOKEN": fieldname.Token,
}
while everything else in nimble/personal_access_token.go can be safely removed.
You could then remove the provisioner test case entirely or modify it to test this custom provisioner provision.EnvVars(nimbleDefaultEnvVarMapping)
There was a problem hiding this comment.
Let's add the provisioner here in the credential usage, as we discussed before
hculea
left a comment
There was a problem hiding this comment.
Thanks for the contribution! ❤️ I've only left a few comments, looks great for the most part.
| Runs: []string{"nimble"}, | ||
| DocsURL: sdk.URL("https://github.com/nim-lang/nimble"), | ||
| NeedsAuth: needsauth.IfAll( | ||
| needsauth.IfAny( |
There was a problem hiding this comment.
No need for IfAny in this situation, since it only contains one rule.
There was a problem hiding this comment.
This has yet to be resolved
| } | ||
|
|
||
| func TryNimbleConfigFile() sdk.Importer { | ||
| // TODO: Try importing from ~/.nimble/github_api_token file |
There was a problem hiding this comment.
Something like this should do the trick for the file importer, provided the file only contains the token:
func TryNimbleConfigFile(path string) sdk.Importer {
return importer.TryFile(path, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
credential := contents.ToString()
fields := make(map[sdk.FieldName]string)
if len(credential) != 0 {
fields[fieldname.Token] = credential
}
out.AddCandidate(sdk.ImportCandidate{
Fields: fields,
})
})
}I didn't test this code, let us know in case this doesn't work and we can look deeper into it 😄
| type Config struct { | ||
| Token string `ini:"token"` | ||
| } |
| func TestPersonalAccessTokenImporter(t *testing.T) { | ||
| plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{ | ||
| "environment": { | ||
| Environment: map[string]string{ | ||
| "NIMBLE_GITHUB_API_TOKEN": "ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, | ||
| ExpectedCandidates: []sdk.ImportCandidate{ | ||
| { | ||
| Fields: map[sdk.FieldName]string{ | ||
| fieldname.Token: "ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, |
There was a problem hiding this comment.
Let's make sure we also add a test for the file importer, once that's sorted out.
|
@electrocally Are there any further blockers you would need some help with, following our developer Slack conversation? Let me know 😄 ! |
Thanks for checking in @AndyTitu! I've not had a lot of time for my projects lately. Hoping to do a bit more on this over the coming evenings 😁 |
|
@electrocally Do let us know if there is anything that we can help with, to keep this moving 😄 |
|
Hi guys! Thanks so much for the continued encouragement the last few weeks. It's been really great to contribute to this project 😀 I've just pushed up some changes - there's good and bad news. The not so good: I love the concept of using the |
| @@ -0,0 +1 @@ | |||
| ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE No newline at end of file | |||
|
@electrocally I'm fine with not attempting to change the schema to adhere to the importing scenario in this MR. Let's make sure we create a separate issue for that though, if one doesn't exist already. But there are still a few open discussions to be resolved before we could merge this PR |
Overview
This plugin adds support for https://nimble.directory, the package manager for https://nim-lang.org
Type of change
How To Test
nimblemake nimble/build&op plugin init nimble. This may prompt for your PAT, explained in step 4nimble initto create a new Nim package (additional docs here)nimble publish, 1Password will prompt for your GitHub Personal Access Token. This will needpublic_repopermissions.Changelog
Authenticate the publishing Nim (Nimble) packages using Touch ID and other unlock options with 1Password Shell Plugins.