Esempio n. 1
0
func TestUserGroupParsing(t *testing.T) {
	Convey("Given a cloud-config file containing users and/or groups", t, func() {
		configFile := filepath.Join(testConfigDirectory, "usergroups.yaml")

		Convey("It should parse the users and groups", func() {
			c, err := cloudconfig.Parse(configFile)

			So(err, ShouldBeNil)

			So(c.Groups, ShouldEqual, "")
		})
	})
}
Esempio n. 2
0
func TestSSHKeyParsing(t *testing.T) {
	Convey("Given a cloud-config file containing SSH-key directives", t, func() {
		configFile := filepath.Join(testConfigDirectory, "sshkeys.yaml")

		Convey("It should parse the ssh keys", func() {
			c, err := cloudconfig.Parse(configFile)
			So(err, ShouldBeNil)

			So(c.AuthorizedKeys[0], ShouldConsistOf, []byte("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEA3FSyQwBI6Z+nCSjUUk8EEAnnkhXlukKoUPND/RRClWz2s5TCzIkd3Ou5+Cyz71X0XmazM3l5WgeErvtIwQMyT1KjNoMhoJMrJnWqQPOt5Q8zWd9qG7PBl9+eiH5qV7NZ mykey@host"))

			//So(c.SSHKeyPairs[1].Public, ShouldEqual, []byte())
		})
	})
}
Esempio n. 3
0
func TestRunCmdParsing(t *testing.T) {
	Convey("Given a cloud-config file with runcmd directive", t, func() {
		configFile := filepath.Join(testConfigDirectory, "runcmd.yaml")

		Convey("It should parse the execute statements", func() {
			conf, err := cloudconfig.Parse(configFile)
			So(err, ShouldBeNil)

			So(conf.Commands, ShouldConsistOf,
				"ls -l /",
				"sh -xc \"echo $(date) ': hello world!'\"",
				"sh -c echo \"=========hello world'=========\"",
				"ls -l /root",
				"wget http://slashdot.org -O /tmp/index.html",
			)
		})
	})
}
Esempio n. 4
0
func main() {
	// TODO: Build Meaningful Loggers
	flag.Parse()

	// cloudconfig
	if flags.cloudConfig != "" {
		cloudConfigContext, err := cloudconfig.Parse(flags.cloudConfig)
		if err != nil {
			panic(fmt.Errorf("fatal error config file: %v", err))
		}
	}

	metadataDigest := metadata.Get(10 * time.Second)

	conf := datasrc.Merge(metadataDigest, cloudConfigContext)

	StartContextualization()

	// usergroups
	idm := identity.Manager{Exec: sys.DefaultExecutor}

	for _, grp := range conf.Groups {
		if err := idm.CreateGroup(grp); err != nil {
			panic(err)
		}
	}

	for _, usr := range conf.Users {
		if err := idm.CreateUser(usr); err != nil {
			panic(err)
		}
	}

	for _, grp := range conf.Groups {
		for _, usr := range grp {
			if err := idm.AddUserToGroup(grp, usr); err != nil {
				panic(err)
			}
		}
	}

	// ssh_keys
	if err := ssh.InitializeFor("root"); err != nil {
		panic(err)
	}

	ssh.AuthorizeSSHKey(f, conf.AuthorizedKeys...)

	// write_files
	for _, f := range conf.Files {
		file.New(f.Name, file.Contents(f.Data), file.Uid(0), file.Gid(0), file.Permissions(f.Perms))
	}

	// run_cmd
	for _, cmd := range conf.Commands {
		sys.Execute(cmd)
	}

	if err := FinalizeContextualization(); err != nil {
		panic(err)
	}
}