Skip to content

Commit af0b949

Browse files
authored
Merge pull request #184 from nerdynick/Confluent-CLI
Adds support for the Confluent CLI against Confluent Cloud
2 parents 5ff6634 + 2ffbdbf commit af0b949

5 files changed

Lines changed: 221 additions & 0 deletions

File tree

plugins/confluent/confluent.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package confluent
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/needsauth"
6+
"github.com/1Password/shell-plugins/sdk/schema"
7+
"github.com/1Password/shell-plugins/sdk/schema/credname"
8+
)
9+
10+
func ConfluentCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Confluent CLI",
13+
Runs: []string{"confluent"},
14+
DocsURL: sdk.URL("https://docs.confluent.io/confluent-cli/current/overview.html"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotForExactArgs("local"),
18+
needsauth.NotForExactArgs("update"),
19+
needsauth.NotForExactArgs("prompt"),
20+
needsauth.NotForExactArgs("plugin"),
21+
needsauth.NotForExactArgs("logout"),
22+
needsauth.NotForExactArgs("context"),
23+
needsauth.NotForExactArgs("completion"),
24+
needsauth.NotForExactArgs("cloud-signup"),
25+
),
26+
Uses: []schema.CredentialUsage{
27+
{
28+
Name: credname.UserLogin,
29+
},
30+
},
31+
}
32+
}

plugins/confluent/credentials.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package confluent
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/importer"
6+
"github.com/1Password/shell-plugins/sdk/provision"
7+
"github.com/1Password/shell-plugins/sdk/schema"
8+
"github.com/1Password/shell-plugins/sdk/schema/credname"
9+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
10+
)
11+
12+
func CloudCredentials() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.UserLogin,
15+
DocsURL: sdk.URL("https://docs.confluent.io/cloud/current/access-management/identity/user-accounts.html#local-user-username-password"),
16+
ManagementURL: sdk.URL("https://confluent.cloud"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.Username,
20+
MarkdownDescription: "Email used to authenticate to Confluent Cloud.",
21+
Secret: false,
22+
Optional: false,
23+
},
24+
{
25+
Name: fieldname.Password,
26+
MarkdownDescription: "Password used to authenticate to Confluent Cloud.",
27+
Secret: true,
28+
Optional: false,
29+
},
30+
{
31+
Name: fieldname.Organization,
32+
MarkdownDescription: "Organization to use with Confluent Cloud.",
33+
Secret: false,
34+
Optional: true,
35+
},
36+
},
37+
DefaultProvisioner: provision.EnvVars(defaultCloudEnvVarMapping),
38+
Importer: importer.TryAll(
39+
importer.TryEnvVarPair(defaultCloudEnvVarMapping),
40+
)}
41+
}
42+
43+
var defaultCloudEnvVarMapping = map[string]sdk.FieldName{
44+
"CONFLUENT_CLOUD_EMAIL": fieldname.Username,
45+
"CONFLUENT_CLOUD_PASSWORD": fieldname.Password,
46+
"CONFLUENT_CLOUD_ORGANIZATION_ID": fieldname.Organization,
47+
}
48+
49+
//TODO: Revist once the Shell Plugins ecosystem adds support for multiple credential types per plugin
50+
// func PlatformCredentials() schema.CredentialType {
51+
// return schema.CredentialType{
52+
// Name: credname.Credentials,
53+
// DocsURL: sdk.URL("https://docs.confluent.io/confluent-cli/current/command-reference/confluent_login.html"),
54+
// Fields: []schema.CredentialField{
55+
// {
56+
// Name: fieldname.Username,
57+
// MarkdownDescription: "Username used to authenticate to Confluent Platform.",
58+
// Secret: false,
59+
// Optional: false,
60+
// },
61+
// {
62+
// Name: fieldname.Password,
63+
// MarkdownDescription: "Password used to authenticate to Confluent Platform.",
64+
// Secret: true,
65+
// Optional: false,
66+
// },
67+
// {
68+
// Name: fieldname.URL,
69+
// MarkdownDescription: "Metadata Service (MDS) URL used to authenticate to Confluent Platform.",
70+
// Secret: false,
71+
// Optional: false,
72+
// },
73+
// {
74+
// Name: fieldname.Certificate,
75+
// MarkdownDescription: "Self-signed certificate chain in PEM format.",
76+
// Secret: true,
77+
// Optional: false,
78+
// },
79+
// },
80+
// DefaultProvisioner: provision.EnvVars(defaultPlatformEnvVarMapping),
81+
// Importer: importer.TryAll(
82+
// importer.TryEnvVarPair(defaultPlatformEnvVarMapping),
83+
// )}
84+
// }
85+
86+
// var defaultPlatformEnvVarMapping = map[string]sdk.FieldName{
87+
// "CONFLUENT_PLATFORM_USERNAME": fieldname.Username,
88+
// "CONFLUENT_PLATFORM_PASSWORD": fieldname.Password,
89+
// "CONFLUENT_PLATFORM_MDS_URL": fieldname.URL,
90+
// "CONFLUENT_PLATFORM_CA_CERT_PATH": fieldname.Certificate,
91+
// }
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package confluent
2+
3+
import (
4+
"testing"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/plugintest"
8+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
9+
)
10+
11+
func TestCloudCredentialsProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, CloudCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Username: "test@example.com",
16+
},
17+
ExpectedOutput: sdk.ProvisionOutput{
18+
Environment: map[string]string{
19+
"CONFLUENT_CLOUD_EMAIL": "test@example.com",
20+
},
21+
},
22+
},
23+
})
24+
}
25+
26+
func TestCloudCredentialsImporter(t *testing.T) {
27+
plugintest.TestImporter(t, CloudCredentials().Importer, map[string]plugintest.ImportCase{
28+
"environment": {
29+
Environment: map[string]string{
30+
"CONFLUENT_CLOUD_EMAIL": "test@example.com",
31+
},
32+
ExpectedCandidates: []sdk.ImportCandidate{
33+
{
34+
Fields: map[sdk.FieldName]string{
35+
fieldname.Username: "test@example.com",
36+
},
37+
},
38+
},
39+
},
40+
})
41+
}
42+
43+
//TODO: Revist once the Shell Plugins ecosystem adds support for multiple credential types per plugin
44+
// func TestPlatformCredentialsProvisioner(t *testing.T) {
45+
// plugintest.TestProvisioner(t, PlatformCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{
46+
// "default": {
47+
// ItemFields: map[sdk.FieldName]string{
48+
// fieldname.Username: "someusername",
49+
// },
50+
// ExpectedOutput: sdk.ProvisionOutput{
51+
// Environment: map[string]string{
52+
// "CONFLUENT_PLATFORM_USERNAME": "someusername",
53+
// },
54+
// },
55+
// },
56+
// })
57+
// }
58+
59+
// func TestPlatformCredentialsImporter(t *testing.T) {
60+
// plugintest.TestImporter(t, PlatformCredentials().Importer, map[string]plugintest.ImportCase{
61+
// "environment": {
62+
// Environment: map[string]string{
63+
// "CONFLUENT_PLATFORM_USERNAME": "someusername",
64+
// },
65+
// ExpectedCandidates: []sdk.ImportCandidate{
66+
// {
67+
// Fields: map[sdk.FieldName]string{
68+
// fieldname.Username: "someusername",
69+
// },
70+
// },
71+
// },
72+
// },
73+
// })
74+
// }

plugins/confluent/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package confluent
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/schema"
6+
)
7+
8+
func New() schema.Plugin {
9+
return schema.Plugin{
10+
Name: "confluent",
11+
Platform: schema.PlatformInfo{
12+
Name: "Confluent",
13+
Homepage: sdk.URL("https://confluent.io"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
CloudCredentials(),
17+
},
18+
Executables: []schema.Executable{
19+
ConfluentCLI(),
20+
},
21+
}
22+
}

sdk/schema/credname/names.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
PersonalAccessToken = sdk.CredentialName("Personal Access Token")
2222
RegistryCredentials = sdk.CredentialName("Registry Credentials")
2323
SecretKey = sdk.CredentialName("Secret Key")
24+
UserLogin = sdk.CredentialName("User Login")
2425
)
2526

2627
func ListAll() []sdk.CredentialName {
@@ -42,5 +43,6 @@ func ListAll() []sdk.CredentialName {
4243
PersonalAccessToken,
4344
RegistryCredentials,
4445
SecretKey,
46+
UserLogin,
4547
}
4648
}

0 commit comments

Comments
 (0)