fix package name parsing and add sourceref to http resource
This commit is contained in:
parent
55fd39f09d
commit
4caed45f96
@ -4,7 +4,7 @@ package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io"
|
||||
@ -28,6 +28,10 @@ const (
|
||||
HTTPTypeName TypeName = "http"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUndefinedContentSource error = errors.New("Cannot create reader: no content defined")
|
||||
)
|
||||
|
||||
func init() {
|
||||
ResourceTypes.Register([]string{"http", "https"}, HTTPFactory)
|
||||
}
|
||||
@ -256,6 +260,7 @@ func (h *HTTP) Create(ctx context.Context) (err error) {
|
||||
|
||||
slog.Error("HTTP.Create() content", "http", h)
|
||||
|
||||
// create should post to the named resource using the resource content or sourceref.
|
||||
contentReader, err = h.contentSourceReader()
|
||||
if err != nil {
|
||||
return
|
||||
@ -418,6 +423,10 @@ func (h *HTTP) writeThru(ctx context.Context) (contentWriter io.WriteCloser, err
|
||||
}
|
||||
*/
|
||||
|
||||
func (h *HTTP) hasContentSource() bool {
|
||||
return len(h.ContentSourceRef) > 0 || len(h.Content) > 0
|
||||
}
|
||||
|
||||
func (h *HTTP) contentSourceReader() (contentReader io.ReadCloser, err error) {
|
||||
if len(h.ContentSourceRef) != 0 {
|
||||
contentReader, err = h.ContentSourceRef.Lookup(nil).ContentReaderStream()
|
||||
@ -426,7 +435,7 @@ func (h *HTTP) contentSourceReader() (contentReader io.ReadCloser, err error) {
|
||||
if len(h.Content) != 0 {
|
||||
contentReader = io.NopCloser(strings.NewReader(h.Content))
|
||||
} else {
|
||||
err = fmt.Errorf("Cannot create reader: no content defined")
|
||||
err = ErrUndefinedContentSource
|
||||
}
|
||||
}
|
||||
return
|
||||
@ -434,7 +443,9 @@ func (h *HTTP) contentSourceReader() (contentReader io.ReadCloser, err error) {
|
||||
|
||||
// set up reader for source content
|
||||
func (h *HTTP) readThru(ctx context.Context) (contentReader io.ReadCloser, err error) {
|
||||
if contentReader, err = h.contentSourceReader(); err != nil {
|
||||
if h.hasContentSource() {
|
||||
contentReader, err = h.contentSourceReader()
|
||||
} else {
|
||||
if h.reader == nil {
|
||||
h.reader, err = transport.NewReaderWithContext(h.parsedURI, ctx)
|
||||
h.reader.SetGzip(false)
|
||||
|
@ -498,9 +498,12 @@ func NewApkReadCommand() *command.Command {
|
||||
c.Extractor = func(out []byte, target any) error {
|
||||
p := target.(*Package)
|
||||
pkg := strings.Split(string(out), "-")
|
||||
if pkg[0] == p.Name {
|
||||
p.Name = pkg[0]
|
||||
p.Version = pkg[1]
|
||||
numberOfFields := len(pkg)
|
||||
packageName := strings.Join(pkg[0:numberOfFields - 3], "-")
|
||||
packageVersion := strings.Join(pkg[numberOfFields - 2:numberOfFields - 1], "-")
|
||||
if packageName == p.Name {
|
||||
p.Name = packageName
|
||||
p.Version = packageVersion
|
||||
p.State = "present"
|
||||
} else {
|
||||
p.State = "absent"
|
||||
@ -543,7 +546,7 @@ func NewApkReadPackagesCommand() *command.Command {
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
numberOfLines := len(lines)
|
||||
diff := (numberOfLines - 1) - numberOfPackages
|
||||
diff := (numberOfLines) - numberOfPackages
|
||||
if diff > 0 {
|
||||
for i := 0; i < diff; i++ {
|
||||
*Packages = append(*Packages, NewPackage())
|
||||
@ -556,7 +559,7 @@ func NewApkReadPackagesCommand() *command.Command {
|
||||
packageFields := strings.Split(installedPackage[0], "-")
|
||||
numberOfFields := len(packageFields)
|
||||
if numberOfFields > 2 {
|
||||
packageName := strings.Join(packageFields[:numberOfFields - 3], "-")
|
||||
packageName := strings.Join(packageFields[0:numberOfFields - 2], "-")
|
||||
packageVersion := strings.Join(packageFields[numberOfFields - 2:numberOfFields - 1], "-")
|
||||
p.Name = packageName
|
||||
p.State = "present"
|
||||
|
Loading…
Reference in New Issue
Block a user