Skip to content

Commit

Permalink
server: Endpoints for checking theme updates and updating theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
octavore committed Jul 5, 2017
1 parent 61ac996 commit 4c5f05a
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 56 deletions.
12 changes: 11 additions & 1 deletion proto/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,18 @@ message EnableTLSRequest {
optional bool agreed = 3;
}

message CheckThemeForUpdateResponse {
optional string old_ref = 1;
optional string current_ref = 2;
}

message InstallThemeRequest {
optional string name = 1;
optional string vcs_url = 2;
optional string registry_url = 3;
}
}

message UpdateThemeRequest {
optional string name = 1; // extracted from URL
optional string ref = 2;
}
182 changes: 128 additions & 54 deletions proto/ketchup/api/api.pb.go

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

2 changes: 2 additions & 0 deletions server/api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (m *Module) Init(c *service.Config) {

{"/api/v1/themes", methodGet, m.Auth.MustWithAuth(m.ListThemes)},
{"/api/v1/themes/:name", methodGet, m.Auth.MustWithAuth(m.GetTheme)},
{"/api/v1/themes/:name/updates", methodGet, m.Auth.MustWithAuth(m.CheckThemeForUpdate)},
{"/api/v1/themes/:name/update", methodPost, m.Auth.MustWithAuth(m.UpdateTheme)},
{"/api/v1/themes/:name/templates/:template", methodGet, m.Auth.MustWithAuth(m.GetTemplate)},
{"/api/v1/theme-registry", methodGet, m.Auth.MustWithAuth(m.ThemeRegistry)},
{"/api/v1/theme-install", methodPost, m.Auth.MustWithAuth(m.InstallTheme)},
Expand Down
28 changes: 27 additions & 1 deletion server/api/themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (m *Module) InstallTheme(rw http.ResponseWriter, req *http.Request, par htt
}

// search the registry for the theme package
// install the package
p, err := m.Templates.SearchRegistry(r.GetName())
if err != nil {
return errors.New("error searching registry: %s", err)
Expand All @@ -83,5 +82,32 @@ func (m *Module) InstallTheme(rw http.ResponseWriter, req *http.Request, par htt

m.Logger.Infof("cloning package %s from %s", p.GetName(), p.GetVcsUrl())

// install the package
return m.Templates.InstallThemeFromPackage(p)
}

func (m *Module) CheckThemeForUpdate(rw http.ResponseWriter, req *http.Request, par httprouter.Params) error {
name := par.ByName("name")
_, oldRef, currentRef, err := m.Templates.CheckThemeForUpdate(name)
if err != nil {
return errors.Wrap(err)
}

return m.Router.JSON(rw, http.StatusOK, &api.CheckThemeForUpdateResponse{
OldRef: &oldRef,
CurrentRef: &currentRef,
})
}

func (m *Module) UpdateTheme(rw http.ResponseWriter, req *http.Request, par httprouter.Params) error {
themeName := par.ByName("name")
r := &api.UpdateThemeRequest{}
err := jsonpb.Unmarshal(req.Body, r)
if err != nil {
return errors.Wrap(err)
}
if r.GetName() != "" && r.GetName() != themeName {
return errors.New("theme name mismatch")
}
return m.Templates.UpdateTheme(r.GetName(), r.GetRef())
}

0 comments on commit 4c5f05a

Please sign in to comment.