Skip to content

Commit

Permalink
Merge pull request #602 from kinvolk/minor-fixes
Browse files Browse the repository at this point in the history
Backend: Allow accessing resources via API using ProductID
  • Loading branch information
yolossn authored May 30, 2022
2 parents 7c93b50 + 2f543fe commit eaa4ce0
Show file tree
Hide file tree
Showing 26 changed files with 1,465 additions and 704 deletions.
111 changes: 69 additions & 42 deletions backend/api/spec.yaml

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions backend/pkg/api/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,8 @@ func (api *API) UpdateApp(app *Application) error {

// DeleteApp removes the application identified by the id provided.
func (api *API) DeleteApp(appID string) error {
realAppID, err := api.GetAppID(appID)
if err != nil {
return err
}

query, _, err := goqu.Delete("application").Where(goqu.C("id").Eq(realAppID)).ToSQL()
query, _, err := goqu.Delete("application").Where(goqu.C("id").Eq(appID)).ToSQL()
if err != nil {
return err
}
Expand All @@ -213,14 +209,10 @@ func (api *API) DeleteApp(appID string) error {

// GetApp returns the application identified by the id provided.
func (api *API) GetApp(appID string) (*Application, error) {
realAppID, err := api.GetAppID(appID)
if err != nil {
return nil, err
}

var app Application
query, _, err := goqu.From("application").
Where(goqu.C("id").Eq(realAppID)).ToSQL()
Where(goqu.C("id").Eq(appID)).ToSQL()
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion backend/pkg/api/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ func TestGetApp(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tApp1.Name, app.Name)

app, err = a.GetApp(*tApp1.ProductID.Ptr())
appID, err := a.GetAppID(*tApp1.ProductID.Ptr())
assert.NoError(t, err)

app, err = a.GetApp(appID)
assert.NoError(t, err)
assert.Equal(t, tApp1.ProductID, app.ProductID)

Expand Down
8 changes: 4 additions & 4 deletions backend/pkg/api/bindata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/pkg/api/db/sample_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ insert into flatcar_action values ('748df5fc-12a5-4dad-a71e-465cc1668048', 'post
insert into flatcar_action values ('9cd474c5-efa3-4989-9992-58ddb852ed84', 'postinstall', '', '1S9zQCLGjmefYnE/aFcpCjL1NsguHhQGj0UCm5f0M98=', false, false, true, '', '', '', '2019-09-10 23:11:10.913778', '284d295b-518f-4d67-999e-94968d0eed90');

-- Sample application 1
insert into application (id, name, description, team_id) values ('b6458005-8f40-4627-b33b-be70a718c48e', 'Sample application', 'Just an application to show the capabilities of Nebraska', 'd89342dc-9214-441d-a4af-bdd837a3b239');
insert into application (id, name, description, team_id, product_id) values ('b6458005-8f40-4627-b33b-be70a718c48e', 'Sample application', 'Just an application to show the capabilities of Nebraska', 'd89342dc-9214-441d-a4af-bdd837a3b239','io.kinvolk.sample');
insert into package (id, type, url, filename, version, application_id, arch) values ('5195d5a2-5f82-11e5-9d70-feff819cdc9f', 4, 'https://www.kinvolk.io/', 'test_1.0.2', '1.0.2', 'b6458005-8f40-4627-b33b-be70a718c48e', 1);
insert into package (id, type, url, filename, version, application_id, arch) values ('12697fa4-5f83-11e5-9d70-feff819cdc9f', 4, 'https://www.kinvolk.io/', 'test_1.0.3', '1.0.3', 'b6458005-8f40-4627-b33b-be70a718c48e', 1);
insert into package (id, type, url, filename, version, application_id, arch) values ('8004bad8-5f97-11e5-9d70-feff819cdc9f', 4, 'https://www.kinvolk.io/', 'test_1.0.4', '1.0.4', 'b6458005-8f40-4627-b33b-be70a718c48e', 1);
Expand Down
5 changes: 2 additions & 3 deletions backend/pkg/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/tidwall/gjson"
"golang.org/x/oauth2"

"github.com/kinvolk/nebraska/backend/pkg/codegen"
"github.com/kinvolk/nebraska/backend/pkg/sessions"
echosessions "github.com/kinvolk/nebraska/backend/pkg/sessions/echo"
)
Expand Down Expand Up @@ -326,9 +327,7 @@ func (oa *oidcAuth) LoginToken(c echo.Context) error {
session.Set("username", oidcToken.Subject)
sessionSave(c, session, "login_token")

return c.JSON(http.StatusOK, map[string]string{
"token": oidcTokenResp.AccessToken,
})
return c.JSON(http.StatusOK, codegen.LoginToken{Token: oidcTokenResp.AccessToken})
}

// tokenFromRequest extracts token from request header. If Authorization header is not present returns id_token query param .
Expand Down
543 changes: 277 additions & 266 deletions backend/pkg/codegen/client.gen.go

Large diffs are not rendered by default.

422 changes: 211 additions & 211 deletions backend/pkg/codegen/server.gen.go

Large diffs are not rendered by default.

137 changes: 69 additions & 68 deletions backend/pkg/codegen/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions backend/pkg/codegen/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions backend/pkg/handler/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ func (h *Handler) PaginateActivity(ctx echo.Context, params codegen.PaginateActi
}

var p api.ActivityQueryParams
if params.AppID != nil {
p.AppID = *params.AppID
if params.AppIDorProductID != nil {
appID, err := h.db.GetAppID(*params.AppIDorProductID)
if err != nil {
return appNotFoundResponse(ctx, *params.AppIDorProductID)
}
p.AppID = appID
}
if params.GroupID != nil {
p.GroupID = *params.GroupID
Expand Down
Loading

0 comments on commit eaa4ce0

Please sign in to comment.