diff --git a/plugins/expo/access_token.go b/plugins/expo/access_token.go new file mode 100644 index 00000000..4474d0b8 --- /dev/null +++ b/plugins/expo/access_token.go @@ -0,0 +1,33 @@ +package expo + +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 AccessToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.AccessToken, + DocsURL: sdk.URL("https://docs.expo.dev/accounts/programmatic-access/"), + ManagementURL: sdk.URL("https://expo.dev/accounts/[account]/settings/access-tokens"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Access token used to authenticate to Expo.", + Secret: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + ), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "EXPO_TOKEN": fieldname.Token, +} diff --git a/plugins/expo/access_token_test.go b/plugins/expo/access_token_test.go new file mode 100644 index 00000000..495dc324 --- /dev/null +++ b/plugins/expo/access_token_test.go @@ -0,0 +1,41 @@ +package expo + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestAccessTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, AccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "EXAMPLEEXPOTOKEN123", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "EXPO_TOKEN": "EXAMPLEEXPOTOKEN123", + }, + }, + }, + }) +} + +func TestAccessTokenImporter(t *testing.T) { + plugintest.TestImporter(t, AccessToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "EXPO_TOKEN": "EXAMPLEEXPOTOKEN123", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "EXAMPLEEXPOTOKEN123", + }, + }, + }, + }, + }) +} diff --git a/plugins/expo/eas.go b/plugins/expo/eas.go new file mode 100644 index 00000000..3d103162 --- /dev/null +++ b/plugins/expo/eas.go @@ -0,0 +1,27 @@ +package expo + +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 EASCLI() schema.Executable { + return schema.Executable{ + Name: "EAS CLI", + Runs: []string{"eas"}, + DocsURL: sdk.URL("https://docs.expo.dev/build/setup/"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("login"), + needsauth.NotWhenContainsArgs("logout"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.AccessToken, + }, + }, + } +} diff --git a/plugins/expo/expo.go b/plugins/expo/expo.go new file mode 100644 index 00000000..97561b14 --- /dev/null +++ b/plugins/expo/expo.go @@ -0,0 +1,28 @@ +package expo + +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 ExpoCLI() schema.Executable { + return schema.Executable{ + Name: "Expo CLI", + Runs: []string{"expo"}, + DocsURL: sdk.URL("https://docs.expo.dev/more/expo-cli/"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("login"), + needsauth.NotWhenContainsArgs("logout"), + needsauth.NotWhenContainsArgs("register"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.AccessToken, + }, + }, + } +} diff --git a/plugins/expo/plugin.go b/plugins/expo/plugin.go new file mode 100644 index 00000000..3e449d88 --- /dev/null +++ b/plugins/expo/plugin.go @@ -0,0 +1,23 @@ +package expo + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "expo", + Platform: schema.PlatformInfo{ + Name: "Expo", + Homepage: sdk.URL("https://expo.dev"), + }, + Credentials: []schema.CredentialType{ + AccessToken(), + }, + Executables: []schema.Executable{ + ExpoCLI(), + EASCLI(), + }, + } +}