diff options
author | Alec Warner <antarus@gentoo.org> | 2018-12-03 22:44:29 -0500 |
---|---|---|
committer | Alec Warner <antarus@gentoo.org> | 2018-12-03 23:21:47 -0500 |
commit | 9f830bbee6ff0494372ba701d051c039cc5a7fd6 (patch) | |
tree | c768bb82c92857ef5c84cff9fdc8e25aa96d808a /src/foundation.gentoo.org/golang/members | |
parent | Start tracking tools for tracking members. (diff) | |
download | antarus-9f830bbee6ff0494372ba701d051c039cc5a7fd6.tar.gz antarus-9f830bbee6ff0494372ba701d051c039cc5a7fd6.tar.bz2 antarus-9f830bbee6ff0494372ba701d051c039cc5a7fd6.zip |
Initial commit of rsync docker stuff.
Signed-off-by: Alec Warner <antarus@gentoo.org>
Diffstat (limited to 'src/foundation.gentoo.org/golang/members')
5 files changed, 180 insertions, 56 deletions
diff --git a/src/foundation.gentoo.org/golang/members/data/member.pb.go b/src/foundation.gentoo.org/golang/members/data/member.pb.go index 3d39f40..4f12ab6 100644 --- a/src/foundation.gentoo.org/golang/members/data/member.pb.go +++ b/src/foundation.gentoo.org/golang/members/data/member.pb.go @@ -11,6 +11,7 @@ It is generated from these files: It has these top-level messages: MemberRoll Member + Status */ package data @@ -21,6 +22,41 @@ import math "math" var _ = proto.Marshal var _ = math.Inf +type Status_State int32 + +const ( + // Member has voting rights + Status_ACTIVE Status_State = 0 + // Member had voting rights, but is no longer a foundation member. + Status_EMERITUS Status_State = 1 +) + +var Status_State_name = map[int32]string{ + 0: "ACTIVE", + 1: "EMERITUS", +} +var Status_State_value = map[string]int32{ + "ACTIVE": 0, + "EMERITUS": 1, +} + +func (x Status_State) Enum() *Status_State { + p := new(Status_State) + *p = x + return p +} +func (x Status_State) String() string { + return proto.EnumName(Status_State_name, int32(x)) +} +func (x *Status_State) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Status_State_value, data, "Status_State") + if err != nil { + return err + } + *x = Status_State(value) + return nil +} + type MemberRoll struct { // When we add a new member, they should receive this ID. // We rely on clients to increment this ID during add operations. @@ -55,11 +91,16 @@ type Member struct { Email []string `protobuf:"bytes,2,rep,name=email" json:"email,omitempty"` // Name Name []string `protobuf:"bytes,3,rep,name=name" json:"name,omitempty"` - // microsecond timestamp of joining. - JoinTimestampUs *int64 `protobuf:"varint,4,opt,name=join_timestamp_us" json:"join_timestamp_us,omitempty"` // microsecond timestamp of any elections member participated in - VotedInElection []int64 `protobuf:"varint,5,rep,name=voted_in_election" json:"voted_in_election,omitempty"` - XXX_unrecognized []byte `json:"-"` + VotedInElection []int64 `protobuf:"varint,4,rep,name=voted_in_election" json:"voted_in_election,omitempty"` + // Status's of a given member. Typically most users have 1 state + // (e.g. they are an active member of the foundation.) But we will + // try to record all state changes here, so if people leave and come + // back we have a record. + State []*Status `protobuf:"bytes,5,rep,name=state" json:"state,omitempty"` + // A list of gpg key bytes for each member. + Gpgkey [][]byte `protobuf:"bytes,6,rep,name=gpgkey" json:"gpgkey,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Member) Reset() { *m = Member{} } @@ -87,19 +128,55 @@ func (m *Member) GetName() []string { return nil } -func (m *Member) GetJoinTimestampUs() int64 { - if m != nil && m.JoinTimestampUs != nil { - return *m.JoinTimestampUs +func (m *Member) GetVotedInElection() []int64 { + if m != nil { + return m.VotedInElection } - return 0 + return nil } -func (m *Member) GetVotedInElection() []int64 { +func (m *Member) GetState() []*Status { if m != nil { - return m.VotedInElection + return m.State } return nil } +func (m *Member) GetGpgkey() [][]byte { + if m != nil { + return m.Gpgkey + } + return nil +} + +type Status struct { + // State of the member. + State *Status_State `protobuf:"varint,1,opt,name=state,enum=data.Status_State,def=0" json:"state,omitempty"` + // Time when state change occured. + StatusChange *int64 `protobuf:"varint,2,opt,name=status_change" json:"status_change,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *Status) Reset() { *m = Status{} } +func (m *Status) String() string { return proto.CompactTextString(m) } +func (*Status) ProtoMessage() {} + +const Default_Status_State Status_State = Status_ACTIVE + +func (m *Status) GetState() Status_State { + if m != nil && m.State != nil { + return *m.State + } + return Default_Status_State +} + +func (m *Status) GetStatusChange() int64 { + if m != nil && m.StatusChange != nil { + return *m.StatusChange + } + return 0 +} + func init() { + proto.RegisterEnum("data.Status_State", Status_State_name, Status_State_value) } diff --git a/src/foundation.gentoo.org/golang/members/data/member.proto b/src/foundation.gentoo.org/golang/members/data/member.proto index 2e35208..500364e 100644 --- a/src/foundation.gentoo.org/golang/members/data/member.proto +++ b/src/foundation.gentoo.org/golang/members/data/member.proto @@ -18,9 +18,29 @@ message Member { // Name repeated string name = 3; - // microsecond timestamp of joining. - optional int64 join_timestamp_us = 4; - // microsecond timestamp of any elections member participated in - repeated int64 voted_in_election = 5; + repeated int64 voted_in_election = 4; + + // Status's of a given member. Typically most users have 1 state + // (e.g. they are an active member of the foundation.) But we will + // try to record all state changes here, so if people leave and come + // back we have a record. + repeated Status state = 5; + + // A list of gpg key bytes for each member. + repeated bytes gpgkey = 6; +} + +message Status { + enum State { + // Member has voting rights + ACTIVE = 0; + // Member had voting rights, but is no longer a foundation member. + EMERITUS = 1; + } + + // State of the member. + optional State state = 1 [default=ACTIVE]; + // Time when state change occured. + optional int64 status_change = 2; } diff --git a/src/foundation.gentoo.org/golang/members/importers/ldap.go b/src/foundation.gentoo.org/golang/members/importers/ldap.go index 02db9b0..02cc7eb 100644 --- a/src/foundation.gentoo.org/golang/members/importers/ldap.go +++ b/src/foundation.gentoo.org/golang/members/importers/ldap.go @@ -1,9 +1,3 @@ -package ldap +package importers -import ( - "gopkg.in/ldap.v2" -) - -func listDevs(ldap.v2.Conn) { - -} +import () diff --git a/src/foundation.gentoo.org/golang/members/main.go b/src/foundation.gentoo.org/golang/members/main.go deleted file mode 100644 index 18e7f65..0000000 --- a/src/foundation.gentoo.org/golang/members/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "flag" - "os" - - "foundation.gentoo.org/golang/members/maintenance" - "github.com/google/subcommands" - "golang.org/x/net/context" -) - - -func main() { - subcommands.Register(subcommands.HelpCommand(), "") - subcommands.Register(subcommands.FlagsCommand(), "") - subcommands.Register(subcommands.CommandsCommand(), "") - subcommands.Register(&maintenance.ListCmd{}, "") - - flag.Parse() - ctx := context.Background() - os.Exit(int(subcommands.Execute(ctx))) -} diff --git a/src/foundation.gentoo.org/golang/members/maintenance/memberroll.go b/src/foundation.gentoo.org/golang/members/maintenance/memberroll.go index 05017ea..12369d5 100644 --- a/src/foundation.gentoo.org/golang/members/maintenance/memberroll.go +++ b/src/foundation.gentoo.org/golang/members/maintenance/memberroll.go @@ -1,20 +1,22 @@ package maintenance import ( - "io/ioutil" + "fmt" + "io/ioutil" + "time" - "github.com/golang/protobuf/proto" - pb "foundation.gentoo.org/golang/members/data" + pb "foundation.gentoo.org/golang/members/data" + "github.com/golang/protobuf/proto" ) // Struct MemberRoll defines operations on a MemberRoll // and holds the underlying data. type MemberRoll struct { - roll *pb.MemberRoll + roll *pb.MemberRoll } // Create a new memberRoll from a file. -func NewMemberRoll (path string) (*MemberRoll, error) { +func NewMemberRoll(path string) (*MemberRoll, error) { in, err := ioutil.ReadFile(path) if err != nil { return nil, err @@ -30,10 +32,10 @@ func NewMemberRoll (path string) (*MemberRoll, error) { } // NewEmptyMemberRoll creates an empty MemberRoll -func NewEmptyMemberRoll() (*MemberRoll) { +func NewEmptyMemberRoll() *MemberRoll { // The first member gets ID 1. return &MemberRoll{ - roll: &pb.MemberRoll { + roll: &pb.MemberRoll{ NextMemberId: proto.Int64(1), }, } @@ -42,18 +44,71 @@ func NewEmptyMemberRoll() (*MemberRoll) { // Save will write the MemberRoll to file at path. func (mr *MemberRoll) Save(path string) (bool, error) { bytes, err := proto.Marshal(mr.roll) - if err != nil { return false, err } + if err != nil { + return false, err + } if err = ioutil.WriteFile(path, bytes, 0644); err != nil { return false, err } return true, nil } +// Does this email match an existing member? +func (mr *MemberRoll) MatchEmail(email string) *pb.Member { + member := &pb.Member{ + Email: []string{email}, + } + return mr.Match(member) +} + +// Members match if they shared an email address. +func Match(m1, m2 *pb.Member) bool { + for _, i := range m1.GetEmail() { + for _, j := range m2.GetEmail() { + if i == j { + return true + } + } + } + return false +} + +// Match will try to find if m is in mr. +func (mr *MemberRoll) Match(m *pb.Member) *pb.Member { + for _, i := range mr.roll.GetMembers() { + if Match(m, i) { + return i + } + } + return nil +} + +// low-level function for add raw member protobufs to the roll. +func (mr *MemberRoll) Add(m pb.Member) (bool, error) { + match := mr.Match(&m) + if match != nil { + err := fmt.Errorf("Adding existing member: %v", match) + return false, err + } + mr.roll.Members = append(mr.roll.Members, &m) + return true, nil +} + +func (mr *MemberRoll) RecordVote(id int64, t time.Time) error { + return nil +} + +func (mr *MemberRoll) Print() { + for _, member := range mr.roll.GetMembers() { + fmt.Printf("Member: %v\n", member) + } +} + // GetMaxMemberId computes the largest ID amongst a memberroll. // This works by assuming members are not removed from a roll. -func (mr *MemberRoll) GetMaxMemberId() (int64) { - var id int64 = 0; - for _, member := range (mr.roll.GetMembers()) { +func (mr *MemberRoll) GetMaxMemberId() int64 { + var id int64 = 0 + for _, member := range mr.roll.GetMembers() { member_id := member.GetId() if member_id > id { id = member_id @@ -62,7 +117,7 @@ func (mr *MemberRoll) GetMaxMemberId() (int64) { return id } -func (mr *MemberRoll) GetNextMemberId() (int64) { +func (mr *MemberRoll) GetNextMemberId() int64 { id := mr.GetNextMemberId() // If the member roll lost its ID (not a required field.) // Recalculate based on existing membership. |