MCPcopy Create free account
hub / github.com/devoteamgcloud/petra / processModule

Function processModule

internal/modules/package.go:39–78  ·  view source on GitHub ↗
(path string, b *storage.GCSBackend)

Source from the content-addressed store, hash-verified

37}
38
39func processModule(path string, b *storage.GCSBackend) error {
40 var err error
41 // Retrieve Module Specs
42 mod := &module{}
43
44 yamlFile, err := os.ReadFile(path)
45 if err != nil {
46 return err
47 }
48
49 err = yaml.Unmarshal(yamlFile, mod)
50
51 if err != nil {
52 return fmt.Errorf("error: %v", err)
53 }
54
55 moduleRoot := filepath.Dir(path)
56
57 // Fixes the bug where when the filepath is '.' all the file extensions get dropped
58 if moduleRoot == "." {
59 moduleRoot = moduleRoot + "/"
60 }
61
62 // Create tgz archive
63 archiveBuffer, err := archiveModule(moduleRoot)
64 if err != nil {
65 return err
66 }
67
68 // Upload archive to bucket
69 modulePath := modPath(*mod)
70 downloadURL, err := b.UploadModule(modulePath, archiveBuffer)
71 if err != nil {
72 return err
73 }
74
75 fmt.Printf("module successfully uploaded at : %s\n", downloadURL)
76
77 return err
78}
79
80func archiveModule(root string) (io.Reader, error) {
81 buf := new(bytes.Buffer)

Callers 1

PackageModulesFunction · 0.85

Calls 3

archiveModuleFunction · 0.85
modPathFunction · 0.85
UploadModuleMethod · 0.80

Tested by

no test coverage detected