Skip to content

Commit

Permalink
Merge pull request #402 from jlarriba/endpoint_lists
Browse files Browse the repository at this point in the history
Add funcs for returning a list of endpoints and a list of endpointurls
  • Loading branch information
openshift-merge-bot[bot] committed Apr 16, 2024
2 parents d8e4316 + f077cbd commit 1e9d3e3
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions api/v1beta1/keystoneendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,55 @@ func DeleteKeystoneEndpointWithName(

return nil
}

// GetKeystoneEndpointList func
func GetKeystoneEndpointList(
ctx context.Context,
h *helper.Helper,
namespace string,
) (*KeystoneEndpointList, error) {

ke := &KeystoneEndpointList{}
listOpts := []client.ListOption{
client.InNamespace(namespace),
}

if err := h.GetClient().List(ctx, ke, listOpts...); err != nil {
err = fmt.Errorf("error listing endpoints for namespace %s: %w", namespace, err)
return nil, err
}

return ke, nil
}

// GetKeystoneEndpointUrls returns all URLs currently registered. Visibility can be admin, public or internal.
// If it is nil, all URLs are returned
func GetKeystoneEndpointUrls(
ctx context.Context,
h *helper.Helper,
namespace string,
visibility *string,
) ([]string, error) {

ke, err := GetKeystoneEndpointList(ctx, h, namespace)
if err != nil {
return nil, err
}

var endpointurls []string

if visibility != nil {
for _, endpoint := range ke.Items {
endpointurls = append(endpointurls, endpoint.Spec.Endpoints[*visibility])
}
} else {
for _, endpoint := range ke.Items {
endpointurls = append(endpointurls, endpoint.Spec.Endpoints["internal"])
endpointurls = append(endpointurls, endpoint.Spec.Endpoints["public"])
endpointurls = append(endpointurls, endpoint.Spec.Endpoints["admin"])
}
}


return endpointurls, nil
}

0 comments on commit 1e9d3e3

Please sign in to comment.