Skip to content

Commit

Permalink
g
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Jul 25, 2024
1 parent 56e5b3c commit ba66ab3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
19 changes: 15 additions & 4 deletions cmd/embedded-cluster/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
Expand All @@ -12,6 +13,8 @@ import (
"github.com/replicatedhq/embedded-cluster/pkg/addons"
"github.com/replicatedhq/embedded-cluster/pkg/config"
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
"github.com/replicatedhq/embedded-cluster/pkg/embed"
"github.com/replicatedhq/embedded-cluster/pkg/goods"
"github.com/replicatedhq/embedded-cluster/pkg/release"
)

Expand Down Expand Up @@ -59,13 +62,21 @@ var metadataCommand = &cli.Command{
Usage: "Print metadata about this release",
Hidden: true,
Action: func(c *cli.Context) error {
meta, err := gatherVersionMetadata()
// If we are a fully realized release, we can extract the metadata from the binary
metadata, err := goods.ExtractReleaseMetadataFromSelf()
if err != nil {
return err
if !errors.Is(err, embed.ErrEmbeddedDataNotFound) {
return fmt.Errorf("failed to extract version metadata: %w", err)
}
// Otherwise, we can gather the metadata from the defaults
metadata, err = gatherVersionMetadata()
if err != nil {
return fmt.Errorf("failed to gather version metadata: %w", err)
}
}
data, err := json.MarshalIndent(meta, "", "\t")
data, err := json.MarshalIndent(metadata, "", "\t")
if err != nil {
return fmt.Errorf("unable to marshal versions: %w", err)
return fmt.Errorf("failed to marshal versions: %w", err)
}
fmt.Println(string(data))
return nil
Expand Down
9 changes: 7 additions & 2 deletions pkg/embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package embed
import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"io"
"os"
Expand All @@ -17,6 +18,10 @@ const (
endDelimiterTemplate = "-----END %s-----"
)

const (
ErrEmbeddedDataNotFound = errors.New("embedded data not found")

Check failure on line 22 in pkg/embed/embed.go

View workflow job for this annotation

GitHub Actions / output-matrix

errors.New("embedded data not found") (value of type error) is not constant

Check failure on line 22 in pkg/embed/embed.go

View workflow job for this annotation

GitHub Actions / Unit tests

errors.New("embedded data not found") (value of type error) is not constant

Check failure on line 22 in pkg/embed/embed.go

View workflow job for this annotation

GitHub Actions / Sanitize

errors.New("embedded data not found") (value of type error) is not constant

Check failure on line 22 in pkg/embed/embed.go

View workflow job for this annotation

GitHub Actions / Build

errors.New("embedded data not found") (value of type error) is not constant
)

// EmbedReleaseDataInBinary embeds the app release data in the binary at the end of the file and
// writes the new binary to the output path.
func EmbedReleaseDataInBinary(binPath string, embedPath string, outputPath string) error {
Expand Down Expand Up @@ -122,12 +127,12 @@ func ExtractDataFromBinary(delim string, binPath string) ([]byte, error) {

start := bytes.Index(binContent, beginDelimiterBytes(delim))
if start == -1 {
return nil, nil
return nil, ErrEmbeddedDataNotFound
}

end := bytes.Index(binContent, endDelimiterBytes(delim))
if end == -1 {
return nil, fmt.Errorf("failed to find end delimiter in executable")
return nil, ErrEmbeddedDataNotFound
}

if start+len(beginDelimiterBytes(delim)) > len(binContent) {
Expand Down

0 comments on commit ba66ab3

Please sign in to comment.