-
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 2 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,88 @@ | ||
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://nirmata.com/docs/api_token"), // TODO: Replace with actual URL | ||
ManagementURL: sdk.URL("https://console.nirmata.com/user/security/tokens"), // TODO: Replace with actual URL | ||
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.", | ||
Comment on lines
+33
to
+34
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. But it should be used for this command 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. With this shell plugin, the user should no longer have to run 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. Okay in that way makes sense 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. 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 commentThe 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 commentThe 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 commentThe 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 |
||
}, | ||
{ | ||
Name: fieldname.Address, | ||
MarkdownDescription: "Url address of Nirmata[https://nirmata.io].", | ||
}, | ||
}, | ||
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.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. I see we import and require an email, but only provision the token and URL. Is the email something that is required as well? Otherwise, let's consider making it optional, or, alternatively, omitting it from the importer. 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. yup done! |
||
|
||
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() != "" { | ||
fields[fieldname.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. I don't think we need to import this, since it's not provisioned to the commands. 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 i feel you are correct ill try without email |
||
if section.HasKey("token") && section.Key("token").Value() != "" { | ||
fields[fieldname.Token] = section.Key("token").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. I see there is a reference to Let's make sure that our import candidates comply with the structure that the provider expects. 😄 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. Yeah I've done the change |
||
} | ||
if fields[fieldname.Address] != "" && fields[fieldname.Email] != "" && 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 { | ||
Address string | ||
Email string | ||
Token string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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.URL: "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{ // 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. |
||
"NIRMATA_TOKEN": "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
"NIRMATA_URL": "https://nirmata.io", | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.Token: "fw90xpbsq8d1nzmdmbie0bcwk99x9rodqx72wfwif7y2hfbhq3gjg4bhcluw8b5qto5hwzfagsztgibbjs4rm8vswu6ppez8za9vhc2ozv5trexample", | ||
fieldname.URL: "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.URL: "https://nirmata.io", | ||
fieldname.Email: "user@email.com", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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 |
||
), | ||
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,3 @@ | ||
address: https://nirmata.io | ||
email: user@gmail.com | ||
token: oXcdvSstvdvx5uC+bfbDrv+UyQzalwluvcdfQa0HMzzRpjdvdUe9taD9cdsknlkca7IeVdHUibaxjakbcdlcVHcP9yA14A= |
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.
These URLs don't work for me 🤔
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.
ohh yeahh I should change it,I didn't find proper documentation about the CLI ,this is the only where it is mentioned
https://downloads.nirmata.io/nctl/downloads/