Skip to content

feat: encapsulate control plane dialing logic #3062

@jiparis

Description

@jiparis

The goal is to make it simple to extend by external tools without having to duplicate the dialing logic.

Currently controlplane dialing depends on reading variables with viper, setting connection options and finally calling grpcconn.New. All that logic could be encapsulated in a single package for others to use without worrying about viper or any other dependency.

// DialControlPlane reads standard viper keys and dials the control plane.
// extra lets callers override/augment (e.g. grpcconn.WithOrgName).
func DialControlPlane(authToken string, extra ...grpcconn.Option) (*grpc.ClientConn, error) {
    opts := []grpcconn.Option{
        grpcconn.WithInsecure(viper.GetBool(KeyAPIInsecure)),
    }
    if ca := viper.GetString(KeyControlPlaneCA); ca != "" {
        if _, err := os.Stat(ca); err == nil {
            opts = append(opts, grpcconn.WithCAFile(ca))
        } else {
            opts = append(opts, grpcconn.WithCAContent(ca))
        }
    }
    opts = append(opts, extra...)
    return grpcconn.New(viper.GetString(KeyControlPlaneAPI), authToken, opts...)
}

// DialArtifactCAS is the symmetric helper for CAS.
func DialArtifactCAS(authToken string, extra ...grpcconn.Option) (*grpc.ClientConn, error) { /* ... */ }

Also, it's worth mentioning that Chainloop-Organization header is set at connection time. I suggest to move it to runtime (via context) so that a single connection can be reused with different organization headers.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions