// Open the function.json file and prime the config. func (f *Function) Open() error { f.Log = f.Log.WithField("function", f.Name) if f.Plugins == nil { f.Plugins = defaultPlugins } if f.Environment == nil { f.Environment = make(map[string]string) } p, err := os.Open(filepath.Join(f.Path, "function.json")) if err == nil { if err := json.NewDecoder(p).Decode(&f.Config); err != nil { return err } } if err := f.hookOpen(); err != nil { return err } if err := validator.Validate(&f.Config); err != nil { return fmt.Errorf("error opening function %s: %s", f.Name, err.Error()) } patterns, err := utils.ReadIgnoreFile(f.Path) if err != nil { return err } f.IgnoredPatterns = append(f.IgnoredPatterns, patterns...) return nil }
// Open the function.json file and prime the config. func (f *Function) Open(environment string) error { f.defaults() f.Log = f.Log.WithFields(log.Fields{ "function": f.Name, "env": environment, }) f.Log.Debug("open") if err := f.loadConfig(environment); err != nil { return err } if err := f.hookOpen(); err != nil { return err } if err := validator.Validate(&f.Config); err != nil { return fmt.Errorf("error opening function %s: %s", f.Name, err.Error()) } ignoreFile, err := utils.ReadIgnoreFile(f.Path) if err != nil { return err } f.IgnoreFile = append(f.IgnoreFile, []byte("\n")...) f.IgnoreFile = append(f.IgnoreFile, ignoreFile...) return nil }
// Open the function.json file and prime the config. func (f *Function) Open() error { f.defaults() f.Log = f.Log.WithField("function", f.Name) p, err := os.Open(filepath.Join(f.Path, "function.json")) if err == nil { if err := json.NewDecoder(p).Decode(&f.Config); err != nil { return err } } if err := f.hookOpen(); err != nil { return err } if err := validator.Validate(&f.Config); err != nil { return fmt.Errorf("error opening function %s: %s", f.Name, err.Error()) } ignoreFile, err := utils.ReadIgnoreFile(f.Path) if err != nil { return err } f.IgnoreFile = append(f.IgnoreFile, []byte("\n")...) f.IgnoreFile = append(f.IgnoreFile, ignoreFile...) return nil }
// Open the project.json file and prime the config. func (p *Project) Open() error { p.defaults() f, err := os.Open(filepath.Join(p.Path, "project.json")) if err != nil { return err } if err := json.NewDecoder(f).Decode(&p.Config); err != nil { return err } if err := validator.Validate(&p.Config); err != nil { return err } t, err := template.New("nameTemplate").Parse(p.NameTemplate) if err != nil { return err } p.nameTemplate = t ignoreFile, err := utils.ReadIgnoreFile(p.Path) if err != nil { return err } p.IgnoreFile = append(p.IgnoreFile, ignoreFile...) return nil }
// Open the project.json file and prime the config. func (p *Project) Open() error { p.defaults() f, err := os.Open(filepath.Join(p.Path, "project.json")) if err != nil { return err } if err := json.NewDecoder(f).Decode(&p.Config); err != nil { return err } if err := validator.Validate(&p.Config); err != nil { return err } t, err := template.New("nameTemplate").Parse(p.NameTemplate) if err != nil { return err } p.nameTemplate = t p.IgnoredPatterns, err = utils.ReadIgnoreFile(p.Path) if err != nil { return err } return p.loadFunctions() }
// Open the function.json file and prime the config. func (f *Function) Open() error { p, err := os.Open(filepath.Join(f.Path, "function.json")) if err == nil { if err := json.NewDecoder(p).Decode(&f.Config); err != nil { return err } } if f.Runtime == "" { if runtimeName, err := runtime.Detect(f.Path); err == nil { f.Runtime = runtimeName } } if err := validator.Validate(&f.Config); err != nil { return fmt.Errorf("error opening function %s: %s", f.Name, err.Error()) } r, err := runtime.ByName(f.Runtime) if err != nil { return err } f.runtime = r patterns, err := utils.ReadIgnoreFile(f.Path) if err != nil { return err } f.IgnoredPatterns = append(f.IgnoredPatterns, patterns...) f.Log = f.Log.WithField("function", f.Name) return nil }
// Open the project.json file and prime the config. func (p *Project) Open() error { p.defaults() configFile := "project.json" if p.Environment != "" { configFile = fmt.Sprintf("project.%s.json", p.Environment) } f, err := os.Open(filepath.Join(p.Path, configFile)) if err != nil { return err } if err := json.NewDecoder(f).Decode(&p.Config); err != nil { return err } if p.InfraEnvironment == "" { p.InfraEnvironment = p.Config.DefaultEnvironment } if p.Role == "" { p.Role = p.readInfraRole() } if err := validator.Validate(&p.Config); err != nil { return err } t, err := template.New("nameTemplate").Parse(p.NameTemplate) if err != nil { return err } p.nameTemplate = t ignoreFile, err := utils.ReadIgnoreFile(p.Path) if err != nil { return err } p.IgnoreFile = append(p.IgnoreFile, ignoreFile...) return nil }
func Test_ReadIgnoreFile_missing(t *testing.T) { patterns, err := utils.ReadIgnoreFile("_fixtures/fileAndDir") assert.NoError(t, err) assert.Equal(t, []string(nil), patterns) }
func Test_ReadIgnoreFile_found(t *testing.T) { patterns, err := utils.ReadIgnoreFile("_fixtures") assert.NoError(t, err) assert.Equal(t, []string{"*.go", "*.log", "whatever"}, patterns) }
func Test_ReadIgnoreFile_found(t *testing.T) { file, err := utils.ReadIgnoreFile("_fixtures") assert.NoError(t, err) assert.Equal(t, []byte("*.go\n*.log\nwhatever"), file) }