Skip to content
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

Add core api #235

Merged
merged 5 commits into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- (#183) Add a `configuration` attribute in the `mesg.yml` file to accept docker configuration for your service
- (#187) Stop all services when the MESG Core stops
- (#190) Possibility to `test` or `deploy` a service from a git or GitHub url
- (#235) Add `ListServices` and `GetService` APIs

#### Removed

Expand Down
204 changes: 169 additions & 35 deletions api/core/api.pb.go

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

17 changes: 17 additions & 0 deletions api/core/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ service Core {
rpc StopService (StopServiceRequest) returns (StopServiceReply) {}
rpc DeployService (DeployServiceRequest) returns (DeployServiceReply) {}
rpc DeleteService (DeleteServiceRequest) returns (DeleteServiceReply) {}
rpc ListServices (ListServicesRequest) returns (ListServicesReply) {}
rpc GetService (GetServiceRequest) returns (GetServiceReply) {}
}

message ListenEventRequest {
Expand Down Expand Up @@ -75,4 +77,19 @@ message DeleteServiceRequest {
}

message DeleteServiceReply {
}

message ListServicesRequest {
}

message ListServicesReply {
repeated service.Service services = 1;
}

message GetServiceRequest {
string serviceID = 1;
}

message GetServiceReply {
service.Service service = 1;
}
18 changes: 18 additions & 0 deletions api/core/get_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package core

import (
"github.com/mesg-foundation/core/database/services"
"golang.org/x/net/context"
)

// GetService fetch a service in the db and return ot
func (s *Server) GetService(ctx context.Context, request *GetServiceRequest) (reply *GetServiceReply, err error) {
service, err := services.Get(request.ServiceID)
if err != nil {
return
}
reply = &GetServiceReply{
Service: &service,
}
return
}
26 changes: 26 additions & 0 deletions api/core/get_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package core

import (
"context"
"testing"

"github.com/mesg-foundation/core/database/services"

"github.com/mesg-foundation/core/service"
"github.com/stvp/assert"
)

var servergetservice = new(Server)

func TestGetService(t *testing.T) {
hash, _ := services.Save(&service.Service{
Name: "TestGetService",
})
defer services.Delete(hash)
reply, err := servergetservice.GetService(context.Background(), &GetServiceRequest{
ServiceID: hash,
})
assert.Nil(t, err)
assert.NotNil(t, reply)
assert.Equal(t, reply.Service.Name, "TestGetService")
}
18 changes: 18 additions & 0 deletions api/core/list_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package core

import (
"github.com/mesg-foundation/core/database/services"
"golang.org/x/net/context"
)

// ListServices return all services from the database
func (s *Server) ListServices(ctx context.Context, request *ListServicesRequest) (reply *ListServicesReply, err error) {
services, err := services.All()
if err != nil {
return
}
reply = &ListServicesReply{
Services: services,
}
return
}
18 changes: 18 additions & 0 deletions api/core/list_services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package core

import (
"context"
"testing"

"github.com/mesg-foundation/core/database/services"
"github.com/stvp/assert"
)

var serverlistservices = new(Server)

func TestListServices(t *testing.T) {
servicesFromAPI, err := serverlistservices.ListServices(context.Background(), &ListServicesRequest{})
servicesFromDB, _ := services.All()
assert.Nil(t, err)
assert.Equal(t, len(servicesFromAPI.Services), len(servicesFromDB))
}