Skip to content

Commit

Permalink
fix(applicationVersions): activate binary when creating new plugin an…
Browse files Browse the repository at this point in the history
…d assign latest tag
  • Loading branch information
reubenmiller committed Apr 26, 2024
1 parent 9a4f735 commit ef2b1d4
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pkg/c8y/uiExtension.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
// WARNING: THE UI Extension Service API is not yet finalized so expect changes in the future!
type UIExtensionService service

var ApplicationTagLatest = "latest"

type UIExtension struct {
Application
Manifest *UIManifest `json:"manifest,omitempty"`
Expand Down Expand Up @@ -136,6 +138,15 @@ type UpsertOptions struct {
Version *ApplicationVersion
}

func HasTag(tags []string, tag string) bool {
for _, v := range tags {
if strings.EqualFold(v, tag) {
return true
}
}
return false
}

// CreateVersion creates a new version of an application from a given file
// The filename can either be a string or a io.Reader
func (s *UIExtensionService) CreateExtension(ctx context.Context, application *Application, filename any, opt UpsertOptions) (*ApplicationVersion, *Response, error) {
Expand Down Expand Up @@ -166,13 +177,23 @@ func (s *UIExtensionService) CreateExtension(ctx context.Context, application *A
if app == nil {
// Create the new application
app, resp, err = s.client.Application.Create(ctx, application)

// New applicaitons must have the first binary be activated, so ignore the existing SkipActivation option

Check warning on line 181 in pkg/c8y/uiExtension.go

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"applicaitons" should be "applications".

Check failure on line 181 in pkg/c8y/uiExtension.go

View workflow job for this annotation

GitHub Actions / lint

`applicaitons` is a misspelling of `applications` (misspell)
opt.SkipActivation = false

// Append latest tag if not already defined
if opt.Version != nil {
if !HasTag(opt.Version.Tags, ApplicationTagLatest) {
opt.Version.Tags = append(opt.Version.Tags, ApplicationTagLatest)
}
}
} else {
// Update the existing application
props := &Application{}
if application.Availability != "" {
props := &Application{}
props.Availability = application.Availability
app, resp, err = s.client.Application.Update(ctx, app.ID, props)
}
app, resp, err = s.client.Application.Update(ctx, app.ID, props)
}
if err != nil {
return nil, resp, err
Expand Down

0 comments on commit ef2b1d4

Please sign in to comment.