Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions plugins/railway/api_token.go
Original file line number Diff line number Diff line change
@@ -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,
}
41 changes: 41 additions & 0 deletions plugins/railway/api_token_test.go
Original file line number Diff line number Diff line change
@@ -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",
},
},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/railway/plugin.go
Original file line number Diff line number Diff line change
@@ -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(),
},
}
}
25 changes: 25 additions & 0 deletions plugins/railway/railway.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}