// Connect typically produces an ExternalClient by:
// 1. Tracking that the managed resource is using a ProviderConfig.
// 2. Getting the managed resource's ProviderConfig.
// 3. Getting the credentials specified by the ProviderConfig.
// 4. Using the credentials to form a client.
Connect typically produces an ExternalClient by:
1. Tracking that the managed resource is using a ProviderConfig.
2. Getting the managed resource's ProviderConfig.
3. Getting the credentials specified by the ProviderConfig.
4. Using the credentials to form a client.
// Connect typically produces an ExternalClient by : // 1 . Tracking that the managed resource is using a ProviderConfig . // 2 . Getting the managed resource ' s ProviderConfig . // 3 . Getting the credentials specified by the ProviderConfig . // 4 . Using the credentials to form a client .
func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.ExternalClient, error) {
	cr, ok := mg.(*v1alpha1.ZeebeCluster)
	if !ok {
		return nil, errors.New(errNotMyType)
	}
	if err := c.usage.Track(ctx, mg); err != nil {
		return nil, errors.Wrap(err, errTrackPCUsage)
	}
	pc := &apisv1alpha1.ProviderConfig{}
	if err := c.kube.Get(ctx, types.NamespacedName{Name: cr.GetProviderConfigReference().Name}, pc); err != nil {
		return nil, errors.Wrap(err, errGetPC)
	}
	cd := pc.Spec.Credentials
	data, err := resource.CommonCredentialExtractor(ctx, cd.Source, c.kube, cd.CommonCredentialSelectors)
	if err != nil {
		return nil, errors.Wrap(err, errGetCreds)
	}
	credentials := 	CCCredentials{}
	err = json.Unmarshal(data, &credentials)
	if err != nil {
		return nil, errors.Wrap(err, errGetCreds)
	}
	var svc = cc.CCClient{}
	flush := svc.InitTracer()
	defer flush()
	var logged, _ = svc.LoginWithContext(ctx, credentials.CCClientId, credentials.CCSecretId)
	flush2 := initTracer()
	defer flush2()
	if logged{
		fmt.Printf("logged in!\n")
	}else{
		return nil, errors.New(errCannotLoginToCC)
	}
	if err != nil {
		return nil, errors.Wrap(err, errNewClient)
	}
	return &external{service: svc, tracer: otel.Tracer("provider-camunda-cloud")}, nil
}
func ( c * connector ) Connect ( ctx context . Context , mg resource . Managed ) ( managed . ExternalClient , error ) { cr , ok := mg . ( * v1alpha1 . ZeebeCluster ) if ! ok { return nil , errors . New ( errNotMyType ) } if err := c . usage . Track ( ctx , mg ) ; err != nil { return nil , errors . Wrap ( err , errTrackPCUsage ) } pc := & apisv1alpha1 . ProviderConfig { } if err := c . kube . Get ( ctx , types . NamespacedName { Name : cr . GetProviderConfigReference ( ) . Name } , pc ) ; err != nil { return nil , errors . Wrap ( err , errGetPC ) } cd := pc . Spec . Credentials data , err := resource . CommonCredentialExtractor ( ctx , cd . Source , c . kube , cd . CommonCredentialSelectors ) if err != nil { return nil , errors . Wrap ( err , errGetCreds ) } credentials := CCCredentials { } err = json . Unmarshal ( data , & credentials ) if err != nil { return nil , errors . Wrap ( err , errGetCreds ) } var svc = cc . CCClient { } flush := svc . InitTracer ( ) defer flush ( ) var logged , _ = svc . LoginWithContext ( ctx , credentials . CCClientId , credentials . CCSecretId ) flush2 := initTracer ( ) defer flush2 ( ) if logged { fmt . Printf ( " \n " ) } else { return nil , errors . New ( errCannotLoginToCC ) } if err != nil { return nil , errors . Wrap ( err , errNewClient ) } return & external { service : svc , tracer : otel . Tracer ( " " ) } , nil }
Connect typically produces an ExternalClient by:
1.
Connect typically produces an ExternalClient by : 1 .