bootcfg: Add gRPC Profile service and types

This commit is contained in:
Dalton Hubble
2016-03-03 10:57:11 -08:00
parent 7433a9f25e
commit 9a0de72de8
14 changed files with 723 additions and 366 deletions

View File

@@ -14,8 +14,9 @@ type Config struct {
// Client provides a bootcfg client RPC session.
type Client struct {
Groups pb.GroupsClient
conn *grpc.ClientConn
Groups pb.GroupsClient
Profiles pb.ProfilesClient
conn *grpc.ClientConn
}
// New creates a new Client from the given Config.
@@ -23,14 +24,15 @@ func New(config *Config) (*Client, error) {
return newClient(config)
}
func newClient(config *Config) (*Client, error) {
func newClient(config *Config) (*Client, error) {
conn, err := retryDialer(config)
if err != nil {
return nil, err
}
client := &Client{
Groups: pb.NewGroupsClient(conn),
conn: conn,
conn: conn,
Groups: pb.NewGroupsClient(conn),
Profiles: pb.NewProfilesClient(conn),
}
return client, nil
}

View File

@@ -3,39 +3,61 @@ package server
import (
"golang.org/x/net/context"
"github.com/coreos/coreos-baremetal/bootcfg/storage"
pb "github.com/coreos/coreos-baremetal/bootcfg/server/serverpb"
"github.com/coreos/coreos-baremetal/bootcfg/storage"
)
// Config configures an RPC Server.
// Server defines a bootcfg Server.
type Server interface {
pb.GroupsServer
pb.ProfilesServer
}
// Config configures a server implementation.
type Config struct {
Store storage.Store
}
// server implements the grpc GroupsServer interface.
// server implements the Server interface.
type server struct {
store storage.Store
}
// NewServer returns a new server.
func NewServer(config *Config) pb.GroupsServer {
// NewServer returns a new Server.
func NewServer(config *Config) Server {
return &server{
store: config.Store,
}
}
func (s *server) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse, error) {
group, err := s.store.GetGroup(req.Id)
func (s *server) GroupGet(ctx context.Context, req *pb.GroupGetRequest) (*pb.GroupGetResponse, error) {
group, err := s.store.GroupGet(req.Id)
if err != nil {
return nil, err
}
return &pb.GetResponse{Group: group}, nil
return &pb.GroupGetResponse{Group: group}, nil
}
func (s *server) List(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error) {
groups, err := s.store.ListGroups()
func (s *server) GroupList(ctx context.Context, req *pb.GroupListRequest) (*pb.GroupListResponse, error) {
groups, err := s.store.GroupList()
if err != nil {
return nil, err
}
return &pb.ListResponse{Groups: groups}, nil
}
return &pb.GroupListResponse{Groups: groups}, nil
}
func (s *server) ProfileGet(ctx context.Context, req *pb.ProfileGetRequest) (*pb.ProfileGetResponse, error) {
profile, err := s.store.ProfileGet(req.Id)
if err != nil {
return nil, err
}
return &pb.ProfileGetResponse{Profile: profile}, nil
}
func (s *server) ProfileList(ctx context.Context, req *pb.ProfileListRequest) (*pb.ProfileListResponse, error) {
profiles, err := s.store.ProfileList()
if err != nil {
return nil, err
}
return &pb.ProfileListResponse{Profiles: profiles}, nil
}

View File

@@ -0,0 +1,356 @@
// Code generated by protoc-gen-go.
// source: rpc.proto
// DO NOT EDIT!
/*
Package serverpb is a generated protocol buffer package.
It is generated from these files:
rpc.proto
It has these top-level messages:
GroupGetRequest
GroupListRequest
GroupGetResponse
GroupListResponse
ProfileGetRequest
ProfileGetResponse
ProfileListRequest
ProfileListResponse
*/
package serverpb
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import storagepb "github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// 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.
const _ = proto.ProtoPackageIsVersion1
type GroupGetRequest struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}
func (m *GroupGetRequest) Reset() { *m = GroupGetRequest{} }
func (m *GroupGetRequest) String() string { return proto.CompactTextString(m) }
func (*GroupGetRequest) ProtoMessage() {}
func (*GroupGetRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type GroupListRequest struct {
}
func (m *GroupListRequest) Reset() { *m = GroupListRequest{} }
func (m *GroupListRequest) String() string { return proto.CompactTextString(m) }
func (*GroupListRequest) ProtoMessage() {}
func (*GroupListRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type GroupGetResponse struct {
Group *storagepb.Group `protobuf:"bytes,1,opt,name=group" json:"group,omitempty"`
}
func (m *GroupGetResponse) Reset() { *m = GroupGetResponse{} }
func (m *GroupGetResponse) String() string { return proto.CompactTextString(m) }
func (*GroupGetResponse) ProtoMessage() {}
func (*GroupGetResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *GroupGetResponse) GetGroup() *storagepb.Group {
if m != nil {
return m.Group
}
return nil
}
type GroupListResponse struct {
Groups []*storagepb.Group `protobuf:"bytes,1,rep,name=groups" json:"groups,omitempty"`
}
func (m *GroupListResponse) Reset() { *m = GroupListResponse{} }
func (m *GroupListResponse) String() string { return proto.CompactTextString(m) }
func (*GroupListResponse) ProtoMessage() {}
func (*GroupListResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *GroupListResponse) GetGroups() []*storagepb.Group {
if m != nil {
return m.Groups
}
return nil
}
type ProfileGetRequest struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}
func (m *ProfileGetRequest) Reset() { *m = ProfileGetRequest{} }
func (m *ProfileGetRequest) String() string { return proto.CompactTextString(m) }
func (*ProfileGetRequest) ProtoMessage() {}
func (*ProfileGetRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
type ProfileGetResponse struct {
Profile *storagepb.Profile `protobuf:"bytes,1,opt,name=profile" json:"profile,omitempty"`
}
func (m *ProfileGetResponse) Reset() { *m = ProfileGetResponse{} }
func (m *ProfileGetResponse) String() string { return proto.CompactTextString(m) }
func (*ProfileGetResponse) ProtoMessage() {}
func (*ProfileGetResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
func (m *ProfileGetResponse) GetProfile() *storagepb.Profile {
if m != nil {
return m.Profile
}
return nil
}
type ProfileListRequest struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}
func (m *ProfileListRequest) Reset() { *m = ProfileListRequest{} }
func (m *ProfileListRequest) String() string { return proto.CompactTextString(m) }
func (*ProfileListRequest) ProtoMessage() {}
func (*ProfileListRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
type ProfileListResponse struct {
Profiles []*storagepb.Profile `protobuf:"bytes,1,rep,name=profiles" json:"profiles,omitempty"`
}
func (m *ProfileListResponse) Reset() { *m = ProfileListResponse{} }
func (m *ProfileListResponse) String() string { return proto.CompactTextString(m) }
func (*ProfileListResponse) ProtoMessage() {}
func (*ProfileListResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
func (m *ProfileListResponse) GetProfiles() []*storagepb.Profile {
if m != nil {
return m.Profiles
}
return nil
}
func init() {
proto.RegisterType((*GroupGetRequest)(nil), "serverpb.GroupGetRequest")
proto.RegisterType((*GroupListRequest)(nil), "serverpb.GroupListRequest")
proto.RegisterType((*GroupGetResponse)(nil), "serverpb.GroupGetResponse")
proto.RegisterType((*GroupListResponse)(nil), "serverpb.GroupListResponse")
proto.RegisterType((*ProfileGetRequest)(nil), "serverpb.ProfileGetRequest")
proto.RegisterType((*ProfileGetResponse)(nil), "serverpb.ProfileGetResponse")
proto.RegisterType((*ProfileListRequest)(nil), "serverpb.ProfileListRequest")
proto.RegisterType((*ProfileListResponse)(nil), "serverpb.ProfileListResponse")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// Client API for Groups service
type GroupsClient interface {
// Get a machine Group by id.
GroupGet(ctx context.Context, in *GroupGetRequest, opts ...grpc.CallOption) (*GroupGetResponse, error)
// List all machine Groups.
GroupList(ctx context.Context, in *GroupListRequest, opts ...grpc.CallOption) (*GroupListResponse, error)
}
type groupsClient struct {
cc *grpc.ClientConn
}
func NewGroupsClient(cc *grpc.ClientConn) GroupsClient {
return &groupsClient{cc}
}
func (c *groupsClient) GroupGet(ctx context.Context, in *GroupGetRequest, opts ...grpc.CallOption) (*GroupGetResponse, error) {
out := new(GroupGetResponse)
err := grpc.Invoke(ctx, "/serverpb.Groups/GroupGet", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *groupsClient) GroupList(ctx context.Context, in *GroupListRequest, opts ...grpc.CallOption) (*GroupListResponse, error) {
out := new(GroupListResponse)
err := grpc.Invoke(ctx, "/serverpb.Groups/GroupList", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Groups service
type GroupsServer interface {
// Get a machine Group by id.
GroupGet(context.Context, *GroupGetRequest) (*GroupGetResponse, error)
// List all machine Groups.
GroupList(context.Context, *GroupListRequest) (*GroupListResponse, error)
}
func RegisterGroupsServer(s *grpc.Server, srv GroupsServer) {
s.RegisterService(&_Groups_serviceDesc, srv)
}
func _Groups_GroupGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
in := new(GroupGetRequest)
if err := dec(in); err != nil {
return nil, err
}
out, err := srv.(GroupsServer).GroupGet(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
func _Groups_GroupList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
in := new(GroupListRequest)
if err := dec(in); err != nil {
return nil, err
}
out, err := srv.(GroupsServer).GroupList(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
var _Groups_serviceDesc = grpc.ServiceDesc{
ServiceName: "serverpb.Groups",
HandlerType: (*GroupsServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GroupGet",
Handler: _Groups_GroupGet_Handler,
},
{
MethodName: "GroupList",
Handler: _Groups_GroupList_Handler,
},
},
Streams: []grpc.StreamDesc{},
}
// Client API for Profiles service
type ProfilesClient interface {
// Get a Profile by id.
ProfileGet(ctx context.Context, in *ProfileGetRequest, opts ...grpc.CallOption) (*ProfileGetResponse, error)
// List all Profiles.
ProfileList(ctx context.Context, in *ProfileListRequest, opts ...grpc.CallOption) (*ProfileListResponse, error)
}
type profilesClient struct {
cc *grpc.ClientConn
}
func NewProfilesClient(cc *grpc.ClientConn) ProfilesClient {
return &profilesClient{cc}
}
func (c *profilesClient) ProfileGet(ctx context.Context, in *ProfileGetRequest, opts ...grpc.CallOption) (*ProfileGetResponse, error) {
out := new(ProfileGetResponse)
err := grpc.Invoke(ctx, "/serverpb.Profiles/ProfileGet", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *profilesClient) ProfileList(ctx context.Context, in *ProfileListRequest, opts ...grpc.CallOption) (*ProfileListResponse, error) {
out := new(ProfileListResponse)
err := grpc.Invoke(ctx, "/serverpb.Profiles/ProfileList", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Profiles service
type ProfilesServer interface {
// Get a Profile by id.
ProfileGet(context.Context, *ProfileGetRequest) (*ProfileGetResponse, error)
// List all Profiles.
ProfileList(context.Context, *ProfileListRequest) (*ProfileListResponse, error)
}
func RegisterProfilesServer(s *grpc.Server, srv ProfilesServer) {
s.RegisterService(&_Profiles_serviceDesc, srv)
}
func _Profiles_ProfileGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
in := new(ProfileGetRequest)
if err := dec(in); err != nil {
return nil, err
}
out, err := srv.(ProfilesServer).ProfileGet(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
func _Profiles_ProfileList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
in := new(ProfileListRequest)
if err := dec(in); err != nil {
return nil, err
}
out, err := srv.(ProfilesServer).ProfileList(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
var _Profiles_serviceDesc = grpc.ServiceDesc{
ServiceName: "serverpb.Profiles",
HandlerType: (*ProfilesServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ProfileGet",
Handler: _Profiles_ProfileGet_Handler,
},
{
MethodName: "ProfileList",
Handler: _Profiles_ProfileList_Handler,
},
},
Streams: []grpc.StreamDesc{},
}
var fileDescriptor0 = []byte{
// 342 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x7c, 0x52, 0x4b, 0x4e, 0xf3, 0x30,
0x10, 0xfe, 0xf3, 0x23, 0x4a, 0x3a, 0x95, 0xa0, 0x1d, 0x36, 0x10, 0x40, 0x02, 0x83, 0x50, 0x17,
0xe0, 0x4a, 0x65, 0x87, 0xc4, 0x06, 0x04, 0x15, 0xa8, 0x0b, 0x94, 0x1b, 0xd4, 0xc1, 0x0d, 0x91,
0x5a, 0x6c, 0x6c, 0x97, 0x9b, 0x70, 0x02, 0x2e, 0x4a, 0x71, 0xec, 0x60, 0x9a, 0xc0, 0x2a, 0xd6,
0x7c, 0xaf, 0x79, 0x04, 0xda, 0x4a, 0x66, 0x54, 0x2a, 0x61, 0x04, 0xc6, 0x9a, 0xab, 0x37, 0xae,
0x24, 0x4b, 0x1e, 0xf2, 0xc2, 0x3c, 0x2f, 0x18, 0xcd, 0xc4, 0x7c, 0x90, 0x09, 0xc5, 0x85, 0x76,
0x9f, 0x73, 0x36, 0x51, 0x7c, 0xce, 0xcd, 0x64, 0x36, 0x60, 0x42, 0x98, 0x6c, 0x9a, 0x0f, 0xb4,
0x11, 0x6a, 0x92, 0x73, 0xff, 0x95, 0xcc, 0xbf, 0x4a, 0x57, 0x72, 0x04, 0x5b, 0x23, 0x25, 0x16,
0x72, 0xc4, 0x4d, 0xca, 0x5f, 0x17, 0x5c, 0x1b, 0xdc, 0x84, 0xff, 0xc5, 0xd3, 0x4e, 0x74, 0x18,
0xf5, 0xdb, 0xe9, 0xf2, 0x45, 0x10, 0xba, 0x96, 0x32, 0x2e, 0xb4, 0xe7, 0x90, 0x4b, 0x57, 0xb3,
0x32, 0x2d, 0xc5, 0x8b, 0xe6, 0x78, 0x0a, 0xeb, 0xf9, 0x57, 0xcd, 0x4a, 0x3b, 0xc3, 0x2e, 0xad,
0x32, 0xa9, 0xe5, 0xa6, 0x25, 0x4c, 0xae, 0xa0, 0x17, 0xf8, 0x39, 0x71, 0x1f, 0x5a, 0x16, 0xd5,
0x4b, 0xf5, 0x5a, 0xa3, 0xda, 0xe1, 0xe4, 0x18, 0x7a, 0x8f, 0x4a, 0x4c, 0x8b, 0x19, 0xff, 0xa3,
0xe7, 0x6b, 0xc0, 0x90, 0xe4, 0x42, 0xce, 0x60, 0x43, 0x96, 0x55, 0xd7, 0x23, 0x06, 0x29, 0x8e,
0x9f, 0x7a, 0x0a, 0x39, 0xa9, 0x3c, 0x82, 0xc9, 0x6b, 0x49, 0xb7, 0xb0, 0xfd, 0x83, 0xe5, 0xa2,
0x28, 0xc4, 0xce, 0xc7, 0x4f, 0xd4, 0x94, 0x55, 0x71, 0x86, 0xef, 0x11, 0xb4, 0xec, 0x9c, 0x1a,
0x6f, 0x20, 0xf6, 0xbb, 0xc5, 0x5d, 0xea, 0xaf, 0x4e, 0x57, 0xce, 0x94, 0x24, 0x4d, 0x50, 0x99,
0x4e, 0xfe, 0xe1, 0x1d, 0xb4, 0xab, 0x25, 0xe3, 0x2a, 0x35, 0x98, 0x27, 0xd9, 0x6b, 0xc4, 0xbc,
0xcf, 0xf0, 0x23, 0x82, 0xd8, 0x75, 0xab, 0xf1, 0x1e, 0xe0, 0x7b, 0xab, 0x18, 0x28, 0x6b, 0x07,
0x49, 0xf6, 0x9b, 0xc1, 0xaa, 0xbf, 0x31, 0x74, 0x82, 0xb5, 0x61, 0x9d, 0x1e, 0xf6, 0x78, 0xf0,
0x0b, 0xea, 0xdd, 0x58, 0xcb, 0xfe, 0xcc, 0x17, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc7, 0xa6,
0x0e, 0xd9, 0x2f, 0x03, 0x00, 0x00,
}

View File

@@ -0,0 +1,53 @@
syntax = "proto3";
package serverpb;
import "github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb/storage.proto";
service Groups {
// Get a machine Group by id.
rpc GroupGet(GroupGetRequest) returns (GroupGetResponse) {};
// List all machine Groups.
rpc GroupList(GroupListRequest) returns (GroupListResponse) {};
}
service Profiles {
// Get a Profile by id.
rpc ProfileGet(ProfileGetRequest) returns (ProfileGetResponse) {};
// List all Profiles.
rpc ProfileList(ProfileListRequest) returns (ProfileListResponse) {};
}
message GroupGetRequest {
string id = 1;
}
message GroupListRequest {
}
message GroupGetResponse {
storagepb.Group group = 1;
}
message GroupListResponse {
repeated storagepb.Group groups = 1;
}
message ProfileGetRequest {
string id = 1;
}
message ProfileGetResponse {
storagepb.Profile profile = 1;
}
message ProfileListRequest {
string id = 1;
}
message ProfileListResponse {
repeated storagepb.Profile profiles = 1;
}

View File

@@ -1,204 +0,0 @@
// Code generated by protoc-gen-go.
// source: server.proto
// DO NOT EDIT!
/*
Package serverpb is a generated protocol buffer package.
It is generated from these files:
server.proto
It has these top-level messages:
GetRequest
ListRequest
GetResponse
ListResponse
*/
package serverpb
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import storagepb "github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// 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.
const _ = proto.ProtoPackageIsVersion1
type GetRequest struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}
func (m *GetRequest) Reset() { *m = GetRequest{} }
func (m *GetRequest) String() string { return proto.CompactTextString(m) }
func (*GetRequest) ProtoMessage() {}
func (*GetRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type ListRequest struct {
}
func (m *ListRequest) Reset() { *m = ListRequest{} }
func (m *ListRequest) String() string { return proto.CompactTextString(m) }
func (*ListRequest) ProtoMessage() {}
func (*ListRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type GetResponse struct {
Group *storagepb.Group `protobuf:"bytes,1,opt,name=group" json:"group,omitempty"`
}
func (m *GetResponse) Reset() { *m = GetResponse{} }
func (m *GetResponse) String() string { return proto.CompactTextString(m) }
func (*GetResponse) ProtoMessage() {}
func (*GetResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *GetResponse) GetGroup() *storagepb.Group {
if m != nil {
return m.Group
}
return nil
}
type ListResponse struct {
Groups []*storagepb.Group `protobuf:"bytes,1,rep,name=groups" json:"groups,omitempty"`
}
func (m *ListResponse) Reset() { *m = ListResponse{} }
func (m *ListResponse) String() string { return proto.CompactTextString(m) }
func (*ListResponse) ProtoMessage() {}
func (*ListResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *ListResponse) GetGroups() []*storagepb.Group {
if m != nil {
return m.Groups
}
return nil
}
func init() {
proto.RegisterType((*GetRequest)(nil), "serverpb.GetRequest")
proto.RegisterType((*ListRequest)(nil), "serverpb.ListRequest")
proto.RegisterType((*GetResponse)(nil), "serverpb.GetResponse")
proto.RegisterType((*ListResponse)(nil), "serverpb.ListResponse")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// Client API for Groups service
type GroupsClient interface {
// Get a machine Group by id.
Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error)
// List all machine Groups.
List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error)
}
type groupsClient struct {
cc *grpc.ClientConn
}
func NewGroupsClient(cc *grpc.ClientConn) GroupsClient {
return &groupsClient{cc}
}
func (c *groupsClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) {
out := new(GetResponse)
err := grpc.Invoke(ctx, "/serverpb.Groups/Get", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *groupsClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
out := new(ListResponse)
err := grpc.Invoke(ctx, "/serverpb.Groups/List", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Groups service
type GroupsServer interface {
// Get a machine Group by id.
Get(context.Context, *GetRequest) (*GetResponse, error)
// List all machine Groups.
List(context.Context, *ListRequest) (*ListResponse, error)
}
func RegisterGroupsServer(s *grpc.Server, srv GroupsServer) {
s.RegisterService(&_Groups_serviceDesc, srv)
}
func _Groups_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
in := new(GetRequest)
if err := dec(in); err != nil {
return nil, err
}
out, err := srv.(GroupsServer).Get(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
func _Groups_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
in := new(ListRequest)
if err := dec(in); err != nil {
return nil, err
}
out, err := srv.(GroupsServer).List(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
var _Groups_serviceDesc = grpc.ServiceDesc{
ServiceName: "serverpb.Groups",
HandlerType: (*GroupsServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Get",
Handler: _Groups_Get_Handler,
},
{
MethodName: "List",
Handler: _Groups_List_Handler,
},
},
Streams: []grpc.StreamDesc{},
}
var fileDescriptor0 = []byte{
// 241 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xc1, 0x4a, 0x03, 0x31,
0x10, 0xb5, 0x56, 0x17, 0x9d, 0xad, 0x22, 0x41, 0x45, 0x16, 0x0f, 0x92, 0x83, 0xf4, 0x62, 0x02,
0x55, 0xd1, 0x3f, 0x28, 0x82, 0xa7, 0xfd, 0x83, 0xcd, 0x3a, 0xc6, 0x05, 0xeb, 0xc4, 0x4c, 0x56,
0x7f, 0xdf, 0x6d, 0xb2, 0xd1, 0x52, 0x3c, 0x4d, 0xf2, 0xde, 0xbc, 0xf7, 0x66, 0x06, 0x66, 0x8c,
0xfe, 0x0b, 0xbd, 0x72, 0x9e, 0x02, 0x89, 0x83, 0xf4, 0x73, 0xa6, 0x7a, 0xb2, 0x5d, 0x78, 0xeb,
0x8d, 0x6a, 0x69, 0xa5, 0x5b, 0xf2, 0x48, 0x3c, 0x96, 0x1b, 0xd3, 0x78, 0x5c, 0x61, 0x68, 0xde,
0xb5, 0x21, 0x0a, 0xed, 0xab, 0xd5, 0x1c, 0xc8, 0x37, 0x16, 0x73, 0x75, 0x46, 0x5b, 0x4f, 0xbd,
0xe3, 0x64, 0x2a, 0x2f, 0x01, 0x96, 0x18, 0x6a, 0xfc, 0xec, 0x91, 0x83, 0x38, 0x86, 0xdd, 0xee,
0xe5, 0x62, 0x72, 0x35, 0x99, 0x1f, 0xd6, 0xc3, 0x4b, 0x1e, 0x41, 0xf9, 0xdc, 0x71, 0xa6, 0xe5,
0x3d, 0x94, 0xb1, 0x99, 0x1d, 0x7d, 0x30, 0x8a, 0x6b, 0xd8, 0x8f, 0x5e, 0x51, 0x50, 0x2e, 0x4e,
0xd4, 0x6f, 0x86, 0x5a, 0xae, 0xf1, 0x3a, 0xd1, 0xf2, 0x11, 0x66, 0xc9, 0x65, 0xd4, 0xcd, 0xa1,
0x48, 0x33, 0x0c, 0xc2, 0xe9, 0xbf, 0xc2, 0x91, 0x5f, 0x7c, 0x43, 0x11, 0x01, 0x16, 0x77, 0x30,
0x1d, 0xa2, 0xc5, 0xa9, 0xca, 0x47, 0x50, 0x7f, 0x63, 0x57, 0x67, 0x5b, 0x68, 0xca, 0x91, 0x3b,
0xe2, 0x01, 0xf6, 0xd6, 0xc9, 0x62, 0xa3, 0x61, 0x63, 0x9f, 0xea, 0x7c, 0x1b, 0xce, 0x42, 0x53,
0xc4, 0xeb, 0xdc, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x46, 0xb8, 0x4d, 0x82, 0x01, 0x00,
0x00,
}

View File

@@ -1,27 +0,0 @@
syntax = "proto3";
package serverpb;
import "github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb/groups.proto";
service Groups {
// Get a machine Group by id.
rpc Get(GetRequest) returns (GetResponse) {}
// List all machine Groups.
rpc List(ListRequest) returns (ListResponse) {}
}
message GetRequest {
string id = 1;
}
message ListRequest {
}
message GetResponse {
storagepb.Group group = 1;
}
message ListResponse {
repeated storagepb.Group groups = 1;
}

View File

@@ -1,47 +1,61 @@
package storage
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
)
// Errors querying a Store.
var (
ErrGroupNotFound = errors.New("storage: No Group found")
ErrGroupNotFound = errors.New("storage: No Group found")
ErrProfileNotFound = errors.New("storage: No Profile found")
)
// A Store provides machine Groups.
// A Store stores machine Groups and Profiles.
type Store interface {
// Get a machine Group by id.
GetGroup(id string) (*storagepb.Group, error)
// List all machine Groups.
ListGroups() ([]*storagepb.Group, error)
// GroupGet returns a machine Group by id.
GroupGet(id string) (*storagepb.Group, error)
// GroupList lists all machine Groups.
GroupList() ([]*storagepb.Group, error)
// ProfileGet gets a profile by id.
ProfileGet(id string) (*storagepb.Profile, error)
// ProfileList lists all profiles.
ProfileList() ([]*storagepb.Profile, error)
}
// Config initializes a memStore.
// Config initializes a fileStore.
type Config struct {
Dir string
Groups []*storagepb.Group
}
// memStore implements ths Store interface.
type memStore struct {
groups map[string] *storagepb.Group
// fileStore implements ths Store interface. Queries to the file system
// are restricted to the specified directory tree.
type fileStore struct {
dir string
groups map[string]*storagepb.Group
}
// NewMemStore returns a new memory-backed Store.
func NewMemStore(config *Config) Store {
// NewFileStore returns a new memory-backed Store.
func NewFileStore(config *Config) Store {
groups := make(map[string]*storagepb.Group)
for _, group := range config.Groups {
groups[group.Id] = group
}
return &memStore{
return &fileStore{
dir: config.Dir,
groups: groups,
}
}
// GetGroup returns a machine Group by id.
func (s *memStore) GetGroup(id string) (*storagepb.Group, error) {
// GroupGet returns a machine Group by id.
func (s *fileStore) GroupGet(id string) (*storagepb.Group, error) {
val, ok := s.groups[id]
if !ok {
return nil, ErrGroupNotFound
@@ -49,8 +63,8 @@ func (s *memStore) GetGroup(id string) (*storagepb.Group, error) {
return val, nil
}
// ListGroups lists all machine Groups.
func (s *memStore) ListGroups() ([]*storagepb.Group, error) {
// GroupList lists all machine Groups.
func (s *fileStore) GroupList() ([]*storagepb.Group, error) {
groups := make([]*storagepb.Group, len(s.groups))
i := 0
for _, g := range s.groups {
@@ -59,3 +73,56 @@ func (s *memStore) ListGroups() ([]*storagepb.Group, error) {
}
return groups, nil
}
// ProfileGet gets a profile by id.
func (s *fileStore) ProfileGet(id string) (*storagepb.Profile, error) {
file, err := openFile(http.Dir(s.dir), filepath.Join("specs", id, "spec.json"))
if err != nil {
return nil, err
}
defer file.Close()
profile := new(storagepb.Profile)
err = json.NewDecoder(file).Decode(profile)
if err != nil {
return nil, err
}
return profile, err
}
// ProfileList lists all profiles.
func (s *fileStore) ProfileList() ([]*storagepb.Profile, error) {
finfos, err := ioutil.ReadDir(filepath.Join(s.dir, "specs"))
if err != nil {
return nil, err
}
profiles := make([]*storagepb.Profile, 0, len(finfos))
for _, finfo := range finfos {
profile, err := s.ProfileGet(finfo.Name())
if err == nil {
profiles = append(profiles, profile)
}
}
return profiles, nil
}
// openFile attempts to open the file within the specified Filesystem. If
// successful, the http.File is returned and must be closed by the caller.
// Otherwise, the path was not a regular file that could be opened and an
// error is returned.
func openFile(fs http.FileSystem, path string) (http.File, error) {
file, err := fs.Open(path)
if err != nil {
return nil, err
}
info, err := file.Stat()
if err != nil {
file.Close()
return nil, err
}
if info.Mode().IsRegular() {
return file, nil
}
file.Close()
return nil, fmt.Errorf("%s is not a file on the given filesystem", path)
}

View File

@@ -1,2 +1,2 @@
// Package storagepb provides storage protobuf client and server interfaces.
package storagepb
package storagepb

View File

@@ -1,81 +0,0 @@
// Code generated by protoc-gen-go.
// source: groups.proto
// DO NOT EDIT!
/*
Package storagepb is a generated protocol buffer package.
It is generated from these files:
groups.proto
It has these top-level messages:
Group
*/
package storagepb
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import 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.
const _ = proto.ProtoPackageIsVersion1
type Group struct {
// machine readable Id
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
// human readable name
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
// profile id
Profile string `protobuf:"bytes,3,opt,name=profile" json:"profile,omitempty"`
// tags required to match the group
Requirements map[string]string `protobuf:"bytes,4,rep,name=requirements" json:"requirements,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
// custom metadata
Metadata map[string]string `protobuf:"bytes,5,rep,name=metadata" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
func (m *Group) Reset() { *m = Group{} }
func (m *Group) String() string { return proto.CompactTextString(m) }
func (*Group) ProtoMessage() {}
func (*Group) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Group) GetRequirements() map[string]string {
if m != nil {
return m.Requirements
}
return nil
}
func (m *Group) GetMetadata() map[string]string {
if m != nil {
return m.Metadata
}
return nil
}
func init() {
proto.RegisterType((*Group)(nil), "storagepb.Group")
}
var fileDescriptor0 = []byte{
// 217 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x2f, 0xca, 0x2f,
0x2d, 0x28, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x2c, 0x2e, 0xc9, 0x2f, 0x4a, 0x4c,
0x4f, 0x2d, 0x48, 0x52, 0x3a, 0xce, 0xc4, 0xc5, 0xea, 0x0e, 0x92, 0x13, 0xe2, 0xe3, 0x62, 0xca,
0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x02, 0xb2, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12,
0x73, 0x53, 0x25, 0x98, 0xc0, 0x22, 0x60, 0xb6, 0x90, 0x04, 0x17, 0x3b, 0xd0, 0x84, 0xb4, 0xcc,
0x9c, 0x54, 0x09, 0x66, 0xb0, 0x30, 0x8c, 0x2b, 0xe4, 0xc6, 0xc5, 0x53, 0x94, 0x5a, 0x58, 0x9a,
0x59, 0x94, 0x9a, 0x9b, 0x9a, 0x57, 0x52, 0x2c, 0xc1, 0xa2, 0xc0, 0xac, 0xc1, 0x6d, 0xa4, 0xa4,
0x07, 0xb7, 0x49, 0x0f, 0x6c, 0x8b, 0x5e, 0x10, 0x92, 0x22, 0xd7, 0xbc, 0x92, 0xa2, 0xca, 0x20,
0x14, 0x7d, 0x42, 0x56, 0x5c, 0x1c, 0xb9, 0xa9, 0x25, 0x89, 0x29, 0x89, 0x25, 0x89, 0x12, 0xac,
0x60, 0x33, 0xe4, 0x30, 0xcc, 0xf0, 0x85, 0x2a, 0x80, 0xe8, 0x87, 0xab, 0x97, 0xb2, 0xe7, 0x12,
0xc4, 0x30, 0x5e, 0x48, 0x80, 0x8b, 0x39, 0x3b, 0xb5, 0x12, 0xea, 0x2f, 0x10, 0x53, 0x48, 0x84,
0x8b, 0xb5, 0x2c, 0x31, 0xa7, 0x14, 0xe6, 0x33, 0x08, 0xc7, 0x8a, 0xc9, 0x82, 0x51, 0xca, 0x9a,
0x8b, 0x17, 0xc5, 0x6c, 0x52, 0x34, 0x27, 0xb1, 0x81, 0xc3, 0xd6, 0x18, 0x10, 0x00, 0x00, 0xff,
0xff, 0xcc, 0x89, 0x49, 0x42, 0x6b, 0x01, 0x00, 0x00,
}

View File

@@ -1,15 +0,0 @@
syntax = "proto3";
package storagepb;
message Group {
// machine readable Id
string id = 1;
// human readable name
string name = 2;
// profile id
string profile = 3;
// tags required to match the group
map<string, string> requirements = 4;
// custom metadata
map<string, string> metadata = 5;
}

View File

@@ -0,0 +1,139 @@
// Code generated by protoc-gen-go.
// source: storage.proto
// DO NOT EDIT!
/*
Package storagepb is a generated protocol buffer package.
It is generated from these files:
storage.proto
It has these top-level messages:
Group
Profile
NetBoot
*/
package storagepb
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import 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.
const _ = proto.ProtoPackageIsVersion1
type Group struct {
// machine readable Id
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
// human readable name
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
// profile id
Profile string `protobuf:"bytes,3,opt,name=profile" json:"profile,omitempty"`
// tags required to match the group
Requirements map[string]string `protobuf:"bytes,4,rep,name=requirements" json:"requirements,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
// custom metadata
Metadata map[string]string `protobuf:"bytes,5,rep,name=metadata" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
func (m *Group) Reset() { *m = Group{} }
func (m *Group) String() string { return proto.CompactTextString(m) }
func (*Group) ProtoMessage() {}
func (*Group) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Group) GetRequirements() map[string]string {
if m != nil {
return m.Requirements
}
return nil
}
func (m *Group) GetMetadata() map[string]string {
if m != nil {
return m.Metadata
}
return nil
}
type Profile struct {
// profile id
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
// human readable name
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
// ignition id
IgnitionId string `protobuf:"bytes,3,opt,name=ignition_id,json=ignitionId" json:"ignition_id,omitempty"`
// cloud config id
CloudId string `protobuf:"bytes,4,opt,name=cloud_id,json=cloudId" json:"cloud_id,omitempty"`
// support network boot / PXE
Boot *NetBoot `protobuf:"bytes,5,opt,name=boot" json:"boot,omitempty"`
}
func (m *Profile) Reset() { *m = Profile{} }
func (m *Profile) String() string { return proto.CompactTextString(m) }
func (*Profile) ProtoMessage() {}
func (*Profile) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *Profile) GetBoot() *NetBoot {
if m != nil {
return m.Boot
}
return nil
}
type NetBoot struct {
// the URL of the kernel image
Kernel string `protobuf:"bytes,1,opt,name=kernel" json:"kernel,omitempty"`
// the init RAM filesystem URLs
Initrd []string `protobuf:"bytes,2,rep,name=initrd" json:"initrd,omitempty"`
// kernel parameters (command line)
Cmdline map[string]string `protobuf:"bytes,3,rep,name=cmdline" json:"cmdline,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
func (m *NetBoot) Reset() { *m = NetBoot{} }
func (m *NetBoot) String() string { return proto.CompactTextString(m) }
func (*NetBoot) ProtoMessage() {}
func (*NetBoot) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *NetBoot) GetCmdline() map[string]string {
if m != nil {
return m.Cmdline
}
return nil
}
func init() {
proto.RegisterType((*Group)(nil), "storagepb.Group")
proto.RegisterType((*Profile)(nil), "storagepb.Profile")
proto.RegisterType((*NetBoot)(nil), "storagepb.NetBoot")
}
var fileDescriptor0 = []byte{
// 347 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x52, 0x4b, 0x4e, 0xc3, 0x30,
0x10, 0x55, 0x3e, 0xfd, 0x4d, 0x5b, 0x04, 0x23, 0x84, 0x42, 0x17, 0xb4, 0xca, 0x02, 0x75, 0x95,
0x05, 0x6c, 0xa0, 0x2c, 0x90, 0x40, 0x80, 0x58, 0x80, 0x50, 0x2e, 0x80, 0xd2, 0xc6, 0x54, 0x56,
0x13, 0xbb, 0xb8, 0x0e, 0x52, 0x8f, 0xc1, 0x4d, 0xb8, 0x05, 0xd7, 0xc2, 0xb1, 0x9d, 0xaa, 0x55,
0x36, 0x74, 0x37, 0xef, 0xcd, 0x9b, 0x8f, 0xdf, 0x18, 0xfa, 0x2b, 0xc9, 0x45, 0x32, 0x27, 0xd1,
0x52, 0x70, 0xc9, 0xb1, 0x63, 0xe1, 0x72, 0x1a, 0xfe, 0xba, 0xd0, 0x78, 0x12, 0xbc, 0x58, 0xe2,
0x01, 0xb8, 0x34, 0x0d, 0x9c, 0x91, 0x33, 0xee, 0xc4, 0x2a, 0x42, 0x04, 0x9f, 0x25, 0x39, 0x09,
0x5c, 0xcd, 0xe8, 0x18, 0x03, 0x68, 0xa9, 0x0e, 0x1f, 0x34, 0x23, 0x81, 0xa7, 0xe9, 0x0a, 0xe2,
0x23, 0xf4, 0x04, 0xf9, 0x2c, 0xa8, 0x20, 0x39, 0x61, 0x72, 0x15, 0xf8, 0x23, 0x6f, 0xdc, 0xbd,
0x08, 0xa3, 0xcd, 0xa4, 0x48, 0x4f, 0x89, 0xe2, 0x2d, 0xd1, 0x03, 0x93, 0x62, 0x1d, 0xef, 0xd4,
0xe1, 0x04, 0xda, 0x39, 0x91, 0x49, 0x9a, 0xc8, 0x24, 0x68, 0xe8, 0x1e, 0x67, 0xb5, 0x1e, 0x2f,
0x56, 0x60, 0xea, 0x37, 0xfa, 0xc1, 0x2d, 0x1c, 0xd5, 0xda, 0xe3, 0x21, 0x78, 0x0b, 0xb2, 0xb6,
0xef, 0x2a, 0x43, 0x3c, 0x86, 0xc6, 0x57, 0x92, 0x15, 0xd5, 0xcb, 0x0c, 0x98, 0xb8, 0x57, 0xce,
0xe0, 0x06, 0xfa, 0x3b, 0xbd, 0xf7, 0x29, 0x0e, 0xbf, 0x1d, 0x68, 0xbd, 0x59, 0x37, 0xfe, 0xe3,
0xe5, 0x10, 0xba, 0x74, 0xce, 0xa8, 0xa4, 0x9c, 0xbd, 0x2b, 0xb1, 0xf1, 0x13, 0x2a, 0xea, 0x39,
0xc5, 0x53, 0x68, 0xcf, 0x32, 0x5e, 0xa4, 0x65, 0xd6, 0x37, 0x6e, 0x6b, 0xac, 0x52, 0xe7, 0xe0,
0x4f, 0x39, 0x97, 0xca, 0x21, 0x47, 0x39, 0x84, 0x5b, 0x0e, 0xbd, 0x12, 0x79, 0xa7, 0x32, 0xb1,
0xce, 0x87, 0x3f, 0x6a, 0x27, 0xcb, 0xe0, 0x09, 0x34, 0x17, 0x44, 0x30, 0x92, 0xd9, 0xbd, 0x2c,
0x2a, 0x79, 0xaa, 0x66, 0x8a, 0x54, 0x6d, 0xe7, 0x95, 0xbc, 0x41, 0x78, 0x0d, 0xad, 0x59, 0x9e,
0x66, 0x94, 0x95, 0xb7, 0x2e, 0x0f, 0x31, 0xac, 0x8f, 0x89, 0xee, 0x8d, 0xc2, 0x5c, 0xa2, 0xd2,
0x0f, 0x26, 0xd0, 0xdb, 0x4e, 0xec, 0x63, 0xe3, 0xb4, 0xa9, 0xbf, 0xe8, 0xe5, 0x5f, 0x00, 0x00,
0x00, 0xff, 0xff, 0x97, 0x23, 0xfd, 0x6e, 0xb3, 0x02, 0x00, 0x00,
}

View File

@@ -0,0 +1,37 @@
syntax = "proto3";
package storagepb;
message Group {
// machine readable Id
string id = 1;
// human readable name
string name = 2;
// profile id
string profile = 3;
// tags required to match the group
map<string, string> requirements = 4;
// custom metadata
map<string, string> metadata = 5;
}
message Profile {
// profile id
string id = 1;
// human readable name
string name = 2;
// ignition id
string ignition_id = 3;
// cloud config id
string cloud_id = 4;
// support network boot / PXE
NetBoot boot = 5;
}
message NetBoot {
// the URL of the kernel image
string kernel = 1;
// the init RAM filesystem URLs
repeated string initrd = 2;
// kernel parameters (command line)
map<string, string> cmdline = 3;
}

View File

@@ -27,11 +27,13 @@ func main() {
flags := struct {
address string
configPath string
dataPath string
version bool
help bool
}{}
flag.StringVar(&flags.address, "address", "127.0.0.1:8081", "gRPC listen address")
flag.StringVar(&flags.configPath, "config", "./data/config.yaml", "Path to config file")
flag.StringVar(&flags.dataPath, "data-path", "./data", "Path to data directory")
// subcommands
flag.BoolVar(&flags.version, "version", false, "print version and exit")
flag.BoolVar(&flags.help, "help", false, "print usage and exit")
@@ -59,6 +61,9 @@ func main() {
if finfo, err := os.Stat(flags.configPath); err != nil || finfo.IsDir() {
log.Fatal("A path to a config file is required")
}
if finfo, err := os.Stat(flags.dataPath); err != nil || !finfo.IsDir() {
log.Fatal("A path to a data directory is required")
}
// load bootstrap config
cfg, err := config.LoadConfig(flags.configPath)
@@ -67,7 +72,8 @@ func main() {
}
// storage
store := storage.NewMemStore(&storage.Config{
store := storage.NewFileStore(&storage.Config{
Dir: flags.dataPath,
Groups: cfg.PBGroups(),
})
@@ -78,8 +84,10 @@ func main() {
log.Fatalf("failed to start listening: %v", err)
}
grpcServer := grpc.NewServer()
pb.RegisterGroupsServer(grpcServer, bootcfg.NewServer(&bootcfg.Config{
bootcfgServer := bootcfg.NewServer(&bootcfg.Config{
Store: store,
}))
})
pb.RegisterGroupsServer(grpcServer, bootcfgServer)
pb.RegisterProfilesServer(grpcServer, bootcfgServer)
grpcServer.Serve(lis)
}

2
test
View File

@@ -1,7 +1,7 @@
#!/bin/bash -e
PKGS=$(go list ./... | grep -v /vendor)
FORMATTABLE="./api ./config ./cmd ./sign"
FORMATTABLE="$(ls -d */ | grep -v vendor/)"
LINT_EXCLUDE='(/vendor|pb$)'
LINTABLE=$(go list ./... | grep -v -E $LINT_EXCLUDE)