forked from helm/monocular
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled repositories API endpoint (helm#203)
* Expose repors * Repository API endpoint
- Loading branch information
Showing
11 changed files
with
326 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package handlers | ||
|
||
import ( | ||
middleware "github.com/go-openapi/runtime/middleware" | ||
"github.com/helm/monocular/src/api/config" | ||
"github.com/helm/monocular/src/api/data/helpers" | ||
"github.com/helm/monocular/src/api/swagger/models" | ||
"github.com/helm/monocular/src/api/swagger/restapi/operations" | ||
) | ||
|
||
// GetRepos returns all the enabled repositories | ||
func GetRepos(params operations.GetAllReposParams) middleware.Responder { | ||
config, _ := config.GetConfig() | ||
resources := helpers.MakeRepoResources(config.Repos) | ||
return reposHTTPBody(resources) | ||
} | ||
|
||
func reposHTTPBody(repos []*models.Resource) middleware.Responder { | ||
resourceArrayData := models.ResourceArrayData{ | ||
Data: repos, | ||
} | ||
return operations.NewGetAllReposOK().WithPayload(&resourceArrayData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/arschles/assert" | ||
"github.com/go-openapi/runtime" | ||
"github.com/helm/monocular/src/api/config" | ||
"github.com/helm/monocular/src/api/swagger/models" | ||
"github.com/helm/monocular/src/api/swagger/restapi/operations" | ||
"github.com/helm/monocular/src/api/testutil" | ||
) | ||
|
||
func TestGetAllRepos200(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
params := operations.GetAllReposParams{} | ||
resp := GetRepos(params) | ||
assert.NotNil(t, resp, "GetRepos response") | ||
resp.WriteResponse(w, runtime.JSONProducer()) | ||
assert.Equal(t, w.Code, http.StatusOK, "expect a 200 response code") | ||
var httpBody models.ResourceArrayData | ||
assert.NoErr(t, testutil.ResourceArrayDataFromJSON(w.Body, &httpBody)) | ||
config, err := config.GetConfig() | ||
assert.NoErr(t, err) | ||
assert.Equal(t, len(config.Repos), len(httpBody.Data), "Returns the enabled repos") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package operations | ||
|
||
// This file was generated by the swagger tool. | ||
// Editing this file might prove futile when you re-run the generate command | ||
|
||
import ( | ||
"net/http" | ||
|
||
middleware "github.com/go-openapi/runtime/middleware" | ||
) | ||
|
||
// GetAllReposHandlerFunc turns a function with the right signature into a get all repos handler | ||
type GetAllReposHandlerFunc func(GetAllReposParams) middleware.Responder | ||
|
||
// Handle executing the request and returning a response | ||
func (fn GetAllReposHandlerFunc) Handle(params GetAllReposParams) middleware.Responder { | ||
return fn(params) | ||
} | ||
|
||
// GetAllReposHandler interface for that can handle valid get all repos params | ||
type GetAllReposHandler interface { | ||
Handle(GetAllReposParams) middleware.Responder | ||
} | ||
|
||
// NewGetAllRepos creates a new http.Handler for the get all repos operation | ||
func NewGetAllRepos(ctx *middleware.Context, handler GetAllReposHandler) *GetAllRepos { | ||
return &GetAllRepos{Context: ctx, Handler: handler} | ||
} | ||
|
||
/*GetAllRepos swagger:route GET /v1/repos getAllRepos | ||
get all repositories enabled in the backend | ||
*/ | ||
type GetAllRepos struct { | ||
Context *middleware.Context | ||
Handler GetAllReposHandler | ||
} | ||
|
||
func (o *GetAllRepos) ServeHTTP(rw http.ResponseWriter, r *http.Request) { | ||
route, _ := o.Context.RouteInfo(r) | ||
var Params = NewGetAllReposParams() | ||
|
||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params | ||
o.Context.Respond(rw, r, route.Produces, route, err) | ||
return | ||
} | ||
|
||
res := o.Handler.Handle(Params) // actually handle the request | ||
|
||
o.Context.Respond(rw, r, route.Produces, route, res) | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/api/swagger/restapi/operations/get_all_repos_parameters.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package operations | ||
|
||
// This file was generated by the swagger tool. | ||
// Editing this file might prove futile when you re-run the swagger generate command | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/go-openapi/errors" | ||
"github.com/go-openapi/runtime/middleware" | ||
) | ||
|
||
// NewGetAllReposParams creates a new GetAllReposParams object | ||
// with the default values initialized. | ||
func NewGetAllReposParams() GetAllReposParams { | ||
var () | ||
return GetAllReposParams{} | ||
} | ||
|
||
// GetAllReposParams contains all the bound params for the get all repos operation | ||
// typically these are obtained from a http.Request | ||
// | ||
// swagger:parameters getAllRepos | ||
type GetAllReposParams struct { | ||
|
||
// HTTP Request Object | ||
HTTPRequest *http.Request | ||
} | ||
|
||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface | ||
// for simple values it will use straight method calls | ||
func (o *GetAllReposParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { | ||
var res []error | ||
o.HTTPRequest = r | ||
|
||
if len(res) > 0 { | ||
return errors.CompositeValidationError(res...) | ||
} | ||
return nil | ||
} |
104 changes: 104 additions & 0 deletions
104
src/api/swagger/restapi/operations/get_all_repos_responses.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package operations | ||
|
||
// This file was generated by the swagger tool. | ||
// Editing this file might prove futile when you re-run the swagger generate command | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/go-openapi/runtime" | ||
|
||
"github.com/helm/monocular/src/api/swagger/models" | ||
) | ||
|
||
/*GetAllReposOK repositories response | ||
swagger:response getAllReposOK | ||
*/ | ||
type GetAllReposOK struct { | ||
|
||
// In: body | ||
Payload *models.ResourceArrayData `json:"body,omitempty"` | ||
} | ||
|
||
// NewGetAllReposOK creates GetAllReposOK with default headers values | ||
func NewGetAllReposOK() *GetAllReposOK { | ||
return &GetAllReposOK{} | ||
} | ||
|
||
// WithPayload adds the payload to the get all repos o k response | ||
func (o *GetAllReposOK) WithPayload(payload *models.ResourceArrayData) *GetAllReposOK { | ||
o.Payload = payload | ||
return o | ||
} | ||
|
||
// SetPayload sets the payload to the get all repos o k response | ||
func (o *GetAllReposOK) SetPayload(payload *models.ResourceArrayData) { | ||
o.Payload = payload | ||
} | ||
|
||
// WriteResponse to the client | ||
func (o *GetAllReposOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { | ||
|
||
rw.WriteHeader(200) | ||
if o.Payload != nil { | ||
if err := producer.Produce(rw, o.Payload); err != nil { | ||
panic(err) // let the recovery middleware deal with this | ||
} | ||
} | ||
} | ||
|
||
/*GetAllReposDefault unexpected error | ||
swagger:response getAllReposDefault | ||
*/ | ||
type GetAllReposDefault struct { | ||
_statusCode int | ||
|
||
// In: body | ||
Payload *models.Error `json:"body,omitempty"` | ||
} | ||
|
||
// NewGetAllReposDefault creates GetAllReposDefault with default headers values | ||
func NewGetAllReposDefault(code int) *GetAllReposDefault { | ||
if code <= 0 { | ||
code = 500 | ||
} | ||
|
||
return &GetAllReposDefault{ | ||
_statusCode: code, | ||
} | ||
} | ||
|
||
// WithStatusCode adds the status to the get all repos default response | ||
func (o *GetAllReposDefault) WithStatusCode(code int) *GetAllReposDefault { | ||
o._statusCode = code | ||
return o | ||
} | ||
|
||
// SetStatusCode sets the status to the get all repos default response | ||
func (o *GetAllReposDefault) SetStatusCode(code int) { | ||
o._statusCode = code | ||
} | ||
|
||
// WithPayload adds the payload to the get all repos default response | ||
func (o *GetAllReposDefault) WithPayload(payload *models.Error) *GetAllReposDefault { | ||
o.Payload = payload | ||
return o | ||
} | ||
|
||
// SetPayload sets the payload to the get all repos default response | ||
func (o *GetAllReposDefault) SetPayload(payload *models.Error) { | ||
o.Payload = payload | ||
} | ||
|
||
// WriteResponse to the client | ||
func (o *GetAllReposDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { | ||
|
||
rw.WriteHeader(o._statusCode) | ||
if o.Payload != nil { | ||
if err := producer.Produce(rw, o.Payload); err != nil { | ||
panic(err) // let the recovery middleware deal with this | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters