-
Notifications
You must be signed in to change notification settings - Fork 197
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 Shodan Command-Line Interface Plugin #400
Open
kusshi94
wants to merge
9
commits into
1Password:main
Choose a base branch
from
kusshi94:feature/shodanPlugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
247553f
Initialize shodan Plugin
kusshi94 e2e540b
Update the shodan plugin definition
kusshi94 7e6ab0f
Update the shodan plugin API Key definition
kusshi94 3258d1d
Update the shodan plugin executable definition
kusshi94 d27a4a8
update API Key Test
kusshi94 85660be
go fmt
kusshi94 5acbc42
change to use ~/.config/shodan/
kusshi94 c6e781b
change DocsURL
kusshi94 6abf2e2
change to exclude shodan init command from needsauth targets
kusshi94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package shodan | ||
|
||
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 APIKey() schema.CredentialType { | ||
return schema.CredentialType{ | ||
Name: credname.APIKey, | ||
DocsURL: sdk.URL("https://cli.shodan.io"), | ||
ManagementURL: sdk.URL("https://account.shodan.io"), | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.APIKey, | ||
MarkdownDescription: "API Key used to authenticate to Shodan.", | ||
Secret: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 32, | ||
Charset: schema.Charset{ | ||
Uppercase: true, | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.TempFile( | ||
provision.FieldAsFile(fieldname.APIKey), | ||
provision.AtFixedPath("~/.shodan/api_key"), | ||
), | ||
Importer: importer.TryAll( | ||
TryShodanConfigFile("~/.shodan/api_key"), | ||
TryShodanConfigFile("~/.config/shodan/api_key"), | ||
)} | ||
} | ||
|
||
func TryShodanConfigFile(configPath string) sdk.Importer { | ||
return importer.TryFile(configPath, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
apiKey := contents.ToString() | ||
|
||
if apiKey == "" { | ||
return | ||
} | ||
|
||
out.AddCandidate(sdk.ImportCandidate{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: apiKey, | ||
}, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package shodan | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/plugintest" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func TestAPIKeyProvisioner(t *testing.T) { | ||
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
"default": { | ||
ItemFields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "ddXfzwQOIjTaaxGMzcxXYR6Q0EXAMPLE", | ||
}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Files: map[string]sdk.OutputFile{ | ||
"~/.config/shodan/api_key": {Contents: []byte("ddXfzwQOIjTaaxGMzcxXYR6Q0EXAMPLE")}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAPIKeyImporter(t *testing.T) { | ||
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ | ||
"config file": { | ||
Files: map[string]string{ | ||
"~/.config/shodan/api_key": plugintest.LoadFixture(t, "api_key"), | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "ddXfzwQOIjTaaxGMzcxXYR6Q0EXAMPLE", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package shodan | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "shodan", | ||
Platform: schema.PlatformInfo{ | ||
Name: "Shodan", | ||
Homepage: sdk.URL("https://www.shodan.io"), | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
APIKey(), | ||
}, | ||
Executables: []schema.Executable{ | ||
ShodanCLI(), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package shodan | ||
|
||
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 ShodanCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "Shodan Command-Line Interface", | ||
Runs: []string{"shodan"}, | ||
DocsURL: sdk.URL("https://cli.shodan.io"), | ||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
needsauth.NotWithoutArgs(), | ||
needsauth.NotForExactArgs("init"), | ||
), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.APIKey, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ddXfzwQOIjTaaxGMzcxXYR6Q0EXAMPLE |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
shall we also exclude
shodan init
from here?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 appended
needsauth.NotForExactArgs("init")
to the arguments ofneedsauth.IfAll()
.