diff --git a/plugins/railway/api_token.go b/plugins/railway/api_token.go new file mode 100644 index 00000000..60c41738 --- /dev/null +++ b/plugins/railway/api_token.go @@ -0,0 +1,39 @@ +package railway + +import ( + "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://docs.railway.app/guides/cli#authenticating-with-the-cli"), + ManagementURL: sdk.URL("https://railway.app/account/tokens"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Token used to authenticate to Railway.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 36, + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + )} +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "RAILWAY_API_TOKEN": fieldname.Token, +} diff --git a/plugins/railway/api_token_test.go b/plugins/railway/api_token_test.go new file mode 100644 index 00000000..00a677a6 --- /dev/null +++ b/plugins/railway/api_token_test.go @@ -0,0 +1,41 @@ +package railway + +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: "abcdefghijklm-1234567890-example", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "RAILWAY_API_TOKEN": "abcdefghijklm-1234567890-example", + }, + }, + }, + }) +} + +func TestAPITokenImporter(t *testing.T) { + plugintest.TestImporter(t, APIToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "RAILWAY_API_TOKEN": "abcdefghijklm-1234567890-example", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "abcdefghijklm-1234567890-example", + }, + }, + }, + }, + }) +} diff --git a/plugins/railway/plugin.go b/plugins/railway/plugin.go new file mode 100644 index 00000000..95564fb9 --- /dev/null +++ b/plugins/railway/plugin.go @@ -0,0 +1,22 @@ +package railway + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "railway", + Platform: schema.PlatformInfo{ + Name: "Railway", + Homepage: sdk.URL("https://railway.app"), + }, + Credentials: []schema.CredentialType{ + APIToken(), + }, + Executables: []schema.Executable{ + RailwayCLI(), + }, + } +} diff --git a/plugins/railway/railway.go b/plugins/railway/railway.go new file mode 100644 index 00000000..08479116 --- /dev/null +++ b/plugins/railway/railway.go @@ -0,0 +1,25 @@ +package railway + +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 RailwayCLI() schema.Executable { + return schema.Executable{ + Name: "Railway CLI", + Runs: []string{"railway"}, + DocsURL: sdk.URL("https://docs.railway.app/guides/cli"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.APIToken, + }, + }, + } +}