Compare commits
No commits in common. "dc8a9cff2026155075f60391a74d081630efca7b" and "73498a08de7789db7d52437972de16aca2ec70ff" have entirely different histories.
dc8a9cff20
...
73498a08de
6 changed files with 25 additions and 29 deletions
18
README.md
18
README.md
|
|
@ -44,18 +44,6 @@ makeshift list
|
||||||
|
|
||||||
# list files store in the template directory with a specified host
|
# list files store in the template directory with a specified host
|
||||||
makeshift list --host http://localhost:5050 --path templates
|
makeshift list --host http://localhost:5050 --path templates
|
||||||
|
|
||||||
# list all available plugins
|
|
||||||
makeshift list plugins
|
|
||||||
|
|
||||||
# list specific plugin (for plugin info, use 'makeshift plugin info` instead)
|
|
||||||
makeshift list plugins jinja2
|
|
||||||
|
|
||||||
# list all available profiles
|
|
||||||
makeshift list profiles
|
|
||||||
|
|
||||||
# list specific profile information
|
|
||||||
makeshift list profiles default
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then, we can start downloading some files or directories (as archives).
|
Then, we can start downloading some files or directories (as archives).
|
||||||
|
|
@ -76,12 +64,6 @@ makeshift download -p templates --plugins smd,jinja2 --profile compute
|
||||||
|
|
||||||
# do everything in the above example but extract and remove archive
|
# do everything in the above example but extract and remove archive
|
||||||
makeshift download -p templates --plugins smd,jinja2 --profile compute -xr
|
makeshift download -p templates --plugins smd,jinja2 --profile compute -xr
|
||||||
|
|
||||||
# download a raw plugin
|
|
||||||
makeshift download plugin jinja2
|
|
||||||
|
|
||||||
# download a profile
|
|
||||||
makeshift download profile default
|
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ var listPluginsCmd = &cobra.Command{
|
||||||
Msg("response returned bad status")
|
Msg("response returned bad status")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
fmt.Println(string(body))
|
||||||
err = json.Unmarshal(body, &plugins)
|
err = json.Unmarshal(body, &plugins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).
|
log.Error().Err(err).
|
||||||
|
|
@ -124,7 +125,7 @@ var listPluginsCmd = &cobra.Command{
|
||||||
for _, pluginName := range args {
|
for _, pluginName := range args {
|
||||||
// make request to /list endpoint
|
// make request to /list endpoint
|
||||||
res, body, err = c.MakeRequest(client.HTTPEnvelope{
|
res, body, err = c.MakeRequest(client.HTTPEnvelope{
|
||||||
Path: fmt.Sprintf("/plugins/%s/info", pluginName),
|
Path: fmt.Sprintf("/plugins/%s", pluginName),
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ type DataFormat string
|
||||||
const (
|
const (
|
||||||
List DataFormat = "list"
|
List DataFormat = "list"
|
||||||
JSON DataFormat = "json"
|
JSON DataFormat = "json"
|
||||||
YAML DataFormat = "yaml"
|
FORMAT_YAML DataFormat = "yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (df DataFormat) String() string {
|
func (df DataFormat) String() string {
|
||||||
|
|
@ -22,12 +22,12 @@ func (df DataFormat) String() string {
|
||||||
|
|
||||||
func (df *DataFormat) Set(v string) error {
|
func (df *DataFormat) Set(v string) error {
|
||||||
switch DataFormat(v) {
|
switch DataFormat(v) {
|
||||||
case List, JSON, YAML:
|
case List, JSON, FORMAT_YAML:
|
||||||
*df = DataFormat(v)
|
*df = DataFormat(v)
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("must be one of %v", []DataFormat{
|
return fmt.Errorf("must be one of %v", []DataFormat{
|
||||||
List, JSON, YAML,
|
List, JSON, FORMAT_YAML,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ func Marshal(data interface{}, outFormat DataFormat) ([]byte, error) {
|
||||||
} else {
|
} else {
|
||||||
return bytes, nil
|
return bytes, nil
|
||||||
}
|
}
|
||||||
case YAML:
|
case FORMAT_YAML:
|
||||||
if bytes, err := yaml.Marshal(data); err != nil {
|
if bytes, err := yaml.Marshal(data); err != nil {
|
||||||
return nil, fmt.Errorf("failed to marshal data into YAML: %w", err)
|
return nil, fmt.Errorf("failed to marshal data into YAML: %w", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -72,7 +72,7 @@ func Unmarshal(data []byte, v interface{}, inFormat DataFormat) error {
|
||||||
if err := json.Unmarshal(data, v); err != nil {
|
if err := json.Unmarshal(data, v); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal data into JSON: %w", err)
|
return fmt.Errorf("failed to unmarshal data into JSON: %w", err)
|
||||||
}
|
}
|
||||||
case YAML:
|
case FORMAT_YAML:
|
||||||
if err := yaml.Unmarshal(data, v); err != nil {
|
if err := yaml.Unmarshal(data, v); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal data into YAML: %w", err)
|
return fmt.Errorf("failed to unmarshal data into YAML: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +98,7 @@ func DataFormatFromFileExt(path string, defaultFmt DataFormat) DataFormat {
|
||||||
return JSON
|
return JSON
|
||||||
case ".yaml", ".yml", ".YAML", ".YML":
|
case ".yaml", ".yml", ".YAML", ".YML":
|
||||||
// The file is a YAML file
|
// The file is a YAML file
|
||||||
return YAML
|
return FORMAT_YAML
|
||||||
}
|
}
|
||||||
return defaultFmt
|
return defaultFmt
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -34,6 +35,7 @@ func (s *Service) ListPlugins() http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fmt.Printf("%v", plugins)
|
||||||
|
|
||||||
w.Write(body)
|
w.Write(body)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,16 @@ func (s *Service) ListProfiles() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func (s *Service) CreateProfiles() http.HandlerFunc {
|
||||||
|
// return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// var (
|
||||||
|
// path = chi.URLParam(r, "path")
|
||||||
|
// err error
|
||||||
|
// )
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func (s *Service) GetProfile() http.HandlerFunc {
|
func (s *Service) GetProfile() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -184,14 +184,15 @@ func LoadPluginsFromDir(dirpath string) (map[string]makeshift.Plugin, error) {
|
||||||
|
|
||||||
// helper to check for valid extensions
|
// helper to check for valid extensions
|
||||||
var hasValidExt = func(path string) bool {
|
var hasValidExt = func(path string) bool {
|
||||||
return slices.Contains([]string{".so", ".dylib", ".dll"}, filepath.Ext(path))
|
var validExts = []string{".so", ".dylib", ".dll"}
|
||||||
|
return slices.Contains(validExts, filepath.Ext(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
// walk all files in directory only loading *valid* plugins
|
// walk all files in directory only loading *valid* plugins
|
||||||
err = filepath.Walk(dirpath, func(path string, info fs.FileInfo, err error) error {
|
err = filepath.Walk(dirpath, func(path string, info fs.FileInfo, err error) error {
|
||||||
// skip trying to load generator plugin if directory or error
|
// skip trying to load generator plugin if directory or error
|
||||||
// only try loading if file has .so extension
|
// only try loading if file has .so extension
|
||||||
if info.IsDir() || err != nil || !hasValidExt(path) {
|
if info.IsDir() || err != nil || hasValidExt(path) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue