コード例 #1
0
func ListEnvs() (envs []string, err error) {
	envs, _, err = Zk.Children(helper.GetBaseEnvPath())
	if envs == nil {
		return []string{}, err
	}
	return
}
コード例 #2
0
func (s *DeployHelperSuite) TestResolveDepValues(c *C) {
	datamodel.Zk.RecursiveDelete(helper.GetBaseEnvPath())
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(false))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(false))
	datamodel.CreateEnvPath()
	datamodel.CreateRouterPaths()
	datamodel.Router(true, "dev", "somehost", "1.2.3.4").Save()
	zkEnv := datamodel.Env("root")
	err := zkEnv.Save()
	c.Assert(err, IsNil)
	deps, err := ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, Not(IsNil))
	_, err = datamodel.CreateInstance("hello-go", "1234567890", "root", "myhost")
	c.Assert(err, IsNil)
	_, err = datamodel.CreateOrUpdateApp(false, false, "app", "ssh://github.com/ooyala/apo", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	zkApp, err := datamodel.CreateOrUpdateApp(false, true, "hello-go", "ssh://github.com/ooyala/hello-go", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	c.Assert(zkApp.AddDependerAppData(&DependerAppData{Name: "app", DependerEnvData: map[string]*DependerEnvData{"root": &DependerEnvData{Name: "root"}}}), IsNil)
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, true, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].EncryptedData, Not(Equals), "")
	c.Assert(deps["dev1"]["hello-go"].DataMap, IsNil)
	scrypto.DecryptAppDep(deps["dev1"]["hello-go"])
	c.Assert(deps["dev1"]["hello-go"].DataMap, Not(IsNil))
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
}
コード例 #3
0
func (s *DatamodelSuite) TestEnvironment(c *C) {
	path := helper.GetBaseEnvPath()
	Zk.RecursiveDelete(path)
	// Create root environment
	root := Env("root")
	c.Assert(root.Get(), Not(IsNil))
	_, err := GetEnv("root")
	c.Assert(err, Not(IsNil))
	c.Assert(root.Save(), IsNil)

	// test get root env
	gRoot, err := GetEnv("root")
	c.Assert(err, IsNil)
	c.Assert(gRoot, DeepEquals, root)
	gRoot = Env("root")
	c.Assert(gRoot.Get(), IsNil)
	c.Assert(gRoot, DeepEquals, root)
}
コード例 #4
0
func (s *DatamodelSuite) TestApp(c *C) {
	crypto.Init()
	Zk.RecursiveDelete(helper.GetBaseAppPath())
	Zk.RecursiveDelete(helper.GetBaseEnvPath())
	Env("prod").Save()
	Env("staging").Save()
	apps, err := ListRegisteredApps()
	c.Assert(err, Not(IsNil)) // the path doesn't exist. this is an error
	c.Assert(len(apps), Equals, 0)
	app1, err := GetApp(app)
	c.Assert(err, Not(IsNil))
	app1, err = CreateOrUpdateApp(true, true, "app1", "", "", "*****@*****.**")
	c.Assert(err, IsNil)
	c.Assert(app1.NonAtlantis, Equals, true)
	c.Assert(app1.Internal, Equals, true)
	c.Assert(app1.Name, Equals, "app1")
	c.Assert(app1.Repo, Equals, "")
	c.Assert(app1.Root, Equals, "")
	c.Assert(app1.Email, Equals, "*****@*****.**")
	app2, err := CreateOrUpdateApp(false, true, "app2", repo, root, "*****@*****.**")
	c.Assert(err, IsNil)
	c.Assert(app2.NonAtlantis, Equals, false)
	c.Assert(app2.Internal, Equals, true)
	c.Assert(app2.Name, Equals, "app2")
	c.Assert(app2.Repo, Equals, repo)
	c.Assert(app2.Root, Equals, root)
	c.Assert(app2.Email, Equals, "*****@*****.**")

	// verify ListRegisteredApps
	apps, err = ListRegisteredApps()
	c.Assert(err, IsNil)
	c.Assert(len(apps), Equals, 2)

	// attempt to set env/app data
	c.Assert(app1.AddDependerEnvData(&types.DependerEnvData{
		Name:          "prod",
		SecurityGroup: map[string][]uint16{"1.1.1.1": []uint16{1111}, "1.1.1.2": []uint16{1111}},
		DataMap: map[string]interface{}{
			"dep1": "prodvalue1",
		},
	}), IsNil)
	c.Assert(app1.AddDependerAppData(&types.DependerAppData{
		Name: "app2",
		DependerEnvData: map[string]*types.DependerEnvData{
			"prod": &types.DependerEnvData{
				Name: "prod",
				DataMap: map[string]interface{}{
					"dep2": "prodvalue2",
				},
			},
		},
	}), IsNil)
	c.Assert(app1.AddDependerEnvDataForDependerApp("app2", &types.DependerEnvData{
		Name:          "staging",
		SecurityGroup: map[string][]uint16{"1.1.2.1": []uint16{1121}, "1.1.2.2": []uint16{1121}},
		DataMap: map[string]interface{}{
			"dep1": "stagingvalue1",
		},
	}), IsNil)

	// ensure data is encrypted
	app1, err = GetApp("app1")
	c.Assert(err, IsNil)
	c.Assert(app1.NonAtlantis, Equals, true)
	c.Assert(app1.Internal, Equals, true)
	c.Assert(app1.Name, Equals, "app1")
	c.Assert(app1.Repo, Equals, "")
	c.Assert(app1.Root, Equals, "")
	c.Assert(app1.Email, Equals, "*****@*****.**")
	c.Assert(app1.GetDependerEnvData("somethingthatdoesntexist", false), IsNil)
	prodEnvData := app1.GetDependerEnvData("prod", false)
	c.Assert(prodEnvData, Not(IsNil))
	c.Assert(prodEnvData.EncryptedData, Not(Equals), "")
	c.Assert(prodEnvData.DataMap, IsNil)
	appData := app1.GetDependerAppData("app2", false)
	c.Assert(appData, Not(IsNil))
	for _, envData := range appData.DependerEnvData {
		c.Assert(envData.EncryptedData, Not(Equals), "")
		c.Assert(envData.DataMap, IsNil)
	}
	prodEnvData = app1.GetDependerEnvDataForDependerApp("app2", "staging", false)
	c.Assert(prodEnvData, Not(IsNil))
	c.Assert(prodEnvData.EncryptedData, Not(Equals), "")
	c.Assert(prodEnvData.DataMap, IsNil)

	// check that data is decrypted
	app1, err = GetApp("app1")
	c.Assert(err, IsNil)
	c.Assert(app1.NonAtlantis, Equals, true)
	c.Assert(app1.Internal, Equals, true)
	c.Assert(app1.Name, Equals, "app1")
	c.Assert(app1.Repo, Equals, "")
	c.Assert(app1.Root, Equals, "")
	c.Assert(app1.Email, Equals, "*****@*****.**")
	c.Assert(app1.GetDependerEnvData("somethingthatdoesntexist", true), IsNil)
	prodEnvData = app1.GetDependerEnvData("prod", true)
	c.Assert(prodEnvData, Not(IsNil))
	c.Assert(prodEnvData.DataMap, Not(IsNil))
	appData = app1.GetDependerAppData("app2", true)
	c.Assert(appData, Not(IsNil))
	for _, envData := range appData.DependerEnvData {
		c.Assert(envData.DataMap, Not(IsNil))
	}
	prodEnvData = app1.GetDependerEnvDataForDependerApp("app2", "staging", true)
	c.Assert(prodEnvData, Not(IsNil))
	c.Assert(prodEnvData.DataMap, Not(IsNil))
}
コード例 #5
0
func (e *ZkEnv) path() string {
	return helper.GetBaseEnvPath(e.Name)
}
コード例 #6
0
func CreateEnvPath() {
	Zk.Touch(helper.GetBaseEnvPath())
}