Example #1
0
func ListRegisteredApps() (apps []string, err error) {
	apps, _, err = Zk.VisibleChildren(helper.GetBaseAppPath())
	if err != nil {
		log.Printf("Error getting list of registered apps. Error: %s.", err.Error())
	}
	if apps == nil {
		log.Println("No registered apps found. Returning empty list.")
		apps = []string{}
	}
	return
}
Example #2
0
func GetApp(name string) (za *ZkApp, err error) {
	za = &ZkApp{}
	err = getJson(helper.GetBaseAppPath(name), za)
	if za.DependerEnvData == nil {
		za.DependerEnvData = map[string]*types.DependerEnvData{}
		za.Save()
	}
	if za.DependerAppData == nil {
		za.DependerAppData = map[string]*types.DependerAppData{}
		za.Save()
	}
	return
}
Example #3
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))
}
Example #4
0
func CreateAppPath() {
	Zk.Touch(helper.GetBaseAppPath())
}
Example #5
0
func (za *ZkApp) path() string {
	return helper.GetBaseAppPath(za.Name)
}