Skip to content

Commit b7b4847

Browse files
committed
HYPERFLEET-1086 - feat: Add version handler and plugin registration
Version CRUD nested under /channels/{parent_id}/versions/ using ResourceHandler ByOwner methods. Plugin init() registers EntityDescriptor with ParentKind=Channel and OnParentDeleteRestrict.
1 parent 3832add commit b7b4847

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

cmd/hyperfleet-api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/generic"
2323
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/nodePools"
2424
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/resources"
25+
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/versions"
2526
)
2627

2728
// nolint

plugins/versions/plugin.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package versions
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gorilla/mux"
7+
8+
"github.com/openshift-hyperfleet/hyperfleet-api/cmd/hyperfleet-api/environments"
9+
"github.com/openshift-hyperfleet/hyperfleet-api/cmd/hyperfleet-api/server"
10+
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/auth"
11+
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/handlers"
12+
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/registry"
13+
"github.com/openshift-hyperfleet/hyperfleet-api/plugins/resources"
14+
)
15+
16+
const (
17+
kindVersion = "Version"
18+
pluralVersions = "versions"
19+
specSchemaVersion = "VersionSpec"
20+
)
21+
22+
func init() {
23+
registry.Register(registry.EntityDescriptor{
24+
Kind: kindVersion,
25+
Plural: pluralVersions,
26+
ParentKind: "Channel",
27+
SpecSchemaName: specSchemaVersion,
28+
OnParentDelete: registry.OnParentDeleteRestrict,
29+
SearchDisallowedFields: []string{"spec"},
30+
})
31+
32+
server.RegisterRoutes(pluralVersions, func(
33+
apiV1Router *mux.Router,
34+
svc server.ServicesInterface,
35+
authMiddleware auth.JWTMiddleware,
36+
) {
37+
envServices := svc.(*environments.Services)
38+
channelDescriptor := registry.MustGet("Channel")
39+
descriptor := registry.MustGet(kindVersion)
40+
h := handlers.NewResourceHandler(
41+
descriptor,
42+
resources.Service(envServices),
43+
)
44+
45+
r := apiV1Router.PathPrefix("/" + channelDescriptor.Plural + "/{parent_id}/" + descriptor.Plural).Subrouter()
46+
r.HandleFunc("", h.ListByOwner).Methods(http.MethodGet)
47+
r.HandleFunc("", h.CreateWithOwner).Methods(http.MethodPost)
48+
r.HandleFunc("/{id}", h.GetByOwner).Methods(http.MethodGet)
49+
r.HandleFunc("/{id}", h.PatchByOwner).Methods(http.MethodPatch)
50+
r.HandleFunc("/{id}", h.DeleteByOwner).Methods(http.MethodDelete)
51+
52+
r.Use(authMiddleware.AuthenticateAccountJWT)
53+
})
54+
}

0 commit comments

Comments
 (0)