Skip to content

feat: add support for template version messages in api and cli #8336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 11, 2023
Merged
Prev Previous commit
Next Next commit
limit message length
  • Loading branch information
mafredri committed Jul 6, 2023
commit 5bee51f3a75d8c78446480f6adb785ee5ef64179
4 changes: 4 additions & 0 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -3921,6 +3921,10 @@ func (q *fakeQuerier) InsertTemplateVersion(_ context.Context, arg database.Inse
return database.TemplateVersion{}, err
}

if len(arg.Message) > 1048576 {
return database.TemplateVersion{}, xerrors.New("message too long")
}

q.mutex.Lock()
defer q.mutex.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE template_versions ADD COLUMN message text NOT NULL DEFAULT '';
ALTER TABLE template_versions ADD COLUMN message varchar(1048576) NOT NULL DEFAULT '';

COMMENT ON COLUMN template_versions.message IS 'Message describing the changes in this version of the template, similar to a Git commit message. Like a commit message, this should be a short, high-level description of the changes in this version of the template. This message is immutable and should not be updated after the fact.';
21 changes: 21 additions & 0 deletions coderd/templateversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"net/http"
"regexp"
"strings"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -51,6 +52,26 @@ func TestTemplateVersion(t *testing.T) {
assert.Equal(t, "first try", tv.Message)
})

t.Run("Message limit exceeded", func(t *testing.T) {
t.Parallel()
client, _, _ := coderdtest.NewWithAPI(t, nil)
user := coderdtest.CreateFirstUser(t, client)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

file, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader([]byte{}))
require.NoError(t, err)
_, err = client.CreateTemplateVersion(ctx, user.OrganizationID, codersdk.CreateTemplateVersionRequest{
Name: "bananas",
Message: strings.Repeat("a", 1048577),
StorageMethod: codersdk.ProvisionerStorageMethodFile,
FileID: file.ID,
Provisioner: codersdk.ProvisionerTypeEcho,
})
require.Error(t, err, "message too long, create should fail")
})

t.Run("MemberCanRead", func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion codersdk/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type OrganizationMember struct {
// CreateTemplateVersionRequest enables callers to create a new Template Version.
type CreateTemplateVersionRequest struct {
Name string `json:"name,omitempty" validate:"omitempty,template_version_name"`
Message string `json:"message,omitempty"`
Message string `json:"message,omitempty" validate:"lt=1048577"` // Database limit: 1048576.
// TemplateID optionally associates a version with a template.
TemplateID uuid.UUID `json:"template_id,omitempty" format:"uuid"`
StorageMethod ProvisionerStorageMethod `json:"storage_method" validate:"oneof=file,required" enums:"file"`
Expand Down