-
Notifications
You must be signed in to change notification settings - Fork 72
/
api.go
35 lines (27 loc) · 1.09 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package serviceregistryutil
import (
"context"
"fmt"
"net/http"
srsmgmtv1 "github.com/redhat-developer/app-services-sdk-core/app-services-sdk-go/registrymgmt/apiv1/client"
srsmgmtv1errors "github.com/redhat-developer/app-services-sdk-core/app-services-sdk-go/registrymgmt/apiv1/error"
)
func GetServiceRegistryByID(ctx context.Context, api srsmgmtv1.RegistriesApi, registryID string) (*srsmgmtv1.Registry, *http.Response, error) {
request := api.GetRegistry(ctx, registryID)
registry, _, err := request.Execute()
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_2) {
return nil, nil, NotFoundByIDError(registryID)
}
return ®istry, nil, err
}
func GetServiceRegistryByName(ctx context.Context, api srsmgmtv1.RegistriesApi, name string) (*srsmgmtv1.Registry, *http.Response, error) {
r := api.GetRegistries(ctx)
r = r.Search(fmt.Sprintf("name=%v", name))
registryList, httpResponse, err := r.Execute()
if registryList.GetTotal() == 0 {
return nil, nil, NotFoundByNameError(name)
}
items := registryList.GetItems()
registryReq := items[0]
return ®istryReq, httpResponse, err
}