diff --git a/backend/inventory/app/server.go b/backend/inventory/app/server.go new file mode 100644 index 0000000000..5b756b7815 --- /dev/null +++ b/backend/inventory/app/server.go @@ -0,0 +1,33 @@ +package app + +import ( + "context" + "fmt" + "github.com/spotify/backstage/inventory/storage" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + pb "github.com/spotify/backstage/proto/inventory/v1" +) + +// Server is the inventory Grpc server +type Server struct { + Storage *storage.Storage +} + +func (s *Server) CreateEntity(ctx context.Context, req *pb.CreateEntityRequest) (*pb.CreateEntityReply, error) { + err := s.Storage.CreateEntity(req.GetEntity().GetUri()) + if err != nil { + return nil, status.Error(codes.Internal, "could not create entity") + } + return &pb.CreateEntityReply{Entity: req.GetEntity()} , nil +} + +// GetEntity returns an inventory Entity with the selected facts +func (s *Server) GetEntity(ctx context.Context, req *pb.GetEntityRequest) (*pb.GetEntityReply, error) { + entityUri, err := s.Storage.GetEntity(req.GetEntity().GetUri()) + if err != nil { + return nil, status.Error(codes.Internal, fmt.Sprintf("could not get entity %v", err)) + } + return &pb.GetEntityReply{Entity: &pb.Entity{Uri: entityUri}}, nil +} diff --git a/backend/inventory/app/server_test.go b/backend/inventory/app/server_test.go new file mode 100644 index 0000000000..5f4253752a --- /dev/null +++ b/backend/inventory/app/server_test.go @@ -0,0 +1,78 @@ +package app + +import ( + "context" + "fmt" + "github.com/spotify/backstage/inventory/storage" + "io/ioutil" + "os" + "testing" + + pb "github.com/spotify/backstage/proto/inventory/v1" +) + +type TestStorage struct { + Storage *storage.Storage + Path string +} + +// NewTestStorage returns a TestStorage using a temporary path. +func NewTestStorage() *TestStorage { + f, err := ioutil.TempFile("", "") + if err != nil { + panic(fmt.Sprintf("temp file: %s", err)) + } + path := f.Name() + f.Close() + os.Remove(path) + // Open the database. + + config := storage.Config{Path: path} + storage, _ := storage.OpenStorage(config) + // Return wrapped type. + return &TestStorage{Storage: storage, Path: path} +} + +// Close and delete Bolt database. +func (db *TestStorage) Close() { + defer os.Remove(db.Path) + db.Storage.Close() +} + +func TestServerCreateEntity(t *testing.T) { + testStorage := NewTestStorage() + defer testStorage.Close() + s := Server{Storage: testStorage.Storage} + + entity := &pb.Entity{Uri: "boss://test/test"} + createReq := &pb.CreateEntityRequest{Entity: entity} + resp, err := s.CreateEntity(context.Background(), createReq) + if err != nil { + t.Errorf("ServerTest(CreateEntity) got unexpected error %v", err) + } + if resp.GetEntity().GetUri() != entity.GetUri() { + t.Errorf("ServerTest(CreateEntity) expected %v, but got %v", entity.GetUri(), resp.GetEntity().GetUri()) + } +} + +func TestServerGetEntity(t *testing.T) { + testStorage := NewTestStorage() + defer testStorage.Close() + s := Server{Storage: testStorage.Storage} + + entity := &pb.Entity{Uri: "boss://test/test"} + createReq := &pb.CreateEntityRequest{Entity: entity} + s.CreateEntity(context.Background(), createReq) + + req := &pb.GetEntityRequest{Entity: entity} + resp, err := s.GetEntity(context.Background(), req) + if err != nil { + t.Errorf("ServerTest(GetEntity) got unexpected error %v", err) + } + if resp == nil { + t.Errorf("ServerTest(GetEntity) returned nil") + } + if resp.GetEntity().GetUri() != entity.GetUri() { + t.Errorf("ServerTest(GetEntity) got %v, wanted %v", resp.GetEntity().GetUri(), entity.GetUri()) + } +} diff --git a/backend/inventory/go.mod b/backend/inventory/go.mod index 790fbbccfd..7a2e505cf6 100644 --- a/backend/inventory/go.mod +++ b/backend/inventory/go.mod @@ -2,8 +2,14 @@ module github.com/spotify/backstage/inventory go 1.12 +replace github.com/spotify/backstage/proto => ../proto + require ( - github.com/golang/protobuf v1.3.2 + github.com/golang/protobuf v1.3.3 + github.com/spotify/backstage/proto v0.0.0-00010101000000-000000000000 go.etcd.io/bbolt v1.3.3 + golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect + golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect google.golang.org/grpc v1.27.0 + honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect ) diff --git a/backend/inventory/go.sum b/backend/inventory/go.sum index e890fb0fae..f1c63ec689 100644 --- a/backend/inventory/go.sum +++ b/backend/inventory/go.sum @@ -9,6 +9,8 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= diff --git a/backend/inventory/main.go b/backend/inventory/main.go index 98c6641bb1..97859962b7 100644 --- a/backend/inventory/main.go +++ b/backend/inventory/main.go @@ -1,11 +1,12 @@ package main import ( - "context" "log" "net" - pb "github.com/spotify/backstage/inventory/protos" + "github.com/spotify/backstage/inventory/app" + pb "github.com/spotify/backstage/proto/inventory/v1" + "google.golang.org/grpc" ) @@ -13,19 +14,12 @@ const ( port = ":50051" ) -type inventoryServer struct { -} - -func (s *inventoryServer) GetEntity(ctx context.Context, req *pb.GetEntityRequest) (*pb.GetEntityReply, error) { - return &pb.GetEntityReply{}, nil -} - func main() { lis, err := net.Listen("tcp", port) if err != nil { log.Fatalf("failed to listen: %v", err) } grpcServer := grpc.NewServer() - pb.RegisterInventoryServer(grpcServer, &inventoryServer{}) + pb.RegisterInventoryServer(grpcServer, &app.Server{}) grpcServer.Serve(lis) } diff --git a/backend/inventory/storage/storage.go b/backend/inventory/storage/storage.go index 2db9d3a1a3..03849516b2 100644 --- a/backend/inventory/storage/storage.go +++ b/backend/inventory/storage/storage.go @@ -64,3 +64,29 @@ func (s *Storage) GetFact(entityUri, name string) (string, error) { return value, nil } + +func (s *Storage) CreateEntity(entityUri string) error { + return s.db.Update(func(tx *bbolt.Tx) error { + _, err := tx.CreateBucketIfNotExists([]byte(entityUri)) + if err != nil { + return err + } + return nil + }) +} + +func (s *Storage) GetEntity(entityUri string) (string, error) { + err := s.db.View(func(tx *bbolt.Tx) error { + b := tx.Bucket([]byte(entityUri)) + if b == nil { + return fmt.Errorf("bucket '%s' does not exist", entityUri) + } + return nil + }) + + if err != nil { + return "", err + } + + return entityUri, nil +} diff --git a/backend/inventory/protos/inventory.pb.go b/backend/proto/inventory/v1/inventory.pb.go similarity index 54% rename from backend/inventory/protos/inventory.pb.go rename to backend/proto/inventory/v1/inventory.pb.go index d7c5e7bfe8..ea981e1ed8 100644 --- a/backend/inventory/protos/inventory.pb.go +++ b/backend/proto/inventory/v1/inventory.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: protos/inventory.proto +// source: inventory/v1/inventory.proto -package spotify_backstage_inventory_v1alpha1 +package inventoryv1 import ( context "context" @@ -36,7 +36,7 @@ func (m *GetEntityRequest) Reset() { *m = GetEntityRequest{} } func (m *GetEntityRequest) String() string { return proto.CompactTextString(m) } func (*GetEntityRequest) ProtoMessage() {} func (*GetEntityRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1a8706afd37ce83a, []int{0} + return fileDescriptor_70be9028e322f9d8, []int{0} } func (m *GetEntityRequest) XXX_Unmarshal(b []byte) error { @@ -83,7 +83,7 @@ func (m *GetEntityReply) Reset() { *m = GetEntityReply{} } func (m *GetEntityReply) String() string { return proto.CompactTextString(m) } func (*GetEntityReply) ProtoMessage() {} func (*GetEntityReply) Descriptor() ([]byte, []int) { - return fileDescriptor_1a8706afd37ce83a, []int{1} + return fileDescriptor_70be9028e322f9d8, []int{1} } func (m *GetEntityReply) XXX_Unmarshal(b []byte) error { @@ -118,9 +118,86 @@ func (m *GetEntityReply) GetFacts() []*Fact { return nil } +type CreateEntityRequest struct { + Entity *Entity `protobuf:"bytes,1,opt,name=entity,proto3" json:"entity,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateEntityRequest) Reset() { *m = CreateEntityRequest{} } +func (m *CreateEntityRequest) String() string { return proto.CompactTextString(m) } +func (*CreateEntityRequest) ProtoMessage() {} +func (*CreateEntityRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_70be9028e322f9d8, []int{2} +} + +func (m *CreateEntityRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateEntityRequest.Unmarshal(m, b) +} +func (m *CreateEntityRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateEntityRequest.Marshal(b, m, deterministic) +} +func (m *CreateEntityRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateEntityRequest.Merge(m, src) +} +func (m *CreateEntityRequest) XXX_Size() int { + return xxx_messageInfo_CreateEntityRequest.Size(m) +} +func (m *CreateEntityRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateEntityRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateEntityRequest proto.InternalMessageInfo + +func (m *CreateEntityRequest) GetEntity() *Entity { + if m != nil { + return m.Entity + } + return nil +} + +type CreateEntityReply struct { + Entity *Entity `protobuf:"bytes,1,opt,name=entity,proto3" json:"entity,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateEntityReply) Reset() { *m = CreateEntityReply{} } +func (m *CreateEntityReply) String() string { return proto.CompactTextString(m) } +func (*CreateEntityReply) ProtoMessage() {} +func (*CreateEntityReply) Descriptor() ([]byte, []int) { + return fileDescriptor_70be9028e322f9d8, []int{3} +} + +func (m *CreateEntityReply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateEntityReply.Unmarshal(m, b) +} +func (m *CreateEntityReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateEntityReply.Marshal(b, m, deterministic) +} +func (m *CreateEntityReply) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateEntityReply.Merge(m, src) +} +func (m *CreateEntityReply) XXX_Size() int { + return xxx_messageInfo_CreateEntityReply.Size(m) +} +func (m *CreateEntityReply) XXX_DiscardUnknown() { + xxx_messageInfo_CreateEntityReply.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateEntityReply proto.InternalMessageInfo + +func (m *CreateEntityReply) GetEntity() *Entity { + if m != nil { + return m.Entity + } + return nil +} + type Entity struct { - Kind string `protobuf:"bytes,1,opt,name=kind,proto3" json:"kind,omitempty"` - Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + Uri string `protobuf:"bytes,1,opt,name=uri,proto3" json:"uri,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -130,7 +207,7 @@ func (m *Entity) Reset() { *m = Entity{} } func (m *Entity) String() string { return proto.CompactTextString(m) } func (*Entity) ProtoMessage() {} func (*Entity) Descriptor() ([]byte, []int) { - return fileDescriptor_1a8706afd37ce83a, []int{2} + return fileDescriptor_70be9028e322f9d8, []int{4} } func (m *Entity) XXX_Unmarshal(b []byte) error { @@ -151,16 +228,9 @@ func (m *Entity) XXX_DiscardUnknown() { var xxx_messageInfo_Entity proto.InternalMessageInfo -func (m *Entity) GetKind() string { +func (m *Entity) GetUri() string { if m != nil { - return m.Kind - } - return "" -} - -func (m *Entity) GetId() string { - if m != nil { - return m.Id + return m.Uri } return "" } @@ -177,7 +247,7 @@ func (m *Fact) Reset() { *m = Fact{} } func (m *Fact) String() string { return proto.CompactTextString(m) } func (*Fact) ProtoMessage() {} func (*Fact) Descriptor() ([]byte, []int) { - return fileDescriptor_1a8706afd37ce83a, []int{3} + return fileDescriptor_70be9028e322f9d8, []int{5} } func (m *Fact) XXX_Unmarshal(b []byte) error { @@ -213,34 +283,38 @@ func (m *Fact) GetValue() string { } func init() { - proto.RegisterType((*GetEntityRequest)(nil), "spotify.backstage.inventory.v1alpha1.GetEntityRequest") - proto.RegisterType((*GetEntityReply)(nil), "spotify.backstage.inventory.v1alpha1.GetEntityReply") - proto.RegisterType((*Entity)(nil), "spotify.backstage.inventory.v1alpha1.Entity") - proto.RegisterType((*Fact)(nil), "spotify.backstage.inventory.v1alpha1.Fact") + proto.RegisterType((*GetEntityRequest)(nil), "spotify.backstage.inventory.v1.GetEntityRequest") + proto.RegisterType((*GetEntityReply)(nil), "spotify.backstage.inventory.v1.GetEntityReply") + proto.RegisterType((*CreateEntityRequest)(nil), "spotify.backstage.inventory.v1.CreateEntityRequest") + proto.RegisterType((*CreateEntityReply)(nil), "spotify.backstage.inventory.v1.CreateEntityReply") + proto.RegisterType((*Entity)(nil), "spotify.backstage.inventory.v1.Entity") + proto.RegisterType((*Fact)(nil), "spotify.backstage.inventory.v1.Fact") } -func init() { proto.RegisterFile("protos/inventory.proto", fileDescriptor_1a8706afd37ce83a) } +func init() { proto.RegisterFile("inventory/v1/inventory.proto", fileDescriptor_70be9028e322f9d8) } -var fileDescriptor_1a8706afd37ce83a = []byte{ - // 273 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x2f, 0xd6, 0xcf, 0xcc, 0x2b, 0x4b, 0xcd, 0x2b, 0xc9, 0x2f, 0xaa, 0xd4, 0x03, 0x0b, 0x08, - 0xa9, 0x14, 0x17, 0xe4, 0x97, 0x64, 0xa6, 0x55, 0xea, 0x25, 0x25, 0x26, 0x67, 0x17, 0x97, 0x24, - 0xa6, 0xa7, 0xea, 0x21, 0x94, 0x94, 0x19, 0x26, 0xe6, 0x14, 0x64, 0x24, 0x1a, 0x2a, 0xd5, 0x72, - 0x09, 0xb8, 0xa7, 0x96, 0xb8, 0xe6, 0x95, 0x64, 0x96, 0x54, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, - 0x97, 0x08, 0xb9, 0x70, 0xb1, 0xa5, 0x82, 0x05, 0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x74, - 0xf4, 0x88, 0x31, 0x4a, 0x0f, 0x6a, 0x08, 0x54, 0xaf, 0x90, 0x32, 0x17, 0x6f, 0x66, 0x5e, 0x72, - 0x4e, 0x69, 0x4a, 0x6a, 0x7c, 0x5a, 0x62, 0x72, 0x49, 0xb1, 0x04, 0x93, 0x02, 0xb3, 0x06, 0x67, - 0x10, 0x0f, 0x54, 0xd0, 0x0d, 0x24, 0xa6, 0x34, 0x83, 0x91, 0x8b, 0x0f, 0xc9, 0xfe, 0x82, 0x9c, - 0x4a, 0x2a, 0xd9, 0xee, 0xc0, 0xc5, 0x8a, 0xb0, 0x95, 0xdb, 0x48, 0x8b, 0x38, 0x43, 0x40, 0x8e, - 0x0a, 0x82, 0x68, 0x54, 0xd2, 0xe1, 0x62, 0x83, 0x98, 0x29, 0x24, 0xc4, 0xc5, 0x92, 0x9d, 0x99, - 0x97, 0x02, 0x76, 0x0f, 0x67, 0x10, 0x98, 0x2d, 0xc4, 0xc7, 0xc5, 0x94, 0x99, 0x22, 0xc1, 0x04, - 0x16, 0x61, 0xca, 0x4c, 0x51, 0x32, 0xe0, 0x62, 0x01, 0x69, 0x06, 0xa9, 0xcd, 0x4b, 0xcc, 0x4d, - 0x85, 0xa9, 0x05, 0xb1, 0x85, 0x44, 0xb8, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x53, 0xa1, 0xca, 0x21, - 0x1c, 0xa3, 0x36, 0x46, 0x2e, 0x4e, 0x4f, 0x98, 0x13, 0x84, 0x2a, 0xb9, 0x38, 0xe1, 0xe1, 0x20, - 0x64, 0x46, 0x9c, 0x6b, 0xd1, 0x23, 0x4e, 0xca, 0x84, 0x64, 0x7d, 0x05, 0x39, 0x95, 0x49, 0x6c, - 0xe0, 0xf4, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x66, 0x0d, 0x53, 0x49, 0x02, 0x00, - 0x00, +var fileDescriptor_70be9028e322f9d8 = []byte{ + // 307 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc9, 0xcc, 0x2b, 0x4b, + 0xcd, 0x2b, 0xc9, 0x2f, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x87, 0x73, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, + 0xf2, 0x85, 0xe4, 0x8a, 0x0b, 0xf2, 0x4b, 0x32, 0xd3, 0x2a, 0xf5, 0x92, 0x12, 0x93, 0xb3, 0x8b, + 0x4b, 0x12, 0xd3, 0x53, 0xf5, 0x10, 0x4a, 0xca, 0x0c, 0x95, 0xca, 0xb9, 0x04, 0xdc, 0x53, 0x4b, + 0x5c, 0xf3, 0x4a, 0x32, 0x4b, 0x2a, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0xec, 0xb8, + 0xd8, 0x52, 0xc1, 0x02, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x6a, 0x7a, 0xf8, 0x0d, 0xd1, + 0x83, 0x6a, 0x87, 0xea, 0x12, 0x52, 0xe6, 0xe2, 0xcd, 0xcc, 0x4b, 0xce, 0x29, 0x4d, 0x49, 0x8d, + 0x4f, 0x4b, 0x4c, 0x2e, 0x29, 0x96, 0x60, 0x52, 0x60, 0xd6, 0xe0, 0x0c, 0xe2, 0x81, 0x0a, 0xba, + 0x81, 0xc4, 0x94, 0x7a, 0x18, 0xb9, 0xf8, 0x90, 0x6c, 0x2e, 0xc8, 0xa9, 0xa4, 0xd8, 0x5e, 0x2b, + 0x2e, 0x56, 0x84, 0x7d, 0xdc, 0x46, 0x2a, 0x84, 0xb4, 0x83, 0x1c, 0x12, 0x04, 0xd1, 0xa2, 0x14, + 0xca, 0x25, 0xec, 0x5c, 0x94, 0x9a, 0x58, 0x92, 0x4a, 0xd5, 0xa0, 0x50, 0x0a, 0xe6, 0x12, 0x44, + 0x35, 0x96, 0x0a, 0xfe, 0x54, 0x92, 0xe2, 0x62, 0x83, 0x88, 0x08, 0x09, 0x70, 0x31, 0x97, 0x16, + 0x65, 0x82, 0x8d, 0xe1, 0x0c, 0x02, 0x31, 0x95, 0x0c, 0xb8, 0x58, 0x40, 0xde, 0x12, 0x12, 0xe2, + 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x85, 0x4a, 0x81, 0xd9, 0x42, 0x22, 0x5c, 0xac, 0x65, 0x89, 0x39, + 0xa5, 0xa9, 0x12, 0x4c, 0x60, 0x41, 0x08, 0xc7, 0xe8, 0x13, 0x23, 0x17, 0xa7, 0x27, 0xcc, 0x36, + 0xa1, 0x5c, 0x2e, 0x4e, 0x78, 0xac, 0x08, 0x19, 0x10, 0x72, 0x18, 0x7a, 0xd2, 0x91, 0xd2, 0x23, + 0x41, 0x07, 0x28, 0x28, 0xca, 0xb8, 0x78, 0x90, 0xc3, 0x47, 0xc8, 0x98, 0x90, 0x7e, 0x2c, 0x91, + 0x24, 0x65, 0x48, 0x9a, 0xa6, 0x82, 0x9c, 0x4a, 0x27, 0xde, 0x28, 0x6e, 0xb8, 0x8a, 0x32, 0xc3, + 0x24, 0x36, 0x70, 0x66, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x24, 0xd0, 0xf1, 0x50, 0x4c, + 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -256,6 +330,7 @@ const _ = grpc.SupportPackageIsVersion6 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type InventoryClient interface { GetEntity(ctx context.Context, in *GetEntityRequest, opts ...grpc.CallOption) (*GetEntityReply, error) + CreateEntity(ctx context.Context, in *CreateEntityRequest, opts ...grpc.CallOption) (*CreateEntityReply, error) } type inventoryClient struct { @@ -268,7 +343,16 @@ func NewInventoryClient(cc grpc.ClientConnInterface) InventoryClient { func (c *inventoryClient) GetEntity(ctx context.Context, in *GetEntityRequest, opts ...grpc.CallOption) (*GetEntityReply, error) { out := new(GetEntityReply) - err := c.cc.Invoke(ctx, "/spotify.backstage.inventory.v1alpha1.Inventory/GetEntity", in, out, opts...) + err := c.cc.Invoke(ctx, "/spotify.backstage.inventory.v1.Inventory/GetEntity", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *inventoryClient) CreateEntity(ctx context.Context, in *CreateEntityRequest, opts ...grpc.CallOption) (*CreateEntityReply, error) { + out := new(CreateEntityReply) + err := c.cc.Invoke(ctx, "/spotify.backstage.inventory.v1.Inventory/CreateEntity", in, out, opts...) if err != nil { return nil, err } @@ -278,6 +362,7 @@ func (c *inventoryClient) GetEntity(ctx context.Context, in *GetEntityRequest, o // InventoryServer is the server API for Inventory service. type InventoryServer interface { GetEntity(context.Context, *GetEntityRequest) (*GetEntityReply, error) + CreateEntity(context.Context, *CreateEntityRequest) (*CreateEntityReply, error) } // UnimplementedInventoryServer can be embedded to have forward compatible implementations. @@ -287,6 +372,9 @@ type UnimplementedInventoryServer struct { func (*UnimplementedInventoryServer) GetEntity(ctx context.Context, req *GetEntityRequest) (*GetEntityReply, error) { return nil, status.Errorf(codes.Unimplemented, "method GetEntity not implemented") } +func (*UnimplementedInventoryServer) CreateEntity(ctx context.Context, req *CreateEntityRequest) (*CreateEntityReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateEntity not implemented") +} func RegisterInventoryServer(s *grpc.Server, srv InventoryServer) { s.RegisterService(&_Inventory_serviceDesc, srv) @@ -302,7 +390,7 @@ func _Inventory_GetEntity_Handler(srv interface{}, ctx context.Context, dec func } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/spotify.backstage.inventory.v1alpha1.Inventory/GetEntity", + FullMethod: "/spotify.backstage.inventory.v1.Inventory/GetEntity", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(InventoryServer).GetEntity(ctx, req.(*GetEntityRequest)) @@ -310,15 +398,37 @@ func _Inventory_GetEntity_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Inventory_CreateEntity_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateEntityRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(InventoryServer).CreateEntity(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/spotify.backstage.inventory.v1.Inventory/CreateEntity", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(InventoryServer).CreateEntity(ctx, req.(*CreateEntityRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Inventory_serviceDesc = grpc.ServiceDesc{ - ServiceName: "spotify.backstage.inventory.v1alpha1.Inventory", + ServiceName: "spotify.backstage.inventory.v1.Inventory", HandlerType: (*InventoryServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "GetEntity", Handler: _Inventory_GetEntity_Handler, }, + { + MethodName: "CreateEntity", + Handler: _Inventory_CreateEntity_Handler, + }, }, Streams: []grpc.StreamDesc{}, - Metadata: "protos/inventory.proto", + Metadata: "inventory/v1/inventory.proto", } diff --git a/protos/inventory.proto b/proto/inventory/v1/inventory.proto similarity index 56% rename from protos/inventory.proto rename to proto/inventory/v1/inventory.proto index 10eeea4ea5..0b3f9f4131 100644 --- a/protos/inventory.proto +++ b/proto/inventory/v1/inventory.proto @@ -1,9 +1,12 @@ syntax = "proto3"; -package spotify.backstage.inventory.v1alpha1; +package spotify.backstage.inventory.v1; + +option go_package = "inventoryv1"; service Inventory { rpc GetEntity(GetEntityRequest) returns (GetEntityReply); + rpc CreateEntity(CreateEntityRequest) returns (CreateEntityReply); } message GetEntityRequest { @@ -16,9 +19,16 @@ message GetEntityReply { repeated Fact facts = 2; } +message CreateEntityRequest { + Entity entity = 1; +} + +message CreateEntityReply { + Entity entity = 1; +} + message Entity { - string kind = 1; - string id = 2; + string uri = 1; } message Fact {