From 40103275dff0502f8e551cde375cec36101d97a2 Mon Sep 17 00:00:00 2001 From: alteredCoder Date: Tue, 26 Oct 2021 14:43:23 +0200 Subject: [PATCH] remove alias and tag from cscli console --- cmd/crowdsec-cli/console.go | 9 +-------- pkg/apiclient/auth_service.go | 8 +++----- pkg/apiclient/auth_service_test.go | 4 ++-- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/cmd/crowdsec-cli/console.go b/cmd/crowdsec-cli/console.go index ef974a3c1..f8f9364be 100644 --- a/cmd/crowdsec-cli/console.go +++ b/cmd/crowdsec-cli/console.go @@ -85,9 +85,6 @@ func NewConsoleCmd() *cobra.Command { }, } - name := "" - tags := []string{} - cmdEnroll := &cobra.Command{ Use: "enroll [enroll-key]", Short: "Enroll this instance to https://app.crowdsec.net [requires local API]", @@ -97,8 +94,6 @@ Enroll this instance to https://app.crowdsec.net You can get your enrollment key by creating an account on https://app.crowdsec.net. After running this command your will need to validate the enrollment in the webapp.`, Example: `cscli console enroll YOUR-ENROLL-KEY -cscli console enroll --name [instance_name] YOUR-ENROLL-KEY -cscli console enroll --name [instance_name] --tags [tag_1] --tags [tag_2] YOUR-ENROLL-KEY `, Args: cobra.ExactArgs(1), DisableAutoGenTag: true, @@ -135,15 +130,13 @@ cscli console enroll --name [instance_name] --tags [tag_1] --tags [tag_2] YOUR-E URL: apiURL, VersionPrefix: "v2", }) - _, err = c.Auth.EnrollWatcher(context.Background(), args[0], name, tags) + _, err = c.Auth.EnrollWatcher(context.Background(), args[0]) if err != nil { log.Fatalf("Could not enroll instance: %s", err) } log.Infof("Watcher successfully enrolled. Visit https://app.crowdsec.net to accept it.") }, } - cmdEnroll.Flags().StringVarP(&name, "name", "n", "", "Name to appear in the console") - cmdEnroll.Flags().StringSliceVarP(&tags, "tags", "t", tags, "Tags to appear in the console") cmdConsole.AddCommand(cmdEnroll) var enableAll, disableAll bool diff --git a/pkg/apiclient/auth_service.go b/pkg/apiclient/auth_service.go index 6809aba30..632fb8778 100644 --- a/pkg/apiclient/auth_service.go +++ b/pkg/apiclient/auth_service.go @@ -13,9 +13,7 @@ type AuthService service // Don't add it to the models, as they are used with LAPI, but the enroll endpoint is specific to CAPI type enrollRequest struct { - EnrollKey string `json:"attachment_key"` - Name string `json:"name"` - Tags []string `json:"tags"` + EnrollKey string `json:"attachment_key"` } func (s *AuthService) UnregisterWatcher(ctx context.Context) (*Response, error) { @@ -63,9 +61,9 @@ func (s *AuthService) AuthenticateWatcher(ctx context.Context, auth models.Watch return resp, nil } -func (s *AuthService) EnrollWatcher(ctx context.Context, enrollKey string, name string, tags []string) (*Response, error) { +func (s *AuthService) EnrollWatcher(ctx context.Context, enrollKey string) (*Response, error) { u := fmt.Sprintf("%s/watchers/enroll", s.client.URLPrefix) - req, err := s.client.NewRequest("POST", u, &enrollRequest{EnrollKey: enrollKey, Name: name, Tags: tags}) + req, err := s.client.NewRequest("POST", u, &enrollRequest{EnrollKey: enrollKey}) if err != nil { return nil, err } diff --git a/pkg/apiclient/auth_service_test.go b/pkg/apiclient/auth_service_test.go index 460d662a1..379769c3b 100644 --- a/pkg/apiclient/auth_service_test.go +++ b/pkg/apiclient/auth_service_test.go @@ -228,11 +228,11 @@ func TestWatcherEnroll(t *testing.T) { log.Fatalf("new api client: %s", err.Error()) } - _, err = client.Auth.EnrollWatcher(context.Background(), "goodkey", "", []string{}) + _, err = client.Auth.EnrollWatcher(context.Background(), "goodkey") if err != nil { t.Fatalf("unexpect enroll err: %s", err) } - _, err = client.Auth.EnrollWatcher(context.Background(), "badkey", "", []string{}) + _, err = client.Auth.EnrollWatcher(context.Background(), "badkey") assert.Contains(t, err.Error(), "the attachment key provided is not valid") }