From ad4b9585c4330760d2074217386142632756b7ee Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 4 Feb 2020 11:58:13 +0100 Subject: [PATCH] add proto/ with prototool management + backend/proto and backend/identity example --- backend/identity/go.mod | 10 + backend/identity/go.sum | 49 +++ backend/identity/main.go | 38 ++ backend/proto/go.mod | 8 + backend/proto/go.sum | 47 +++ backend/proto/identity/v1/identity.pb.go | 434 +++++++++++++++++++++++ proto/README.md | 29 ++ proto/identity/v1/identity.proto | 42 +++ proto/prototool.yaml | 18 + 9 files changed, 675 insertions(+) create mode 100644 backend/identity/go.mod create mode 100644 backend/identity/go.sum create mode 100644 backend/identity/main.go create mode 100644 backend/proto/go.mod create mode 100644 backend/proto/go.sum create mode 100644 backend/proto/identity/v1/identity.pb.go create mode 100644 proto/README.md create mode 100644 proto/identity/v1/identity.proto create mode 100644 proto/prototool.yaml diff --git a/backend/identity/go.mod b/backend/identity/go.mod new file mode 100644 index 0000000000..7514099092 --- /dev/null +++ b/backend/identity/go.mod @@ -0,0 +1,10 @@ +module github.com/spotify/backstage/identity + +go 1.13 + +replace github.com/spotify/backstage/proto => ../proto + +require ( + github.com/spotify/backstage/proto v0.0.0-00010101000000-000000000000 + google.golang.org/grpc v1.27.0 +) diff --git a/backend/identity/go.sum b/backend/identity/go.sum new file mode 100644 index 0000000000..7ec6345fd2 --- /dev/null +++ b/backend/identity/go.sum @@ -0,0 +1,49 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +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= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/backend/identity/main.go b/backend/identity/main.go new file mode 100644 index 0000000000..ed48a3ab6f --- /dev/null +++ b/backend/identity/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "context" + "log" + "net" + + identityv1 "github.com/spotify/backstage/proto/identity/v1" + "google.golang.org/grpc" +) + +const ( + port = ":50051" +) + +func main() { + lis, err := net.Listen("tcp", port) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + + grpcServer := grpc.NewServer() + identityv1.RegisterIdentityServer(grpcServer, &server{}) + + log.Println("Serving Identity Service") + grpcServer.Serve(lis) +} + +type server struct { +} + +func (s *server) GetUser(ctx context.Context, req *identityv1.GetUserRequest) (*identityv1.GetUserReply, error) { + return &identityv1.GetUserReply{}, nil +} + +func (s *server) GetGroup(ctx context.Context, req *identityv1.GetGroupRequest) (*identityv1.GetGroupReply, error) { + return &identityv1.GetGroupReply{}, nil +} diff --git a/backend/proto/go.mod b/backend/proto/go.mod new file mode 100644 index 0000000000..8ffc37c2d2 --- /dev/null +++ b/backend/proto/go.mod @@ -0,0 +1,8 @@ +module github.com/spotify/backstage/proto + +go 1.13 + +require ( + github.com/golang/protobuf v1.3.3 + google.golang.org/grpc v1.27.0 +) diff --git a/backend/proto/go.sum b/backend/proto/go.sum new file mode 100644 index 0000000000..75a87b6f34 --- /dev/null +++ b/backend/proto/go.sum @@ -0,0 +1,47 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +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= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/backend/proto/identity/v1/identity.pb.go b/backend/proto/identity/v1/identity.pb.go new file mode 100644 index 0000000000..5d016b234d --- /dev/null +++ b/backend/proto/identity/v1/identity.pb.go @@ -0,0 +1,434 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: identity/v1/identity.proto + +package identityv1 + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type GetUserRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetUserRequest) Reset() { *m = GetUserRequest{} } +func (m *GetUserRequest) String() string { return proto.CompactTextString(m) } +func (*GetUserRequest) ProtoMessage() {} +func (*GetUserRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2343b5ee8923b571, []int{0} +} + +func (m *GetUserRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetUserRequest.Unmarshal(m, b) +} +func (m *GetUserRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetUserRequest.Marshal(b, m, deterministic) +} +func (m *GetUserRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetUserRequest.Merge(m, src) +} +func (m *GetUserRequest) XXX_Size() int { + return xxx_messageInfo_GetUserRequest.Size(m) +} +func (m *GetUserRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetUserRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetUserRequest proto.InternalMessageInfo + +func (m *GetUserRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type GetUserReply struct { + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + Groups []*Group `protobuf:"bytes,2,rep,name=groups,proto3" json:"groups,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetUserReply) Reset() { *m = GetUserReply{} } +func (m *GetUserReply) String() string { return proto.CompactTextString(m) } +func (*GetUserReply) ProtoMessage() {} +func (*GetUserReply) Descriptor() ([]byte, []int) { + return fileDescriptor_2343b5ee8923b571, []int{1} +} + +func (m *GetUserReply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetUserReply.Unmarshal(m, b) +} +func (m *GetUserReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetUserReply.Marshal(b, m, deterministic) +} +func (m *GetUserReply) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetUserReply.Merge(m, src) +} +func (m *GetUserReply) XXX_Size() int { + return xxx_messageInfo_GetUserReply.Size(m) +} +func (m *GetUserReply) XXX_DiscardUnknown() { + xxx_messageInfo_GetUserReply.DiscardUnknown(m) +} + +var xxx_messageInfo_GetUserReply proto.InternalMessageInfo + +func (m *GetUserReply) GetUser() *User { + if m != nil { + return m.User + } + return nil +} + +func (m *GetUserReply) GetGroups() []*Group { + if m != nil { + return m.Groups + } + return nil +} + +type GetGroupRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetGroupRequest) Reset() { *m = GetGroupRequest{} } +func (m *GetGroupRequest) String() string { return proto.CompactTextString(m) } +func (*GetGroupRequest) ProtoMessage() {} +func (*GetGroupRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2343b5ee8923b571, []int{2} +} + +func (m *GetGroupRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetGroupRequest.Unmarshal(m, b) +} +func (m *GetGroupRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetGroupRequest.Marshal(b, m, deterministic) +} +func (m *GetGroupRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetGroupRequest.Merge(m, src) +} +func (m *GetGroupRequest) XXX_Size() int { + return xxx_messageInfo_GetGroupRequest.Size(m) +} +func (m *GetGroupRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetGroupRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetGroupRequest proto.InternalMessageInfo + +func (m *GetGroupRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type GetGroupReply struct { + Groups *Group `protobuf:"bytes,1,opt,name=groups,proto3" json:"groups,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetGroupReply) Reset() { *m = GetGroupReply{} } +func (m *GetGroupReply) String() string { return proto.CompactTextString(m) } +func (*GetGroupReply) ProtoMessage() {} +func (*GetGroupReply) Descriptor() ([]byte, []int) { + return fileDescriptor_2343b5ee8923b571, []int{3} +} + +func (m *GetGroupReply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetGroupReply.Unmarshal(m, b) +} +func (m *GetGroupReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetGroupReply.Marshal(b, m, deterministic) +} +func (m *GetGroupReply) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetGroupReply.Merge(m, src) +} +func (m *GetGroupReply) XXX_Size() int { + return xxx_messageInfo_GetGroupReply.Size(m) +} +func (m *GetGroupReply) XXX_DiscardUnknown() { + xxx_messageInfo_GetGroupReply.DiscardUnknown(m) +} + +var xxx_messageInfo_GetGroupReply proto.InternalMessageInfo + +func (m *GetGroupReply) GetGroups() *Group { + if m != nil { + return m.Groups + } + return nil +} + +type User struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *User) Reset() { *m = User{} } +func (m *User) String() string { return proto.CompactTextString(m) } +func (*User) ProtoMessage() {} +func (*User) Descriptor() ([]byte, []int) { + return fileDescriptor_2343b5ee8923b571, []int{4} +} + +func (m *User) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_User.Unmarshal(m, b) +} +func (m *User) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_User.Marshal(b, m, deterministic) +} +func (m *User) XXX_Merge(src proto.Message) { + xxx_messageInfo_User.Merge(m, src) +} +func (m *User) XXX_Size() int { + return xxx_messageInfo_User.Size(m) +} +func (m *User) XXX_DiscardUnknown() { + xxx_messageInfo_User.DiscardUnknown(m) +} + +var xxx_messageInfo_User proto.InternalMessageInfo + +func (m *User) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *User) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +type Group struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Users []*User `protobuf:"bytes,2,rep,name=users,proto3" json:"users,omitempty"` + Groups []*Group `protobuf:"bytes,3,rep,name=groups,proto3" json:"groups,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Group) Reset() { *m = Group{} } +func (m *Group) String() string { return proto.CompactTextString(m) } +func (*Group) ProtoMessage() {} +func (*Group) Descriptor() ([]byte, []int) { + return fileDescriptor_2343b5ee8923b571, []int{5} +} + +func (m *Group) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Group.Unmarshal(m, b) +} +func (m *Group) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Group.Marshal(b, m, deterministic) +} +func (m *Group) XXX_Merge(src proto.Message) { + xxx_messageInfo_Group.Merge(m, src) +} +func (m *Group) XXX_Size() int { + return xxx_messageInfo_Group.Size(m) +} +func (m *Group) XXX_DiscardUnknown() { + xxx_messageInfo_Group.DiscardUnknown(m) +} + +var xxx_messageInfo_Group proto.InternalMessageInfo + +func (m *Group) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Group) GetUsers() []*User { + if m != nil { + return m.Users + } + return nil +} + +func (m *Group) GetGroups() []*Group { + if m != nil { + return m.Groups + } + return nil +} + +func init() { + proto.RegisterType((*GetUserRequest)(nil), "spotify.backstage.identity.v1.GetUserRequest") + proto.RegisterType((*GetUserReply)(nil), "spotify.backstage.identity.v1.GetUserReply") + proto.RegisterType((*GetGroupRequest)(nil), "spotify.backstage.identity.v1.GetGroupRequest") + proto.RegisterType((*GetGroupReply)(nil), "spotify.backstage.identity.v1.GetGroupReply") + proto.RegisterType((*User)(nil), "spotify.backstage.identity.v1.User") + proto.RegisterType((*Group)(nil), "spotify.backstage.identity.v1.Group") +} + +func init() { proto.RegisterFile("identity/v1/identity.proto", fileDescriptor_2343b5ee8923b571) } + +var fileDescriptor_2343b5ee8923b571 = []byte{ + // 297 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xca, 0x4c, 0x49, 0xcd, + 0x2b, 0xc9, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, 0x87, 0xb1, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, + 0x85, 0x64, 0x8b, 0x0b, 0xf2, 0x4b, 0x32, 0xd3, 0x2a, 0xf5, 0x92, 0x12, 0x93, 0xb3, 0x8b, 0x4b, + 0x12, 0xd3, 0x53, 0xf5, 0xe0, 0x2a, 0xca, 0x0c, 0x95, 0x14, 0xb8, 0xf8, 0xdc, 0x53, 0x4b, 0x42, + 0x8b, 0x53, 0x8b, 0x82, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0xf8, 0xb8, 0x98, 0x32, 0x53, + 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x98, 0x32, 0x53, 0x94, 0x5a, 0x19, 0xb9, 0x78, 0xe0, + 0x4a, 0x0a, 0x72, 0x2a, 0x85, 0xcc, 0xb9, 0x58, 0x4a, 0x8b, 0x53, 0x8b, 0xc0, 0x4a, 0xb8, 0x8d, + 0x94, 0xf5, 0xf0, 0x5a, 0xa0, 0x07, 0xd6, 0x07, 0xd6, 0x20, 0x64, 0xc3, 0xc5, 0x96, 0x5e, 0x94, + 0x5f, 0x5a, 0x50, 0x2c, 0xc1, 0xa4, 0xc0, 0xac, 0xc1, 0x6d, 0xa4, 0x42, 0x40, 0xab, 0x3b, 0x48, + 0x71, 0x10, 0x54, 0x8f, 0x92, 0x22, 0x17, 0xbf, 0x7b, 0x6a, 0x09, 0x44, 0x0c, 0x87, 0x53, 0x7d, + 0xb9, 0x78, 0x11, 0x4a, 0x40, 0x4e, 0x45, 0xd8, 0x08, 0x71, 0x2c, 0x69, 0x36, 0x6a, 0x71, 0xb1, + 0x80, 0x5c, 0x8f, 0x6e, 0x8d, 0x90, 0x10, 0x17, 0x4b, 0x5e, 0x62, 0x6e, 0xaa, 0x04, 0x13, 0x58, + 0x04, 0xcc, 0x56, 0x9a, 0xc0, 0xc8, 0xc5, 0x0a, 0xd6, 0x8d, 0xa1, 0xda, 0x92, 0x8b, 0x15, 0xe4, + 0x7b, 0x98, 0xa7, 0x89, 0x0a, 0x2f, 0x88, 0x0e, 0x24, 0xe7, 0x33, 0x93, 0x1e, 0x60, 0x46, 0xb7, + 0x19, 0xb9, 0x38, 0x3c, 0xa1, 0xb2, 0x42, 0xa9, 0x5c, 0xec, 0xd0, 0x48, 0x14, 0xd2, 0x25, 0x64, + 0x0a, 0x4a, 0x7a, 0x90, 0xd2, 0x26, 0x56, 0x39, 0x28, 0xc0, 0x33, 0xb8, 0x38, 0x60, 0x31, 0x20, + 0xa4, 0x47, 0x58, 0x23, 0x72, 0x6c, 0x4a, 0xe9, 0x10, 0xad, 0xbe, 0x20, 0xa7, 0xd2, 0x89, 0x27, + 0x8a, 0x0b, 0x26, 0x59, 0x66, 0x98, 0xc4, 0x06, 0x4e, 0xec, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x5f, 0xf8, 0xf1, 0xa3, 0x0a, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// IdentityClient is the client API for Identity service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type IdentityClient interface { + // Returned user's groups will only have ID field populated + GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserReply, error) + // Child groups will only have their ID fields populated + // Users in the group will not have their groups popuplated + GetGroup(ctx context.Context, in *GetGroupRequest, opts ...grpc.CallOption) (*GetGroupReply, error) +} + +type identityClient struct { + cc *grpc.ClientConn +} + +func NewIdentityClient(cc *grpc.ClientConn) IdentityClient { + return &identityClient{cc} +} + +func (c *identityClient) GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserReply, error) { + out := new(GetUserReply) + err := c.cc.Invoke(ctx, "/spotify.backstage.identity.v1.Identity/GetUser", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *identityClient) GetGroup(ctx context.Context, in *GetGroupRequest, opts ...grpc.CallOption) (*GetGroupReply, error) { + out := new(GetGroupReply) + err := c.cc.Invoke(ctx, "/spotify.backstage.identity.v1.Identity/GetGroup", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// IdentityServer is the server API for Identity service. +type IdentityServer interface { + // Returned user's groups will only have ID field populated + GetUser(context.Context, *GetUserRequest) (*GetUserReply, error) + // Child groups will only have their ID fields populated + // Users in the group will not have their groups popuplated + GetGroup(context.Context, *GetGroupRequest) (*GetGroupReply, error) +} + +func RegisterIdentityServer(s *grpc.Server, srv IdentityServer) { + s.RegisterService(&_Identity_serviceDesc, srv) +} + +func _Identity_GetUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetUserRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(IdentityServer).GetUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/spotify.backstage.identity.v1.Identity/GetUser", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(IdentityServer).GetUser(ctx, req.(*GetUserRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Identity_GetGroup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetGroupRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(IdentityServer).GetGroup(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/spotify.backstage.identity.v1.Identity/GetGroup", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(IdentityServer).GetGroup(ctx, req.(*GetGroupRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Identity_serviceDesc = grpc.ServiceDesc{ + ServiceName: "spotify.backstage.identity.v1.Identity", + HandlerType: (*IdentityServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetUser", + Handler: _Identity_GetUser_Handler, + }, + { + MethodName: "GetGroup", + Handler: _Identity_GetGroup_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "identity/v1/identity.proto", +} diff --git a/proto/README.md b/proto/README.md new file mode 100644 index 0000000000..799f62b650 --- /dev/null +++ b/proto/README.md @@ -0,0 +1,29 @@ +# Backstage proto + +Collection of all Backstage protobuf definitions. + +## Usage + +Managed with prototool, install instructions at https://github.com/uber/prototool/blob/dev/docs/install.md + +### Generate code + +Run to generate code to `backend/proto/`: + +``` +$ prototool generate +``` + +Generated code should be check in to the repo. + +### Import generated go code + +Example import of inventory: + +```go +package spotify.backstage.identity.v1; + +func main() { + identityv1.NewInventoryClient(nil) +} +``` diff --git a/proto/identity/v1/identity.proto b/proto/identity/v1/identity.proto new file mode 100644 index 0000000000..ff3ca12cb1 --- /dev/null +++ b/proto/identity/v1/identity.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package spotify.backstage.identity.v1; + +option go_package = "identityv1"; + +service Identity { + // Returned user's groups will only have ID field populated + rpc GetUser(GetUserRequest) returns (GetUserReply); + + // Child groups will only have their ID fields populated + // Users in the group will not have their groups popuplated + rpc GetGroup(GetGroupRequest) returns (GetGroupReply); +} + +message GetUserRequest { + string id = 1; +} + +message GetUserReply { + User user = 1; + repeated Group groups = 2; +} + +message GetGroupRequest { + string id = 1; +} + +message GetGroupReply { + Group groups = 1; +} + +message User { + string id = 1; + string name = 2; +} + +message Group { + string id = 1; + repeated User users = 2; + repeated Group groups = 3; +} diff --git a/proto/prototool.yaml b/proto/prototool.yaml new file mode 100644 index 0000000000..f20878e163 --- /dev/null +++ b/proto/prototool.yaml @@ -0,0 +1,18 @@ + +protoc: + version: 3.8.0 +lint: + group: uber2 + rules: + remove: + - REQUEST_RESPONSE_TYPES_UNIQUE + file_header: + path: ../LICENSE +generate: + go_options: + import_path: github.com/spotify/backstage + plugins: + - name: go + type: go + flags: plugins=grpc + output: ../backend/proto