-
Notifications
You must be signed in to change notification settings - Fork 43
feat: support gRPC and http apis #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2a77b41
feat(server): add grpc support
h4rikris 7d9363d
feat(server): add error handling to grpc
h4rikris 9acdb65
feat(server): add grpc server options
h4rikris 8315b47
feat(server): add validation to grpc handlers
h4rikris 2988359
feat(server): add grpc health check endpoint
h4rikris f7627ef
refactor(server): move stencil protos to proton
h4rikris 9bba7a0
refactor(server): integrate proto method name changes
h4rikris cffa56a
refactor(server): move proto generated code
h4rikris 82920c5
fix(server): handle nil for Checks type
h4rikris 525ebfe
docs(server): update swagger doc
h4rikris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,13 @@ | ||
| version: v1 | ||
| plugins: | ||
| - name: go | ||
| out: ./server | ||
| opt: paths=source_relative | ||
| - name: go-grpc | ||
| out: ./server | ||
| opt: paths=source_relative | ||
| - name: grpc-gateway | ||
| out: ./server | ||
| opt: paths=source_relative | ||
| - name: openapiv2 | ||
| out: ./server |
This file contains hidden or 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,47 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "github.com/odpf/stencil/server/models" | ||
| stencilv1 "github.com/odpf/stencil/server/odpf/stencil/v1" | ||
| "github.com/odpf/stencil/server/snapshot" | ||
| ) | ||
|
|
||
| func fromProtoToSnapshot(g *stencilv1.Snapshot) *snapshot.Snapshot { | ||
| return &snapshot.Snapshot{ | ||
| ID: g.GetId(), | ||
| Namespace: g.GetNamespace(), | ||
| Name: g.GetName(), | ||
| Version: g.GetVersion(), | ||
| Latest: g.GetLatest(), | ||
| } | ||
| } | ||
|
|
||
| func fromSnapshotToProto(g *snapshot.Snapshot) *stencilv1.Snapshot { | ||
| return &stencilv1.Snapshot{ | ||
| Id: g.ID, | ||
| Namespace: g.Namespace, | ||
| Name: g.Name, | ||
| Version: g.Version, | ||
| Latest: g.Latest, | ||
| } | ||
| } | ||
|
|
||
| func toRulesList(r *stencilv1.Checks) []string { | ||
| var rules []string | ||
| if r == nil { | ||
| return rules | ||
| } | ||
| for _, rule := range r.Except { | ||
| rules = append(rules, rule.String()) | ||
| } | ||
| return rules | ||
| } | ||
|
|
||
| func toFileDownloadRequest(g *stencilv1.DownloadDescriptorRequest) *models.FileDownloadRequest { | ||
| return &models.FileDownloadRequest{ | ||
| Namespace: g.Namespace, | ||
| Name: g.Name, | ||
| Version: g.Version, | ||
| FullNames: g.GetFullnames(), | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,66 +1,41 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "context" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/odpf/stencil/server/models" | ||
| stencilv1 "github.com/odpf/stencil/server/odpf/stencil/v1" | ||
| "github.com/odpf/stencil/server/snapshot" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| // ListNames lists descriptor entries | ||
| func (a *API) ListNames(c *gin.Context) { | ||
| namespace := c.Param("namespace") | ||
| result, err := a.Metadata.ListNames(c.Request.Context(), namespace) | ||
| // ListSnapshots returns list of snapshots. If filters applied it will return filtered snapshot list | ||
| func (a *API) ListSnapshots(ctx context.Context, req *stencilv1.ListSnapshotsRequest) (*stencilv1.ListSnapshotsResponse, error) { | ||
| res := &stencilv1.ListSnapshotsResponse{} | ||
| list, err := a.Metadata.List(ctx, &snapshot.Snapshot{Namespace: req.Namespace, Name: req.Name, Version: req.Version, Latest: req.Latest}) | ||
| if err != nil { | ||
| c.Error(err).SetMeta(models.ErrUnknown) | ||
| return | ||
| return res, err | ||
| } | ||
| c.JSON(http.StatusOK, result) | ||
| } | ||
|
|
||
| // ListVersions lists version numbers for specific name | ||
| func (a *API) ListVersions(c *gin.Context) { | ||
| namespace := c.Param("namespace") | ||
| name := c.Param("name") | ||
| result, err := a.Metadata.ListVersions(c.Request.Context(), namespace, name) | ||
| if err != nil { | ||
| c.Error(err).SetMeta(models.ErrUnknown) | ||
| return | ||
| for _, j := range list { | ||
| res.Snapshots = append(res.Snapshots, fromSnapshotToProto(j)) | ||
| } | ||
| c.JSON(http.StatusOK, result) | ||
| return res, nil | ||
| } | ||
|
|
||
| //GetLatestVersion return latest version number | ||
| func (a *API) GetLatestVersion(c *gin.Context) { | ||
| namespace := c.Param("namespace") | ||
| name := c.Param("name") | ||
| snapshot, err := a.Metadata.GetSnapshot(c.Request.Context(), namespace, name, "", true) | ||
| // PromoteSnapshot marks specified snapshot as latest | ||
| func (a *API) PromoteSnapshot(ctx context.Context, req *stencilv1.PromoteSnapshotRequest) (*stencilv1.PromoteSnapshotResponse, error) { | ||
| st, err := a.Metadata.GetSnapshotByID(ctx, req.Id) | ||
| if err != nil { | ||
| c.Error(err).SetMeta(models.ErrGetMetadataFailed) | ||
| return | ||
| } | ||
| c.JSON(http.StatusOK, gin.H{"version": snapshot.Version}) | ||
| } | ||
|
|
||
| //UpdateLatestVersion return latest version number | ||
| func (a *API) UpdateLatestVersion(c *gin.Context) { | ||
| namespace := c.Param("namespace") | ||
| payload := &models.MetadataUpdateRequest{ | ||
| Namespace: namespace, | ||
| } | ||
| if err := c.ShouldBind(payload); err != nil { | ||
| c.Error(err).SetMeta(models.ErrMissingFormData) | ||
| return | ||
| if err == snapshot.ErrNotFound { | ||
| return nil, status.Error(codes.NotFound, err.Error()) | ||
| } | ||
| return nil, status.Error(codes.Internal, err.Error()) | ||
| } | ||
| err := a.Metadata.UpdateLatestVersion(c.Request.Context(), &snapshot.Snapshot{ | ||
| Namespace: namespace, | ||
| Name: payload.Name, | ||
| Version: payload.Version, | ||
| }) | ||
| err = a.Metadata.UpdateLatestVersion(ctx, st) | ||
| if err != nil { | ||
| c.Error(err).SetMeta(models.ErrMetadataUpdateFailed) | ||
| return | ||
| return nil, err | ||
| } | ||
| c.JSON(http.StatusOK, gin.H{"message": "success"}) | ||
| return &stencilv1.PromoteSnapshotResponse{ | ||
| Snapshot: fromSnapshotToProto(st), | ||
| }, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.