diff --git a/plugins/registry.go b/plugins/registry.go index 6850f6df2..cabcad600 100644 --- a/plugins/registry.go +++ b/plugins/registry.go @@ -47,11 +47,15 @@ func GetByExecutable(executableQuery string) (schema.Plugin, schema.Executable, return schema.Plugin{}, schema.Executable{}, fmt.Errorf("unknown plugin: %s", executableQuery) } +// GetCredentialType returns the credential type with the given name from the given plugin. The +// credential can be identified by its name (e.g. "Access Key") or by its ID (e.g. "access_key"). func GetCredentialType(pluginName string, credentialName string) (schema.CredentialType, error) { for _, p := range registry { if p.Name == pluginName { for _, credential := range p.Credentials { - return credential, nil + if credential.Name.String() == credentialName || credential.Name.ID().String() == credentialName { + return credential, nil + } } return schema.CredentialType{}, fmt.Errorf("unknown credential: %s (%s)", credentialName, pluginName) } diff --git a/plugins/registry_test.go b/plugins/registry_test.go index 78ab275f3..54b5074c6 100644 --- a/plugins/registry_test.go +++ b/plugins/registry_test.go @@ -1,10 +1,13 @@ package plugins import ( + "net/url" "testing" + "github.com/1Password/shell-plugins/sdk" "github.com/1Password/shell-plugins/sdk/schema" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestValidatePlugins(t *testing.T) { @@ -27,3 +30,119 @@ func TestAllPluginsHaveUniqueNames(t *testing.T) { assert.True(t, schema.IsStringSliceASet(pluginNames)) } + +// useTestRegistry replaces the registered plugins with the given ones for the duration of the test. +func useTestRegistry(t *testing.T, testPlugins ...schema.Plugin) { + t.Helper() + original := registry + registry = testPlugins + t.Cleanup(func() { + registry = original + }) +} + +func testURL(t *testing.T, rawURL string) *url.URL { + t.Helper() + u, err := url.Parse(rawURL) + require.NoError(t, err) + return u +} + +func testPlugins(t *testing.T) []schema.Plugin { + t.Helper() + return []schema.Plugin{ + { + Name: "single", + Platform: schema.PlatformInfo{Name: "Single"}, + Credentials: []schema.CredentialType{ + {Name: sdk.CredentialName("API Key"), ManagementURL: testURL(t, "https://single.example.com/keys")}, + }, + }, + { + Name: "double", + Platform: schema.PlatformInfo{Name: "Double"}, + Credentials: []schema.CredentialType{ + {Name: sdk.CredentialName("Access Key")}, + {Name: sdk.CredentialName("SSO Profile"), ManagementURL: testURL(t, "https://double.example.com/sso")}, + }, + }, + { + Name: "nocredentials", + Platform: schema.PlatformInfo{Name: "No Credentials"}, + }, + } +} + +func TestGetCredentialType(t *testing.T) { + useTestRegistry(t, testPlugins(t)...) + + cases := map[string]struct { + pluginName string + credentialName string + expectedName sdk.CredentialName + expectedErr string + }{ + "only credential type of a plugin": { + pluginName: "single", + credentialName: "API Key", + expectedName: "API Key", + }, + "first credential type of a plugin with two": { + pluginName: "double", + credentialName: "Access Key", + expectedName: "Access Key", + }, + "second credential type of a plugin with two": { + pluginName: "double", + credentialName: "SSO Profile", + expectedName: "SSO Profile", + }, + "credential type identified by its ID": { + pluginName: "double", + credentialName: "sso_profile", + expectedName: "SSO Profile", + }, + "credential type the plugin does not have": { + pluginName: "single", + credentialName: "Access Key", + expectedErr: "unknown credential: Access Key (single)", + }, + "plugin without credential types": { + pluginName: "nocredentials", + credentialName: "Access Key", + expectedErr: "unknown credential: Access Key (nocredentials)", + }, + "plugin that is not registered": { + pluginName: "missing", + credentialName: "Access Key", + expectedErr: "unknown plugin: missing", + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + credential, err := GetCredentialType(tc.pluginName, tc.credentialName) + + if tc.expectedErr != "" { + assert.EqualError(t, err, tc.expectedErr) + return + } + require.NoError(t, err) + assert.Equal(t, tc.expectedName, credential.Name) + }) + } +} + +func TestRegistryJSON(t *testing.T) { + useTestRegistry(t, testPlugins(t)...) + + result, err := RegistryJSON() + + require.NoError(t, err) + // A plugin gets a single entry, no matter how many credential types it has, with the management URL + // of the first credential type that has one. Plugins without credential types are left out. + assert.JSONEq(t, `[ + {"platform_name": "Single", "management_url": "https://single.example.com/keys"}, + {"platform_name": "Double", "management_url": "https://double.example.com/sso"} + ]`, string(result)) +} diff --git a/sdk/rpc/server/server_test.go b/sdk/rpc/server/server_test.go new file mode 100644 index 000000000..06ed56c18 --- /dev/null +++ b/sdk/rpc/server/server_test.go @@ -0,0 +1,203 @@ +package server + +import ( + "context" + "net" + "net/rpc" + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/rpc/proto" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const ( + testAccessKey = sdk.CredentialName("Access Key") + testSSOProfile = sdk.CredentialName("SSO Profile") +) + +// markingProvisioner sets an environment variable named after itself, so that a test can tell which +// provisioner handled a call. +type markingProvisioner struct { + name string +} + +func (p markingProvisioner) Description() string { return p.name } + +func (p markingProvisioner) Provision(_ context.Context, _ sdk.ProvisionInput, out *sdk.ProvisionOutput) { + out.AddEnvVar("PROVISIONED_BY", p.name) +} + +func (p markingProvisioner) Deprovision(context.Context, sdk.DeprovisionInput, *sdk.DeprovisionOutput) { +} + +// markingImporter returns an importer that reports a single candidate named after the given name, so +// that a test can tell which importer handled a call. +func markingImporter(name string) sdk.Importer { + return func(_ context.Context, _ sdk.ImportInput, out *sdk.ImportOutput) { + out.Attempts = append(out.Attempts, &sdk.ImportAttempt{ + Candidates: []sdk.ImportCandidate{{NameHint: name}}, + }) + } +} + +// testPluginWithTwoCredentialTypes returns a plugin with two credential types that are both used by +// its only executable. The first usage relies on the default provisioner of its credential type, the +// second usage brings its own. +func testPluginWithTwoCredentialTypes() schema.Plugin { + return schema.Plugin{ + Name: "example", + Platform: schema.PlatformInfo{Name: "Example"}, + Credentials: []schema.CredentialType{ + { + Name: testAccessKey, + DefaultProvisioner: markingProvisioner{name: "access key default"}, + Importer: markingImporter("access key importer"), + }, + { + Name: testSSOProfile, + DefaultProvisioner: markingProvisioner{name: "sso profile default"}, + Importer: markingImporter("sso profile importer"), + }, + }, + Executables: []schema.Executable{ + { + Name: "Example CLI", + Runs: []string{"example"}, + Uses: []schema.CredentialUsage{ + {Name: testAccessKey, Optional: true}, + {Name: testSSOProfile, Optional: true, Provisioner: markingProvisioner{name: "sso profile usage"}}, + }, + }, + }, + } +} + +// connectToTestPlugin serves the given plugin over RPC, in the same way as go-plugin does, and returns +// a client that is connected to it. +func connectToTestPlugin(t *testing.T, plugin schema.Plugin) *rpc.Client { + t.Helper() + + rpcServer := rpc.NewServer() + require.NoError(t, rpcServer.RegisterName("Plugin", newServer(plugin))) + + serverConn, clientConn := net.Pipe() + go rpcServer.ServeConn(serverConn) + + client := rpc.NewClient(clientConn) + t.Cleanup(func() { + _ = client.Close() + }) + return client +} + +func newTestProvisionRequest(id proto.ProvisionerID) proto.ProvisionCredentialRequest { + return proto.ProvisionCredentialRequest{ + ProvisionerID: id, + ProvisionOutput: sdk.ProvisionOutput{ + Environment: map[string]string{}, + CommandLine: []string{"example"}, + Files: map[string]sdk.OutputFile{}, + }, + } +} + +func TestGetPluginWithTwoCredentialTypesOverRPC(t *testing.T) { + client := connectToTestPlugin(t, testPluginWithTwoCredentialTypes()) + + var resp proto.GetPluginResponse + require.NoError(t, client.Call("Plugin.GetPlugin", 0, &resp)) + + require.Len(t, resp.Credentials, 2) + assert.Equal(t, testAccessKey, resp.Credentials[0].Name) + assert.Equal(t, testSSOProfile, resp.Credentials[1].Name) + assert.Equal(t, map[proto.CredentialID]bool{0: true, 1: true}, resp.CredentialHasImporter) + + require.Len(t, resp.Executables, 1) + uses := resp.Executables[0].Uses + require.Len(t, uses, 2) + assert.Equal(t, testAccessKey, uses[0].Name) + assert.True(t, uses[0].Optional) + assert.Equal(t, testSSOProfile, uses[1].Name) + assert.True(t, uses[1].Optional) + assert.Equal(t, map[proto.CredentialUsageID]bool{ + {Executable: 0, Usage: 0}: false, + {Executable: 0, Usage: 1}: true, + }, resp.CredentialUsageHasProvisioner) +} + +func TestProvisionWithTwoCredentialTypesOverRPC(t *testing.T) { + client := connectToTestPlugin(t, testPluginWithTwoCredentialTypes()) + + cases := map[string]struct { + id proto.ProvisionerID + expected string + expectedErr string + }{ + "default provisioner of the first credential type": { + id: proto.ProvisionerID{IsDefaultProvisioner: true, Credential: 0}, + expected: "access key default", + }, + "default provisioner of the second credential type": { + id: proto.ProvisionerID{IsDefaultProvisioner: true, Credential: 1}, + expected: "sso profile default", + }, + "provisioner of the second credential usage": { + id: proto.ProvisionerID{CredentialUsage: proto.CredentialUsageID{Executable: 0, Usage: 1}}, + expected: "sso profile usage", + }, + "first credential usage has no provisioner of its own": { + id: proto.ProvisionerID{CredentialUsage: proto.CredentialUsageID{Executable: 0, Usage: 0}}, + expectedErr: "field not set for plugin.Executables[0].Uses[0].Provisioner.Provisioner", + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + var description string + err := client.Call("Plugin.CredentialProvisionerDescription", tc.id, &description) + if tc.expectedErr != "" { + assert.EqualError(t, err, tc.expectedErr) + return + } + require.NoError(t, err) + assert.Equal(t, tc.expected, description) + + var out sdk.ProvisionOutput + require.NoError(t, client.Call("Plugin.CredentialProvisionerProvision", newTestProvisionRequest(tc.id), &out)) + assert.Equal(t, map[string]string{"PROVISIONED_BY": tc.expected}, out.Environment) + assert.Equal(t, []string{"example"}, out.CommandLine) + }) + } +} + +func TestImportWithTwoCredentialTypesOverRPC(t *testing.T) { + client := connectToTestPlugin(t, testPluginWithTwoCredentialTypes()) + + cases := map[string]struct { + id proto.CredentialID + expected string + }{ + "importer of the first credential type": { + id: 0, + expected: "access key importer", + }, + "importer of the second credential type": { + id: 1, + expected: "sso profile importer", + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + var out sdk.ImportOutput + require.NoError(t, client.Call("Plugin.CredentialImport", proto.ImportCredentialRequest{CredentialID: tc.id}, &out)) + + require.Len(t, out.Attempts, 1) + require.Len(t, out.Attempts[0].Candidates, 1) + assert.Equal(t, tc.expected, out.Attempts[0].Candidates[0].NameHint) + }) + } +} diff --git a/sdk/schema/executable.go b/sdk/schema/executable.go index 2f3858289..61be338d4 100644 --- a/sdk/schema/executable.go +++ b/sdk/schema/executable.go @@ -16,6 +16,10 @@ type Executable struct { Name string // Which credentials the executable requires to run and how these should be provisioned. + // + // The order is significant when there is more than one. 1Password CLI attributes configurations + // that were saved before an executable had several credential usages to the first one, because + // they do not record which usage they belong to. Add new usages after the existing ones. Uses []CredentialUsage // (Optional) A URL to the documentation about this executable. @@ -49,7 +53,9 @@ type CredentialUsage struct { // `NeedsAuth`, which can still be used for more generic authentications opt-outs, such as the help flag. NeedsAuth sdk.NeedsAuthentication - // Whether this credential is needed for the executable to run. If set to true, the executable cannot run without provisioning this credential. + // (Optional) Whether the executable can run without this credential. If set to true, the user can skip + // this credential when configuring the executable. Defaults to false, in which case the credential is + // required. Optional bool } diff --git a/sdk/schema/plugin.go b/sdk/schema/plugin.go index 5c29fc11f..3083736b0 100644 --- a/sdk/schema/plugin.go +++ b/sdk/schema/plugin.go @@ -73,12 +73,6 @@ func (p Plugin) Validate() (bool, ValidationReport) { Severity: ValidationSeverityError, }) - report.AddCheck(ValidationCheck{ - Description: "Has no more than one credential type defined. Plugins with multiple credential types are not supported yet", - Assertion: len(p.Credentials) <= 1, - Severity: ValidationSeverityError, - }) - report.AddCheck(ValidationCheck{ Description: "Credentials referenced in executables are included in the same plugin definition", Assertion: CredentialReferencesInCredentialList(p), @@ -91,6 +85,12 @@ func (p Plugin) Validate() (bool, ValidationReport) { Severity: ValidationSeverityError, }) + report.AddCheck(ValidationCheck{ + Description: "If more than one credential type is defined, each one is used by at least one executable", + Assertion: AllCredentialsUsedWhenMultipleDefined(p), + Severity: ValidationSeverityWarning, + }) + return report.IsValid(), report } @@ -119,6 +119,9 @@ func (p Plugin) DeepValidate() []ValidationReport { return reports } +// MarshalJSON returns the plugin's entry for the plugin registry JSON file. The entry describes the +// platform, not the individual credential types, so a plugin gets one entry no matter how many +// credential types it defines. func (p Plugin) MarshalJSON() ([]byte, error) { if len(p.Credentials) == 0 { return nil, nil @@ -127,14 +130,19 @@ func (p Plugin) MarshalJSON() ([]byte, error) { PlatformName string `json:"platform_name"` ManagementURL string `json:"management_url,omitempty"` }{ - PlatformName: p.Platform.Name, - ManagementURL: func() string { - if p.Credentials[0].ManagementURL != nil { - return p.Credentials[0].ManagementURL.String() - } else { - return "" - } - }(), + PlatformName: p.Platform.Name, + ManagementURL: p.managementURL(), } return json.Marshal(plugin) } + +// managementURL returns the management URL of the first credential type that has one, or an empty +// string if none of the plugin's credential types do. +func (p Plugin) managementURL() string { + for _, credential := range p.Credentials { + if credential.ManagementURL != nil { + return credential.ManagementURL.String() + } + } + return "" +} diff --git a/sdk/schema/plugin_test.go b/sdk/schema/plugin_test.go new file mode 100644 index 000000000..3ea435fcb --- /dev/null +++ b/sdk/schema/plugin_test.go @@ -0,0 +1,255 @@ +package schema + +import ( + "context" + "net/url" + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const ( + testAccessKey = sdk.CredentialName("Access Key") + testSSOProfile = sdk.CredentialName("SSO Profile") +) + +type testProvisioner struct{} + +func (testProvisioner) Description() string { return "Test provisioner" } + +func (testProvisioner) Provision(context.Context, sdk.ProvisionInput, *sdk.ProvisionOutput) {} + +func (testProvisioner) Deprovision(context.Context, sdk.DeprovisionInput, *sdk.DeprovisionOutput) {} + +func testURL(t *testing.T, rawURL string) *url.URL { + t.Helper() + u, err := url.Parse(rawURL) + require.NoError(t, err) + return u +} + +func testCredentialType(t *testing.T, name sdk.CredentialName) CredentialType { + t.Helper() + return CredentialType{ + Name: name, + DocsURL: testURL(t, "https://example.com/docs"), + Fields: []CredentialField{ + { + Name: sdk.FieldName("Secret"), + MarkdownDescription: "The secret used to authenticate to Example.", + Secret: true, + }, + }, + DefaultProvisioner: testProvisioner{}, + Importer: func(context.Context, sdk.ImportInput, *sdk.ImportOutput) {}, + } +} + +// testPluginWithTwoCredentialTypes returns a plugin that offers two credential types, both of which can be +// used by its only executable. +func testPluginWithTwoCredentialTypes(t *testing.T) Plugin { + t.Helper() + + accessKey := testCredentialType(t, testAccessKey) + accessKey.ManagementURL = testURL(t, "https://example.com/access-keys") + + ssoProfile := testCredentialType(t, testSSOProfile) + ssoProfile.ManagementURL = testURL(t, "https://example.com/sso") + + return Plugin{ + Name: "example", + Platform: PlatformInfo{ + Name: "Example", + Homepage: testURL(t, "https://example.com"), + }, + Credentials: []CredentialType{accessKey, ssoProfile}, + Executables: []Executable{ + { + Name: "Example CLI", + Runs: []string{"example"}, + DocsURL: testURL(t, "https://example.com/cli"), + NeedsAuth: func(sdk.NeedsAuthenticationInput) bool { return true }, + Uses: []CredentialUsage{ + {Name: testAccessKey, Optional: true}, + {Name: testSSOProfile, Optional: true}, + }, + }, + }, + } +} + +// failedChecks returns the descriptions of all checks that did not pass, warnings included. +func failedChecks(report ValidationReport) []string { + var failed []string + for _, check := range report.Checks { + if !check.Assertion { + failed = append(failed, check.Description) + } + } + return failed +} + +func TestPluginValidate(t *testing.T) { + const ( + credentialsUsedCheck = "If more than one credential type is defined, each one is used by at least one executable" + uniqueCredentialsCheck = "Credentials are uniquely identifiable inside a plugin" + referencesCheck = "Credentials referenced in executables are included in the same plugin definition" + ) + + cases := map[string]struct { + modify func(p *Plugin) + expectedFailed []string + // expectedError is whether one of the failed checks is an error instead of a warning. + expectedError bool + }{ + "two credential types that are both used": { + modify: func(p *Plugin) {}, + }, + "two credential types that are used by different executables": { + modify: func(p *Plugin) { + other := p.Executables[0] + other.Name = "Other Example CLI" + other.Runs = []string{"other-example"} + other.Uses = []CredentialUsage{{Name: testSSOProfile}} + p.Executables[0].Uses = []CredentialUsage{{Name: testAccessKey}} + p.Executables = append(p.Executables, other) + }, + }, + "two credential types and no executables": { + modify: func(p *Plugin) { + p.Executables = nil + }, + }, + "one credential type that is not used by the executable": { + modify: func(p *Plugin) { + p.Credentials = p.Credentials[:1] + p.Executables[0].Uses = []CredentialUsage{ + {SelectFrom: &CredentialSelection{ID: "project", IncludeAllCredentials: true}}, + } + }, + }, + "two credential types of which one is used with the plugin named explicitly": { + modify: func(p *Plugin) { + p.Executables[0].Uses[1].Plugin = p.Name + }, + }, + "two credential types of which one is only reachable through a selection of all credentials": { + modify: func(p *Plugin) { + p.Executables[0].Uses[1] = CredentialUsage{ + SelectFrom: &CredentialSelection{ID: "project", IncludeAllCredentials: true}, + } + }, + }, + "two credential types and an executable that only has a selection of all credentials": { + modify: func(p *Plugin) { + p.Executables[0].Uses = []CredentialUsage{ + {SelectFrom: &CredentialSelection{ID: "project", IncludeAllCredentials: true}}, + } + }, + }, + "two credential types of which one is not used by any executable": { + modify: func(p *Plugin) { + p.Executables[0].Uses = []CredentialUsage{{Name: testAccessKey}} + }, + expectedFailed: []string{credentialsUsedCheck}, + }, + "two credential types of which one is only used through another plugin's name": { + modify: func(p *Plugin) { + p.Executables[0].Uses[1].Plugin = "otherplugin" + }, + expectedFailed: []string{credentialsUsedCheck}, + }, + "two credential types with the same name": { + modify: func(p *Plugin) { + p.Credentials[1].Name = testAccessKey + p.Executables[0].Uses = []CredentialUsage{{Name: testAccessKey}} + }, + expectedFailed: []string{uniqueCredentialsCheck}, + expectedError: true, + }, + "executable uses a credential type that the plugin does not define": { + modify: func(p *Plugin) { + p.Credentials = p.Credentials[:1] + }, + expectedFailed: []string{referencesCheck}, + expectedError: true, + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + plugin := testPluginWithTwoCredentialTypes(t) + tc.modify(&plugin) + + valid, report := plugin.Validate() + + assert.Equal(t, tc.expectedFailed, failedChecks(report)) + assert.Equal(t, len(tc.expectedFailed) == 0, valid) + assert.Equal(t, tc.expectedError, report.HasErrors()) + }) + } +} + +func TestPluginDeepValidateWithTwoCredentialTypes(t *testing.T) { + plugin := testPluginWithTwoCredentialTypes(t) + + reports := plugin.DeepValidate() + + // One report for the plugin, one per credential type, one for the executable and one per credential usage. + require.Len(t, reports, 6) + for _, report := range reports { + assert.Empty(t, failedChecks(report), report.Heading) + } +} + +func TestPluginMarshalJSON(t *testing.T) { + cases := map[string]struct { + modify func(p *Plugin) + expected string + }{ + "one credential type": { + modify: func(p *Plugin) { + p.Credentials = p.Credentials[:1] + }, + expected: `{"platform_name":"Example","management_url":"https://example.com/access-keys"}`, + }, + "one credential type without a management URL": { + modify: func(p *Plugin) { + p.Credentials = p.Credentials[:1] + p.Credentials[0].ManagementURL = nil + }, + expected: `{"platform_name":"Example"}`, + }, + "two credential types use the management URL of the first": { + modify: func(p *Plugin) {}, + expected: `{"platform_name":"Example","management_url":"https://example.com/access-keys"}`, + }, + "two credential types of which only the second has a management URL": { + modify: func(p *Plugin) { + p.Credentials[0].ManagementURL = nil + }, + expected: `{"platform_name":"Example","management_url":"https://example.com/sso"}`, + }, + "two credential types without a management URL": { + modify: func(p *Plugin) { + p.Credentials[0].ManagementURL = nil + p.Credentials[1].ManagementURL = nil + }, + expected: `{"platform_name":"Example"}`, + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + plugin := testPluginWithTwoCredentialTypes(t) + tc.modify(&plugin) + + result, err := plugin.MarshalJSON() + + require.NoError(t, err) + assert.Equal(t, tc.expected, string(result)) + }) + } +} diff --git a/sdk/schema/validation.go b/sdk/schema/validation.go index 679b04d7a..bdf35d932 100644 --- a/sdk/schema/validation.go +++ b/sdk/schema/validation.go @@ -124,6 +124,41 @@ func NoDuplicateCredentials(plugin Plugin) bool { return IsStringSliceASet(ids) } +// AllCredentialsUsedWhenMultipleDefined reports whether every credential type of a plugin that defines +// more than one can be chosen for at least one of the plugin's executables. A credential type that no +// executable uses usually means it was added to the plugin definition but not to its executables. +// +// A credential type counts as used when an executable names it, or when an executable lets the user +// select from all credential types. Plugins with a single credential type, or without executables, +// always pass. +// +// This cannot see the executables of other plugins, so it also reports a credential type that is only +// offered for other plugins to use. That is why the corresponding validation check is a warning. +func AllCredentialsUsedWhenMultipleDefined(plugin Plugin) bool { + if len(plugin.Credentials) <= 1 || len(plugin.Executables) == 0 { + return true + } + + used := map[string]bool{} + for _, executable := range plugin.Executables { + for _, usage := range executable.Uses { + if usage.SelectFrom != nil && usage.SelectFrom.IncludeAllCredentials { + return true + } + if usage.Name != "" && (usage.Plugin == "" || usage.Plugin == plugin.Name) { + used[usage.Name.ID().String()] = true + } + } + } + + for _, credential := range plugin.Credentials { + if !used[credential.Name.ID().String()] { + return false + } + } + return true +} + func AreCredentialUsagesUniquelyIdentifiable(executable Executable) bool { var usageIds []string for _, credentialUsage := range executable.Uses {