Ejemplo n.º 1
0
func run() (err error) {
	users := os.Getenv("LDAP_USERS")
	file, err := os.Open(users)
	if err != nil {
		err = errors.New(fmt.Sprintf("Can not open %s : %s", users, err.Error()))
		return
	}
	cfg, err := config.Parse(file)
	if err != nil {
		return
	}
	info, err := parseEnv()
	if err != nil {
		return
	}
	info.RequestFn = token.RequestWithToken
	fun := token.GetToken.MapUsers(cfg.Users).AddUaaUser(uaa.Adduser).AddCCUser(cc.Adduser).MapOrgs(cc.AssociateOrg).MapSpaces(cc.AssociateSpace)
	return fun(info)
}
Ejemplo n.º 2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotalservices/uaaldapimport/config"
	. "github.com/pivotalservices/uaaldapimport/functions"
)

var info *Info = &Info{
	Ccurl:    "https://ccurl.sysdomain.com",
	Uaaurl:   "https://uaaurl.sysdomain.com",
	Clientid: "bulkimport",
	Secret:   "test",
}

var _ = Describe("Function", func() {
	file, _ := os.Open("fixtures/users.yml")
	cfg, _ := config.Parse(file)
	var _ = Describe("Map Users", func() {
		It("Should map users with tokenFuncs", func() {
			var tokenFunc TokenFunc = func(*Info) (string, error) {
				return "my_token", nil
			}
			resultFunc := tokenFunc.MapUsers(cfg.Users)
			userInfos, err := resultFunc(info)
			Ω(err).Should(BeNil())
			Ω(len(userInfos)).Should(Equal(2))
			Ω(userInfos[0].Token).Should(Equal("my_token"))
			Ω(reflect.DeepEqual(userInfos[0].User, cfg.Users[0])).Should(Equal(true))
			Ω(reflect.DeepEqual(userInfos[1].User, cfg.Users[1])).Should(Equal(true))
			Ω(userInfos[1].Token).Should(Equal("my_token"))
		})
	})
Ejemplo n.º 3
0
import (
	"fmt"
	"os"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotalservices/uaaldapimport/config"
)

var _ = Describe("Config", func() {
	file, _ := os.Open("fixtures/users.yml")
	Describe("Parse config", func() {
		Context("with correct fixture", func() {
			It("should be return correct config", func() {
				cfg, err := config.Parse(file)
				fmt.Print(err)
				Ω(err).Should(BeNil())
				Ω(len(cfg.Users)).Should(Equal(2))
				Ω(cfg.Users[0].Externalid).Should(Equal("uid=jcalabrese,ou=People,dc=homelab,dc=io"))
				Ω(cfg.Users[1].Externalid).Should(Equal("uid=rparrish,ou=People,dc=homelab,dc=io"))
				Ω(cfg.Users[0].Emails[0]).Should(Equal("*****@*****.**"))
				Ω(cfg.Users[1].Emails[0]).Should(Equal("*****@*****.**"))
				Ω(len(cfg.Users[0].Orgs)).Should(Equal(2))
				Ω(cfg.Users[0].Orgs[0].Roles[0]).Should(Equal("managers"))
				Ω(cfg.Users[0].Orgs[0].Roles[1]).Should(Equal("auditors"))
				Ω(len(cfg.Users[0].Orgs[0].Spaces)).Should(Equal(2))
				Ω(cfg.Users[0].Orgs[0].Spaces[0].Roles[0]).Should(Equal("managers"))
				Ω(cfg.Users[0].Orgs[0].Spaces[1].Roles[1]).Should(Equal("auditors"))
				Ω(len(cfg.Users[0].Orgs[1].Spaces)).Should(Equal(2))
			})