-
Notifications
You must be signed in to change notification settings - Fork 172
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
Add support for Nirmata,cloud-native application management #298
Changes from all 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package nirmata | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/importer" | ||
"github.com/1Password/shell-plugins/sdk/provision" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
"github.com/1Password/shell-plugins/sdk/schema/credname" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func APIToken() schema.CredentialType { | ||
return schema.CredentialType{ | ||
Name: credname.APIToken, | ||
DocsURL: sdk.URL("https://downloads.nirmata.io/nctl/downloads/"), | ||
ManagementURL: sdk.URL("https://www.nirmata.io/security/login.html"), | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.Token, | ||
MarkdownDescription: "Token used to authenticate to Nirmata.", | ||
Secret: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 116, | ||
Charset: schema.Charset{ | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: fieldname.Email, | ||
MarkdownDescription: "Email address registered in Nirmata.", | ||
Optional: true, | ||
}, | ||
{ | ||
Name: fieldname.Address, | ||
MarkdownDescription: "Url address of Nirmata[https://nirmata.io].", | ||
Optional: true, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), | ||
|
||
AndyTitu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Importer: importer.TryAll( | ||
importer.TryEnvVarPair(defaultEnvVarMapping), | ||
TryNirmataConfigFile(), | ||
)} | ||
} | ||
|
||
var defaultEnvVarMapping = map[string]sdk.FieldName{ | ||
"NIRMATA_TOKEN": fieldname.Token, | ||
"NIRMATA_URL": fieldname.Address, | ||
} | ||
|
||
func TryNirmataConfigFile() sdk.Importer { | ||
return importer.TryFile("~/.nirmata/config", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
|
||
credentialsFile, err := contents.ToINI() | ||
if err != nil { | ||
out.AddError(err) | ||
return | ||
} | ||
for _, section := range credentialsFile.Sections() { | ||
fields := make(map[sdk.FieldName]string) | ||
if section.HasKey("address") && section.Key("address").Value() != "" { | ||
fields[fieldname.Address] = section.Key("address").Value() | ||
} | ||
// if section.HasKey("email") && section.Key("email").Value() != "" { | ||
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. Let's completely remove this block instead of leaving them as commented sections. 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. @itsCheithanya this is still commented |
||
// fields[fieldname.Email] = section.Key("email").Value() | ||
// } | ||
if section.HasKey("token") && section.Key("token").Value() != "" { | ||
fields[fieldname.Token] = section.Key("token").Value() | ||
} | ||
if fields[fieldname.Token] != "" { | ||
out.AddCandidate(sdk.ImportCandidate{ | ||
Fields: fields, | ||
}) | ||
} | ||
|
||
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. A couple of empty lines in this file as well. |
||
} | ||
|
||
}) | ||
} | ||
|
||
type Config struct { | ||
Token string | ||
Address string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package nirmata | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/plugintest" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func TestAPITokenProvisioner(t *testing.T) { | ||
plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
"default": { | ||
ItemFields: map[sdk.FieldName]string{ | ||
fieldname.Token: "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
fieldname.Address: "https://nirmata.io", | ||
}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Environment: map[string]string{ | ||
"NIRMATA_TOKEN": "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
"NIRMATA_URL": "https://nirmata.io", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAPITokenImporter(t *testing.T) { | ||
plugintest.TestImporter(t, APIToken().Importer, map[string]plugintest.ImportCase{ | ||
"environment": { | ||
Environment: map[string]string{ | ||
"NIRMATA_TOKEN": "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
"NIRMATA_URL": "https://nirmata.io", | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.Token: "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
fieldname.Address: "https://nirmata.io", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
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. An empty line here. Let's remove it. |
||
"config file": { | ||
Files: map[string]string{ | ||
"~/.nirmata/config": plugintest.LoadFixture(t, "config"), | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.Token: "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
fieldname.Address: "https://nirmata.io", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package nirmata | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/needsauth" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
"github.com/1Password/shell-plugins/sdk/schema/credname" | ||
) | ||
|
||
func NirmataCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "Nirmata CLI", | ||
Runs: []string{"nctl"}, | ||
DocsURL: sdk.URL("https://nirmata.com/docs/cli"), // TODO: Replace with actual URL | ||
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 todo as well. |
||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
needsauth.NotWithoutArgs(), | ||
Comment on lines
+16
to
+17
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. Let's opt out of authentication for 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. yess getit!! 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. Thanks! I'm not familiar with the Nirmata CLI, are there any other commands which do not require authentication? 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 believe |
||
needsauth.NotForExactArgs("login"), | ||
), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.APIToken, | ||
}, | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package nirmata | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "nirmata", | ||
Platform: schema.PlatformInfo{ | ||
Name: "Nirmata", | ||
Homepage: sdk.URL("https://nirmata.com"), // TODO: Check if this is correct | ||
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. Let's remove the TODO from here. 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. yess into it 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. @itsCheithanya This does not seem to be removed yet, could we make sure to remove it, please? 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. Let's remove the TODO from here. 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. It looks like nirmata.com and nirmata.io are two different products/services, but from the same company? Could you share some specifics of what you know about Nirmata? That'd help us reviewers jumpstart the process, vs having to understand the Nirmata concepts manually. Thanks @itsCheithanya! |
||
}, | ||
Credentials: []schema.CredentialType{ | ||
APIToken(), | ||
}, | ||
Executables: []schema.Executable{ | ||
NirmataCLI(), | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
address: https://nirmata.io | ||
token: fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample |
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.
Is the email required in the item, since it's not provisioned?
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.
But it should be used for this command
nctl login
which prompts for all these fields including emailThere 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.
With this shell plugin, the user should no longer have to run
nctl login
. From what I can find in the documentation (Alternatively, you can use global flags or set the NIRMATA_TOKEN and NIRMATA_URL environment variables.
), this is an alternative to the email-based authentication.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.
Okay in that way makes sense
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.
So should we now make the URL field required and not optional?
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.
No, since the docs state that the URL has a default:
so not provisioning it would not break the users' workflows.
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.
oh okay so should I only import token from the config file?
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.
It's okay to also import url from the config file. At provisioning time, if there's nothing to provision for the url, then we can use the default value