-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #338 from rajapri28613/pipedream
Add support for Pipedream CLI
- Loading branch information
Showing
7 changed files
with
223 additions
and
0 deletions.
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,102 @@ | ||
package pipedream | ||
|
||
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://pipedream.com/docs/api_key"), | ||
ManagementURL: sdk.URL("https://console.pipedream.com/user/security/tokens"), | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.APIKey, | ||
MarkdownDescription: "API Key used to authenticate to Pipedream.", | ||
Secret: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 32, | ||
Charset: schema.Charset{ | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: fieldname.OrgID, | ||
MarkdownDescription: "OrgId for the Pipedream organization.", | ||
Secret: false, | ||
Optional: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 9, | ||
Charset: schema.Charset{ | ||
Lowercase: true, | ||
Uppercase: true, | ||
Digits: true, | ||
Symbols: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.TempFile( | ||
pipedreamConfig, | ||
provision.AtFixedPath("~/.config/pipedream/config"), | ||
), | ||
Importer: importer.TryAll( | ||
TryPipedreamConfigFile(), | ||
)} | ||
} | ||
|
||
func TryPipedreamConfigFile() sdk.Importer { | ||
return importer.TryFile("~/.config/pipedream/config", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
configFile, err := contents.ToINI() | ||
|
||
if err != nil { | ||
out.AddError(err) | ||
return | ||
} | ||
|
||
for _, section := range configFile.Sections() { | ||
fields := make(map[sdk.FieldName]string) | ||
if section.HasKey("api_key") && section.Key("api_key").Value() != "" { | ||
fields[fieldname.APIKey] = section.Key("api_key").Value() | ||
} | ||
if section.HasKey("org_id") && section.Key("org_id").Value() != "" { | ||
fields[fieldname.OrgID] = section.Key("org_id").Value() | ||
} | ||
|
||
if fields[fieldname.APIKey] != "" { | ||
out.AddCandidate(sdk.ImportCandidate{ | ||
Fields: fields, | ||
NameHint: importer.SanitizeNameHint(section.Name()), | ||
}) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
type Config struct { | ||
APIKey string | ||
OrgId string | ||
} | ||
|
||
func pipedreamConfig(in sdk.ProvisionInput) ([]byte, error) { | ||
contents := "" | ||
|
||
if apikey, ok := in.ItemFields[fieldname.APIKey]; ok { | ||
contents += "api_key = " + apikey + "\n" | ||
} | ||
|
||
if orgid, ok := in.ItemFields[fieldname.OrgID]; ok { | ||
contents += "org_id = " + orgid + "\n" | ||
} | ||
|
||
return []byte(contents), nil | ||
} |
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,59 @@ | ||
package pipedream | ||
|
||
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{ | ||
"config file": { | ||
ItemFields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "ugvfxesz62ycsl42z49c0t1hjexample", | ||
fieldname.OrgID: "YbEXAMPLE", | ||
}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Files: map[string]sdk.OutputFile{ | ||
"~/.config/pipedream/config": { | ||
Contents: []byte(plugintest.LoadFixture(t, "provision")), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAPIKeyImporter(t *testing.T) { | ||
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ | ||
"config file": { | ||
Files: map[string]string{ | ||
"~/.config/pipedream/config": plugintest.LoadFixture(t, "import"), | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "ugvfxesz62ycsl42z49c0t1hjexample", | ||
fieldname.OrgID: "YbEXAMPLE", | ||
}, | ||
NameHint: "DEFAULT", | ||
}, | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "5puf32rvhkz83c6oj4wpxvaniexample", | ||
fieldname.OrgID: "KVEXAMPLE", | ||
}, | ||
NameHint: "first", | ||
}, | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "lgx1amb0qf7mjy6y7nkgfc3x9example", | ||
}, | ||
NameHint: "second", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
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,27 @@ | ||
package pipedream | ||
|
||
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 PipedreamCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "Pipedream CLI", | ||
Runs: []string{"pd"}, | ||
DocsURL: sdk.URL("https://pipedream.com/docs/cli/reference/"), | ||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
needsauth.NotWithoutArgs(), | ||
needsauth.NotWhenContainsArgs("-p"), | ||
needsauth.NotWhenContainsArgs("--profile"), | ||
), | ||
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,22 @@ | ||
package pipedream | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "pipedream", | ||
Platform: schema.PlatformInfo{ | ||
Name: "Pipedream", | ||
Homepage: sdk.URL("https://pipedream.com"), | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
APIKey(), | ||
}, | ||
Executables: []schema.Executable{ | ||
PipedreamCLI(), | ||
}, | ||
} | ||
} |
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,9 @@ | ||
api_key = ugvfxesz62ycsl42z49c0t1hjexample | ||
org_id = YbEXAMPLE | ||
|
||
[first] | ||
api_key = 5puf32rvhkz83c6oj4wpxvaniexample | ||
org_id = KVEXAMPLE | ||
|
||
[second] | ||
api_key = lgx1amb0qf7mjy6y7nkgfc3x9example |
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,2 @@ | ||
api_key = ugvfxesz62ycsl42z49c0t1hjexample | ||
org_id = YbEXAMPLE |
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