func (c *Context) open() error { if c.isOpen { return nil } c.ProjectName = c.sanitizedProjectName() if err := c.readRancherConfig(); err != nil { return err } if _, err := c.loadClient(); err != nil { return err } if envSchema, ok := c.Client.Types["environment"]; !ok || !rUtils.Contains(envSchema.CollectionMethods, "POST") { return fmt.Errorf("Can not create a stack, check API key [%s] for [%s]", c.AccessKey, c.Url) } c.checkVersion() if _, err := c.LoadEnv(); err != nil { return err } c.isOpen = true return nil }
func writeNativeMap(writer io.Writer, rawData map[interface{}]interface{}) { keys, data := toSortedStringMap(rawData) for _, key := range keys { if !rUtils.Contains(ignoreKeys, key) { writeNullTerminatedValue(writer, key) writeNullTerminatedValue(writer, data[key]) } } }
func PreprocessServiceMap(bindingsBytes []byte) func(serviceMap config.RawServiceMap) (config.RawServiceMap, error) { return func(serviceMap config.RawServiceMap) (config.RawServiceMap, error) { newServiceMap := make(config.RawServiceMap) var binding BindingProperty var bindingsServices []string if bindingsBytes != nil { err := json.Unmarshal(bindingsBytes, &binding) if err != nil { return nil, err } for k := range binding.Services { bindingsServices = append(bindingsServices, k) } } for k, v := range serviceMap { newServiceMap[k] = make(config.RawService) if bindingsBytes != nil { if utils.Contains(bindingsServices, k) == true { labelMap := make(map[interface{}]interface{}) for key, value := range binding.Services[k].Labels { labelMap[interface{}(key)] = value } if len(labelMap) != 0 { v["labels"] = labelMap } if len(binding.Services[k].Ports) > 0 { v["ports"] = binding.Services[k].Ports } } } for k2, v2 := range v { if k2 == "environment" || k2 == "labels" { newServiceMap[k][k2] = Preprocess(v2, true) } else { newServiceMap[k][k2] = Preprocess(v2, false) } } } return newServiceMap, nil } }