diff options
author | Kevin Lyda <kevin@ie.suberic.net> | 2017-01-27 09:08:58 +0000 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2017-01-27 09:08:58 +0000 |
commit | 10dfd24117094ed81197c764af25cafe12a25dfd (patch) | |
tree | 4af4c066daffb42469ed8a0e14d510dea321375b /server/store | |
parent | 13054312850d1014e814d2f64afa030a4fea5ef3 (diff) |
Remove mongo support
Resolves #40
Diffstat (limited to 'server/store')
-rw-r--r-- | server/store/mongo.go | 123 | ||||
-rw-r--r-- | server/store/store.go | 2 | ||||
-rw-r--r-- | server/store/store_test.go | 12 |
3 files changed, 0 insertions, 137 deletions
diff --git a/server/store/mongo.go b/server/store/mongo.go deleted file mode 100644 index 6a23e89..0000000 --- a/server/store/mongo.go +++ /dev/null @@ -1,123 +0,0 @@ -package store - -import ( - "strings" - "time" - - "github.com/nsheridan/cashier/server/config" - - "golang.org/x/crypto/ssh" - - mgo "gopkg.in/mgo.v2" - "gopkg.in/mgo.v2/bson" -) - -var ( - certsDB = "certs" - issuedTable = "issued_certs" -) - -func collection(session *mgo.Session) *mgo.Collection { - return session.DB(certsDB).C(issuedTable) -} - -// NewMongoStore returns a MongoDB CertStorer. -func NewMongoStore(c config.Database) (*MongoStore, error) { - m := &mgo.DialInfo{ - Addrs: strings.Split(c["address"], ","), - Username: c["username"], - Password: c["password"], - Database: certsDB, - Timeout: time.Second * 5, - } - session, err := mgo.DialWithInfo(m) - if err != nil { - return nil, err - } - return &MongoStore{ - session: session, - }, nil -} - -var _ CertStorer = (*MongoStore)(nil) - -// MongoStore is a MongoDB-based CertStorer -type MongoStore struct { - session *mgo.Session -} - -// Get a single *CertRecord -func (m *MongoStore) Get(id string) (*CertRecord, error) { - s := m.session.Copy() - defer s.Close() - if err := s.Ping(); err != nil { - return nil, err - } - c := &CertRecord{} - err := collection(s).Find(bson.M{"keyid": id}).One(c) - return c, err -} - -// SetCert parses a *ssh.Certificate and records it -func (m *MongoStore) SetCert(cert *ssh.Certificate) error { - r := parseCertificate(cert) - return m.SetRecord(r) -} - -// SetRecord records a *CertRecord -func (m *MongoStore) SetRecord(record *CertRecord) error { - s := m.session.Copy() - defer s.Close() - if err := s.Ping(); err != nil { - return err - } - return collection(s).Insert(record) -} - -// List returns all recorded certs. -// By default only active certs are returned. -func (m *MongoStore) List(includeExpired bool) ([]*CertRecord, error) { - s := m.session.Copy() - defer s.Close() - if err := s.Ping(); err != nil { - return nil, err - } - var result []*CertRecord - var err error - c := collection(s) - if includeExpired { - err = c.Find(nil).All(&result) - } else { - err = c.Find(bson.M{"expires": bson.M{"$gte": time.Now().UTC()}}).All(&result) - } - return result, err -} - -// Revoke an issued cert by id. -func (m *MongoStore) Revoke(id string) error { - s := m.session.Copy() - defer s.Close() - if err := s.Ping(); err != nil { - return err - } - c := collection(s) - return c.Update(bson.M{"keyid": id}, bson.M{"$set": bson.M{"revoked": true}}) -} - -// GetRevoked returns all revoked certs -func (m *MongoStore) GetRevoked() ([]*CertRecord, error) { - s := m.session.Copy() - defer s.Close() - if err := s.Ping(); err != nil { - return nil, err - } - var result []*CertRecord - err := collection(s).Find(bson.M{"expires": bson.M{"$gte": time.Now().UTC()}, "revoked": true}).All(&result) - return result, err -} - -// Close the connection to the database -func (m *MongoStore) Close() error { - m.session.Close() - return nil -} diff --git a/server/store/store.go b/server/store/store.go index 249489a..d157fd1 100644 --- a/server/store/store.go +++ b/server/store/store.go @@ -13,8 +13,6 @@ import ( // New returns a new configured database. func New(c config.Database) (CertStorer, error) { switch c["type"] { - case "mongo": - return NewMongoStore(c) case "mysql", "sqlite": return NewSQLStore(c) case "mem": diff --git a/server/store/store_test.go b/server/store/store_test.go index 4196c37..47e0f74 100644 --- a/server/store/store_test.go +++ b/server/store/store_test.go @@ -111,18 +111,6 @@ func TestMySQLStore(t *testing.T) { testStore(t, db) } -func TestMongoStore(t *testing.T) { - t.Parallel() - if os.Getenv("MONGO_TEST") == "" { - t.Skip("No MONGO_TEST environment variable") - } - db, err := NewMongoStore(map[string]string{"type": "mongo"}) - if err != nil { - t.Error(err) - } - testStore(t, db) -} - func TestSQLiteStore(t *testing.T) { t.Parallel() f, err := ioutil.TempFile("", "sqlite_test_db") |