Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/garm-cli/cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os"
"strings"

"github.com/go-openapi/strfmt"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -101,7 +102,7 @@ var templateCreateCmd = &cobra.Command{
createTemplateReq.Body.ForgeType = forge
createTemplateReq.Body.OSType = osType
createTemplateReq.Body.Description = templateDescription
createTemplateReq.Body.Data = data
createTemplateReq.Body.Data = strfmt.Base64(data)

response, err := apiCli.Templates.CreateTemplate(createTemplateReq, authToken)
if err != nil {
Expand Down Expand Up @@ -156,7 +157,7 @@ var templateUpdateCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to read template file: %q", err)
}
updateReq.Body.Data = data
updateReq.Body.Data = strfmt.Base64(data)
changes = true
}
if !changes {
Expand Down Expand Up @@ -271,7 +272,7 @@ var templateDownloadCmd = &cobra.Command{
return fmt.Errorf("destination path already exists; will not overwrite")
}

if err := os.WriteFile(templatePath, response.Payload.Data, 0o600); err != nil {
if err := os.WriteFile(templatePath, []byte(response.Payload.Data), 0o600); err != nil {
return fmt.Errorf("failed to save file %s: %s", templatePath, err)
}
return nil
Expand Down Expand Up @@ -445,7 +446,7 @@ var templateEditCmd = &cobra.Command{
if saved && newContent != string(response.Payload.Data) {
updateReq := apiTemplates.NewUpdateTemplateParams()
updateReq.TemplateID = float64(response.Payload.ID)
updateReq.Body.Data = []byte(newContent)
updateReq.Body.Data = strfmt.Base64(newContent)

_, err = apiCli.Templates.UpdateTemplate(updateReq, authToken)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion database/sql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"log/slog"

"github.com/go-openapi/strfmt"
"github.com/google/uuid"
"gorm.io/datatypes"
"gorm.io/gorm"
Expand Down Expand Up @@ -1133,7 +1134,7 @@ func (s *sqlDatabase) sqlToParamTemplate(template Template) (params.Template, er
UpdatedAt: template.UpdatedAt,
Name: template.Name,
Description: template.Description,
Data: data,
Data: strfmt.Base64(data),
ForgeType: template.ForgeType,
Owner: owner,
OSType: template.OSType,
Expand Down
3 changes: 2 additions & 1 deletion params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/go-openapi/strfmt"
"github.com/google/go-github/v84/github"
"github.com/google/uuid"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -1489,7 +1490,7 @@ type Template struct {
Description string `json:"description"`
OSType commonParams.OSType `json:"os_type"`
ForgeType EndpointType `json:"forge_type,omitempty"`
Data []byte `json:"data"`
Data strfmt.Base64 `json:"data"`
Owner string `json:"owner_id,omitempty"`
}

Expand Down
9 changes: 5 additions & 4 deletions params/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
commonParams "github.com/cloudbase/garm-provider-common/params"
commonUtil "github.com/cloudbase/garm-provider-common/util"
"github.com/go-openapi/strfmt"
)

const (
Expand Down Expand Up @@ -877,7 +878,7 @@ func (u UpdateGiteaCredentialsParams) Validate() error {
type CreateTemplateParams struct {
Name string `json:"name"`
Description string `json:"description"`
Data []byte `json:"data"`
Data strfmt.Base64 `json:"data"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just add:

// swagger:strfmt byte
Data        []byte              `json:"data"`

and

// go:generate go run github.com/go-swagger/go-swagger/cmd/swagger@v0.33.1 generate spec --output=../swagger.yaml --scan-models --work-dir=../../

will do the right thing.

@gabriel-samfira gabriel-samfira Jun 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the annotations in #800. Will probably split that out and merge separately.

OSType commonParams.OSType `json:"os_type"`
ForgeType EndpointType `json:"forge_type,omitempty"`
IsSystem bool `json:"-"`
Expand Down Expand Up @@ -908,9 +909,9 @@ func (c *CreateTemplateParams) Validate() error {

// swagger:model UpdateTemplateParams
type UpdateTemplateParams struct {
Name *string `json:"name"`
Description *string `json:"description"`
Data []byte `json:"data"`
Name *string `json:"name"`
Description *string `json:"description"`
Data strfmt.Base64 `json:"data"`
}

func (u *UpdateTemplateParams) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion runner/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (r *Runner) GetRunnerInstallScript(ctx context.Context) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("failed to get template: %w", err)
}
tplBytes = template.Data
tplBytes = []byte(template.Data)
}

installScript, err := templates.RenderRunnerInstallScript(string(tplBytes), tplCtx)
Expand Down
4 changes: 2 additions & 2 deletions runner/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (s *TemplateTestSuite) TestRestoreTemplateSpecific() {
updatedTemplate, err := s.Runner.GetTemplate(s.adminCtx, systemTemplate.ID)
s.Require().Nil(err)
s.Require().Equal(modifiedName, updatedTemplate.Name)
s.Require().Equal(modifiedData, updatedTemplate.Data)
s.Require().Equal(modifiedData, []byte(updatedTemplate.Data))

restoreParams := params.RestoreTemplateRequest{
Forge: params.GithubEndpointType,
Expand All @@ -365,7 +365,7 @@ func (s *TemplateTestSuite) TestRestoreTemplateSpecific() {
// Name should be restored to the system default
s.Require().Equal("github_linux", restoredTemplate.Name)
// Data should be restored to original template content (not the modified content)
s.Require().NotEqual(modifiedData, restoredTemplate.Data)
s.Require().NotEqual(modifiedData, []byte(restoredTemplate.Data))
// Should match the original template data or be close to it (content from internal/templates)
s.Require().NotEmpty(restoredTemplate.Data)
// Verify it's still a system template
Expand Down
12 changes: 6 additions & 6 deletions webapp/src/lib/api/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,10 @@ export interface CreateScaleSetParams {
export interface CreateTemplateParams {
/**
*
* @type {Array<number>}
* @type {string}
* @memberof CreateTemplateParams
*/
'data'?: Array<number>;
'data'?: string;
/**
*
* @type {string}
Expand Down Expand Up @@ -2913,10 +2913,10 @@ export interface Template {
'created_at'?: string;
/**
*
* @type {Array<number>}
* @type {string}
* @memberof Template
*/
'data'?: Array<number>;
'data'?: string;
/**
*
* @type {string}
Expand Down Expand Up @@ -3421,10 +3421,10 @@ export interface UpdateScaleSetParams {
export interface UpdateTemplateParams {
/**
*
* @type {Array<number>}
* @type {string}
* @memberof UpdateTemplateParams
*/
'data'?: Array<number>;
'data'?: string;
/**
*
* @type {string}
Expand Down
18 changes: 6 additions & 12 deletions webapp/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,9 @@ definitions:
CreateTemplateParams:
properties:
data:
items:
format: uint8
type: integer
type: array
type: string
x-go-name: Data
x-go-type: github.com/go-openapi/strfmt.Base64
description:
type: string
x-go-name: Description
Expand Down Expand Up @@ -1898,11 +1896,9 @@ definitions:
type: string
x-go-name: CreatedAt
data:
items:
format: uint8
type: integer
type: array
type: string
x-go-name: Data
x-go-type: github.com/go-openapi/strfmt.Base64
description:
type: string
x-go-name: Description
Expand Down Expand Up @@ -2188,11 +2184,9 @@ definitions:
UpdateTemplateParams:
properties:
data:
items:
format: uint8
type: integer
type: array
type: string
x-go-name: Data
x-go-type: github.com/go-openapi/strfmt.Base64
description:
type: string
x-go-name: Description
Expand Down