(path string, b *storage.GCSBackend)
| 37 | } |
| 38 | |
| 39 | func 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 | |
| 80 | func archiveModule(root string) (io.Reader, error) { |
| 81 | buf := new(bytes.Buffer) |
no test coverage detected