Example #1
0
func makeAdminAPITestFixtures() *adminAPITestFixtures {
	f := &adminAPITestFixtures{}

	dbMap, ur, pwr, um := makeUserObjects(adminUsers, adminPasswords)

	var cliCount int
	secGen := func() ([]byte, error) {
		id := []byte(fmt.Sprintf("client_%v", cliCount))
		cliCount++
		return id, nil
	}
	cr := db.NewClientRepo(dbMap)
	clientIDGenerator := func(hostport string) (string, error) {
		return fmt.Sprintf("client_%v", hostport), nil
	}
	cm := manager.NewClientManager(cr, db.TransactionFactory(dbMap), manager.ManagerOptions{SecretGenerator: secGen, ClientIDGenerator: clientIDGenerator})
	ccr := db.NewConnectorConfigRepo(dbMap)

	f.cr = cr
	f.ur = ur
	f.pwr = pwr
	f.adAPI = admin.NewAdminAPI(ur, pwr, cr, ccr, um, cm, "local")
	f.adSrv = server.NewAdminServer(f.adAPI, nil, adminAPITestSecret)
	f.hSrv = httptest.NewServer(f.adSrv.HTTPHandler())
	f.hc = &http.Client{
		Transport: &adminAPITransport{
			secret: adminAPITestSecret,
		},
	}
	f.adClient, _ = adminschema.NewWithBasePath(f.hc, f.hSrv.URL)

	return f
}
Example #2
0
func (d *AdminAPIConnector) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
	if err := meta.Valid(); err != nil {
		return nil, err
	}
	cli := client.Client{
		Metadata: meta,
	}
	credential := &oidc.ClientCredentials{}
	service, err := adminschema.NewWithBasePath(d.client, d.baseURL)
	if err != nil {
		return credential, nil
	}
	urls := make([]string, len(cli.Metadata.RedirectURIs))
	for i, url := range cli.Metadata.RedirectURIs {
		urls[i] = url.String()
	}
	c := &adminschema.Client{RedirectURIs: urls}
	createClientRequest := &adminschema.ClientCreateRequest{Client: c}
	response, err := service.Client.Create(createClientRequest).Do()
	if err != nil {
		return credential, err
	}
	credential.ID = response.Client.Id
	credential.Secret = response.Client.Secret
	return credential, nil
}
Example #3
0
func (d *AdminAPIConnector) SetConnectorConfigs(cfgs []interface{}) error {
	service, err := adminschema.NewWithBasePath(d.client, d.baseURL)
	if err != nil {
		return nil
	}
	connectorAddRequest := &adminschema.ConnectorsSetRequest{Connectors: cfgs}
	if err := service.Connectors.Set(connectorAddRequest).Do(); err != nil {
		return err
	}
	return nil
}
Example #4
0
func (d *AdminAPIConnector) ConnectorConfigs() ([]interface{}, error) {
	var connectors []interface{}
	service, err := adminschema.NewWithBasePath(d.client, d.baseURL)
	if err != nil {
		return connectors, nil
	}
	response, err := service.Connectors.Get().Do()
	if err != nil {
		return connectors, err
	}
	connectors = response.Connectors
	return connectors, nil
}
Example #5
0
func makeAdminAPITestFixtures() *adminAPITestFixtures {
	f := &adminAPITestFixtures{}

	ur, pwr, um := makeUserObjects(adminUsers, adminPasswords)
	f.ur = ur
	f.pwr = pwr
	f.adAPI = admin.NewAdminAPI(um, f.ur, f.pwr, "local")
	f.adSrv = server.NewAdminServer(f.adAPI, nil)
	f.hSrv = httptest.NewServer(f.adSrv.HTTPHandler())
	f.hc = &http.Client{}
	f.adClient, _ = adminschema.NewWithBasePath(f.hc, f.hSrv.URL)

	return f
}