|
| 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