From 03867ac3fbfdb2f199da20fc19aa2eeeee4c4be3 Mon Sep 17 00:00:00 2001 From: Marco Dinis Date: Wed, 16 Oct 2024 13:49:43 +0100 Subject: [PATCH] move descriptions from api to lib --- api/types/usertasks/object.go | 17 -------- api/types/usertasks/object_test.go | 6 --- lib/usertasks/descriptions.go | 39 +++++++++++++++++++ .../ec2-ssm-agent-connection-lost.md | 0 .../ec2-ssm-agent-not-registered.md | 0 .../ec2-ssm-invocation-failure.md | 0 .../descriptions/ec2-ssm-script-failure.md | 0 .../descriptions/ec2-ssm-unsupported-os.md | 0 lib/usertasks/descriptions_test.go | 33 ++++++++++++++++ lib/web/ui/usertask.go | 2 +- 10 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 lib/usertasks/descriptions.go rename {api/types => lib}/usertasks/descriptions/ec2-ssm-agent-connection-lost.md (100%) rename {api/types => lib}/usertasks/descriptions/ec2-ssm-agent-not-registered.md (100%) rename {api/types => lib}/usertasks/descriptions/ec2-ssm-invocation-failure.md (100%) rename {api/types => lib}/usertasks/descriptions/ec2-ssm-script-failure.md (100%) rename {api/types => lib}/usertasks/descriptions/ec2-ssm-unsupported-os.md (100%) create mode 100644 lib/usertasks/descriptions_test.go diff --git a/api/types/usertasks/object.go b/api/types/usertasks/object.go index dd29d203f58ac..9ac05733ac969 100644 --- a/api/types/usertasks/object.go +++ b/api/types/usertasks/object.go @@ -19,9 +19,7 @@ package usertasks import ( - "embed" "encoding/binary" - "fmt" "slices" "strconv" "time" @@ -156,21 +154,6 @@ const ( AutoDiscoverEC2IssueSSMInvocationFailure = "ec2-ssm-invocation-failure" ) -//go:embed descriptions/*.md -var descriptionsFS embed.FS - -// DescriptionForDiscoverEC2Issue returns the description of the issue and fixing steps. -// The returned string contains a markdown document. -// If issue type is not recognized or doesn't have a specific description, them an empty string is returned. -func DescriptionForDiscoverEC2Issue(issueType string) string { - filename := fmt.Sprintf("descriptions/%s.md", issueType) - bs, err := descriptionsFS.ReadFile(filename) - if err != nil { - return "" - } - return string(bs) -} - // DiscoverEC2IssueTypes is a list of issue types that can occur when trying to auto enroll EC2 instances. var DiscoverEC2IssueTypes = []string{ AutoDiscoverEC2IssueSSMInstanceNotRegistered, diff --git a/api/types/usertasks/object_test.go b/api/types/usertasks/object_test.go index 1e09316e77351..396a18613502d 100644 --- a/api/types/usertasks/object_test.go +++ b/api/types/usertasks/object_test.go @@ -465,9 +465,3 @@ func TestNewDiscoverEKSUserTask(t *testing.T) { }) } } - -func TestAllDescriptions(t *testing.T) { - for _, issueType := range usertasks.DiscoverEC2IssueTypes { - require.NotEmpty(t, usertasks.DescriptionForDiscoverEC2Issue(issueType), "issue type %q is missing descriptions/%s.md file", issueType, issueType) - } -} diff --git a/lib/usertasks/descriptions.go b/lib/usertasks/descriptions.go new file mode 100644 index 0000000000000..eb1655fee5ea7 --- /dev/null +++ b/lib/usertasks/descriptions.go @@ -0,0 +1,39 @@ +/* + * Teleport + * Copyright (C) 2024 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package usertasks + +import ( + "embed" + "fmt" +) + +//go:embed descriptions/*.md +var descriptionsFS embed.FS + +// DescriptionForDiscoverEC2Issue returns the description of the issue and fixing steps. +// The returned string contains a markdown document. +// If issue type is not recognized or doesn't have a specific description, them an empty string is returned. +func DescriptionForDiscoverEC2Issue(issueType string) string { + filename := fmt.Sprintf("descriptions/%s.md", issueType) + bs, err := descriptionsFS.ReadFile(filename) + if err != nil { + return "" + } + return string(bs) +} diff --git a/api/types/usertasks/descriptions/ec2-ssm-agent-connection-lost.md b/lib/usertasks/descriptions/ec2-ssm-agent-connection-lost.md similarity index 100% rename from api/types/usertasks/descriptions/ec2-ssm-agent-connection-lost.md rename to lib/usertasks/descriptions/ec2-ssm-agent-connection-lost.md diff --git a/api/types/usertasks/descriptions/ec2-ssm-agent-not-registered.md b/lib/usertasks/descriptions/ec2-ssm-agent-not-registered.md similarity index 100% rename from api/types/usertasks/descriptions/ec2-ssm-agent-not-registered.md rename to lib/usertasks/descriptions/ec2-ssm-agent-not-registered.md diff --git a/api/types/usertasks/descriptions/ec2-ssm-invocation-failure.md b/lib/usertasks/descriptions/ec2-ssm-invocation-failure.md similarity index 100% rename from api/types/usertasks/descriptions/ec2-ssm-invocation-failure.md rename to lib/usertasks/descriptions/ec2-ssm-invocation-failure.md diff --git a/api/types/usertasks/descriptions/ec2-ssm-script-failure.md b/lib/usertasks/descriptions/ec2-ssm-script-failure.md similarity index 100% rename from api/types/usertasks/descriptions/ec2-ssm-script-failure.md rename to lib/usertasks/descriptions/ec2-ssm-script-failure.md diff --git a/api/types/usertasks/descriptions/ec2-ssm-unsupported-os.md b/lib/usertasks/descriptions/ec2-ssm-unsupported-os.md similarity index 100% rename from api/types/usertasks/descriptions/ec2-ssm-unsupported-os.md rename to lib/usertasks/descriptions/ec2-ssm-unsupported-os.md diff --git a/lib/usertasks/descriptions_test.go b/lib/usertasks/descriptions_test.go new file mode 100644 index 0000000000000..30a358ae1ea9d --- /dev/null +++ b/lib/usertasks/descriptions_test.go @@ -0,0 +1,33 @@ +/* + * Teleport + * Copyright (C) 2024 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package usertasks + +import ( + "testing" + + "github.com/stretchr/testify/require" + + usertasksapi "github.com/gravitational/teleport/api/types/usertasks" +) + +func TestAllDescriptions(t *testing.T) { + for _, issueType := range usertasksapi.DiscoverEC2IssueTypes { + require.NotEmpty(t, DescriptionForDiscoverEC2Issue(issueType), "issue type %q is missing descriptions/%s.md file", issueType, issueType) + } +} diff --git a/lib/web/ui/usertask.go b/lib/web/ui/usertask.go index 0d06827a74683..02b174aeb1782 100644 --- a/lib/web/ui/usertask.go +++ b/lib/web/ui/usertask.go @@ -24,7 +24,7 @@ import ( "github.com/gravitational/trace" usertasksv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/usertasks/v1" - "github.com/gravitational/teleport/api/types/usertasks" + "github.com/gravitational/teleport/lib/usertasks" ) // UserTask describes UserTask fields.