// GetRemoteResources is the implementation that uses VCS to get remote resources. func (g VCSAndLocalFSGetter) GetRemoteResources(destination string, subfolder string, worker *common.ConfigWorker, entries []common.Entry) error { tempResourcesDir, err := worker.FSUtil.TempDir("", "opencontrol-resources") if err != nil { return err } defer os.RemoveAll(tempResourcesDir) for _, entry := range entries { tempPath := filepath.Join(tempResourcesDir, subfolder, filepath.Base(entry.URL)) // Clone repo log.Printf("Attempting to clone %v into %s\n", entry, tempPath) err := worker.Downloader.DownloadEntry(entry, tempPath) if err != nil { return err } // Parse configBytes, err := worker.FSUtil.OpenAndReadFile(filepath.Join(tempPath, entry.GetConfigFile())) if err != nil { return err } schema, err := config.Parse(worker.Parser, configBytes) if err != nil { return err } err = schema.GetResources(tempPath, destination, worker) if err != nil { return err } } return nil }
// Get will retrieve all of the resources for the schemas and the resources for all the dependent schemas. func Get(destination string, configData []byte, worker *common.ConfigWorker) error { // Check the data. if configData == nil || len(configData) == 0 { return config.ErrNoDataToParse } // Parse it. configSchema, err := config.Parse(parser.Parser{}, configData) if err != nil { return err } // Get Resources err = configSchema.GetResources("", destination, worker) if err != nil { return err } return nil }