Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
Choose a Base Repository
Choose a base branch
...
Choose a Head Repository
Choose a head branch
  • 5 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 09, 2012
Commits on Dec 17, 2012
Commits on Dec 21, 2012
Showing with 513 additions and 147 deletions.
  1. +26 −26 account.go
  2. +10 −10 audit.go
  3. +12 −11 config.go
  4. +59 −21 device.go
  5. +329 −15 link.go
  6. +5 −1 log.go
  7. +11 −9 notification.go
  8. +18 −16 twocloud.go
  9. +43 −38 user.go
View
@@ -7,13 +7,13 @@ import (
"github.com/fzzbt/radix/redis"
"io/ioutil"
"net/http"
- "secondbit.org/ruid"
+ "strconv"
"time"
)
type Account struct {
Added time.Time `json:"added,omitempty"`
- ID ruid.RUID `json:"id,omitempty"`
+ ID uint64 `json:"id,omitempty"`
Provider string `json:"provider,omitempty"`
// Provided by the provider
ForeignID string `json:"foreign_id,omitempty"`
@@ -27,14 +27,14 @@ type Account struct {
Timezone string `json:"timezone,omitempty"`
Gender string `json:"gender,omitempty"`
// private info that is stored, never shared
- UserID ruid.RUID `json:"-"`
+ UserID uint64 `json:"-"`
accessToken string
refreshToken string
expires time.Time
}
func (account *Account) IsEmpty() bool {
- return account.ID.String() == ruid.RUID(0).String()
+ return account.ID == 0
}
type googleAccount struct {
@@ -126,12 +126,12 @@ func (r *RequestBundle) GetAccount(access, refresh string, expiration time.Time)
Timezone: googAccount.Timezone,
Locale: googAccount.Locale,
Gender: googAccount.Gender,
- UserID: ruid.RUID(0),
+ UserID: 0,
accessToken: access,
refreshToken: refresh,
expires: expiration,
}
- id, err := gen.Generate([]byte(googAccount.ID))
+ id, err := r.GetID()
if err != nil {
r.Log.Error(err.Error())
return Account{}, err
@@ -219,7 +219,7 @@ func (r *RequestBundle) getAccountByForeignID(foreign_id string) (Account, error
r.Log.Error(err.Error())
return Account{}, nil
}
- id, err := ruid.RUIDFromString(account_id)
+ id, err := strconv.ParseUint(account_id, 10, 64)
if err != nil {
r.Log.Error(err.Error())
return Account{}, err
@@ -234,16 +234,16 @@ func (r *RequestBundle) getAccountByForeignID(foreign_id string) (Account, error
return account, nil
}
-func (r *RequestBundle) GetAccountByID(id ruid.RUID) (Account, error) {
+func (r *RequestBundle) GetAccountByID(id uint64) (Account, error) {
// start instrumentation
- reply := r.Repo.client.Hgetall("accounts:" + id.String())
+ reply := r.Repo.client.Hgetall("accounts:" + strconv.FormatUint(id, 10))
// report the request to the repo to instrumentation
if reply.Err != nil {
r.Log.Error(reply.Err.Error())
return Account{}, reply.Err
}
if reply.Type == redis.ReplyNil {
- r.Log.Warn("Account not found. ID: %s", id)
+ r.Log.Warn("Account not found. ID: %d", id)
return Account{}, nil
}
hash, err := reply.Hash()
@@ -261,7 +261,7 @@ func (r *RequestBundle) GetAccountByID(id ruid.RUID) (Account, error) {
r.Log.Error(err.Error())
return Account{}, err
}
- user_id, err := ruid.RUIDFromString(hash["user_id"])
+ user_id, err := strconv.ParseUint(hash["user_id"], 10, 64)
if err != nil {
return Account{}, err
}
@@ -336,8 +336,8 @@ func (r *RequestBundle) storeAccount(account Account, update bool) error {
from["gender"] = old_account.Gender
}
if old_account.UserID != account.UserID {
- changes["user_id"] = account.UserID.String()
- from["user_id"] = old_account.UserID.String()
+ changes["user_id"] = account.UserID
+ from["user_id"] = old_account.UserID
}
if old_account.accessToken != account.accessToken {
changes["access_token"] = account.accessToken
@@ -351,20 +351,20 @@ func (r *RequestBundle) storeAccount(account Account, update bool) error {
changes["expires"] = account.expires.Format(time.RFC3339)
from["expires"] = old_account.expires.Format(time.RFC3339)
}
- reply := r.Repo.client.Hmset("accounts:"+account.ID.String(), changes)
+ reply := r.Repo.client.Hmset("accounts:"+strconv.FormatUint(account.ID, 10), changes)
// add repo call to instrumentation
if reply.Err != nil {
r.Log.Error(reply.Err.Error())
return reply.Err
}
- reply = r.Repo.client.Sadd("users:"+account.UserID.String()+":accounts", account.ID.String())
+ reply = r.Repo.client.Sadd("users:"+strconv.FormatUint(account.UserID, 10)+":accounts", account.ID, 10)
// add repo call to instrumentation
if reply.Err != nil {
r.Log.Error(reply.Err.Error())
return reply.Err
}
- r.AuditMap("accounts:"+account.ID.String(), from, changes)
+ r.AuditMap("accounts:"+strconv.FormatUint(account.ID, 10), from, changes)
// add repo call to instrumentation
return nil
}
@@ -381,7 +381,7 @@ func (r *RequestBundle) storeAccount(account Account, update bool) error {
"locale": account.Locale,
"timezone": account.Timezone,
"gender": account.Gender,
- "user_id": account.UserID.String(),
+ "user_id": account.UserID,
"access_token": account.accessToken,
"refresh_token": account.refreshToken,
"expires": account.expires.Format(time.RFC3339),
@@ -405,25 +405,25 @@ func (r *RequestBundle) storeAccount(account Account, update bool) error {
"expires": "",
}
reply := r.Repo.client.MultiCall(func(mc *redis.MultiCall) {
- mc.Hmset("accounts:"+account.ID.String(), changes)
- mc.Hmset("oauth_foreign_ids_to_accounts", account.ForeignID, account.ID.String())
- mc.Sadd("users:"+account.UserID.String()+":accounts", account.ID.String())
+ mc.Hmset("accounts:"+strconv.FormatUint(account.ID, 10), changes)
+ mc.Hmset("oauth_foreign_ids_to_accounts", account.ForeignID, strconv.FormatUint(account.ID, 10))
+ mc.Sadd("users:"+strconv.FormatUint(account.UserID, 10)+":accounts", account.ID)
})
// add repo call to instrumentation
if reply.Err != nil {
r.Log.Error(reply.Err.Error())
return reply.Err
}
- r.AuditMap("accounts:"+account.ID.String(), from, changes)
- r.Audit("oauth_foreign_ids_to_accounts", account.ForeignID, "", account.ID.String())
+ r.AuditMap("accounts:"+strconv.FormatUint(account.ID, 10), from, changes)
+ r.Audit("oauth_foreign_ids_to_accounts", account.ForeignID, "", strconv.FormatUint(account.ID, 10))
// report the repo request to instrumentation
// stop instrumentation
return nil
}
func (r *RequestBundle) GetAccountsByUser(user User) ([]Account, error) {
// start instrumentation
- reply := r.Repo.client.Smembers("users:" + user.ID.String() + ":accounts")
+ reply := r.Repo.client.Smembers("users:" + strconv.FormatUint(user.ID, 10) + ":accounts")
// report the repo request to instrumentation
if reply.Err != nil {
r.Log.Error(reply.Err.Error())
@@ -469,12 +469,12 @@ func (r *RequestBundle) GetAccountsByUser(user User) ([]Account, error) {
r.Log.Error(err.Error())
continue
}
- user_id, err := ruid.RUIDFromString(hash["user_id"])
+ user_id, err := strconv.ParseUint(hash["user_id"], 10, 64)
if err != nil {
r.Log.Error(err.Error())
continue
}
- id, err := ruid.RUIDFromString(ids[pos])
+ id, err := strconv.ParseUint(ids[pos], 10, 64)
if err != nil {
r.Log.Error(err.Error())
continue
@@ -544,7 +544,7 @@ func (r *RequestBundle) UpdateAccountData(account Account) (Account, error) {
return account, nil
}
-func (r *RequestBundle) AssociateUserWithAccount(account Account, user ruid.RUID) error {
+func (r *RequestBundle) AssociateUserWithAccount(account Account, user uint64) error {
// begin instrumentation
account.UserID = user
err := r.storeAccount(account, true)
View
@@ -2,7 +2,7 @@ package twocloud
import (
"github.com/fzzbt/radix/redis"
- "secondbit.org/ruid"
+ "strconv"
"time"
)
@@ -21,7 +21,7 @@ func (a *Auditor) Close() {
}
type Change struct {
- ID ruid.RUID `json:"id"`
+ ID uint64 `json:"id"`
Key string `json:"key"`
Field string `json:"field"`
From interface{} `json:"from"`
@@ -31,10 +31,10 @@ type Change struct {
Timestamp time.Time `json:"timestamp"`
}
-func (a *Auditor) Insert(key, ip string, user User, from, to map[string]interface{}) error {
+func (a *Auditor) Insert(r *RequestBundle, key, ip string, user User, from, to map[string]interface{}) error {
changes := []Change{}
for k, v := range to {
- id, err := gen.Generate([]byte(key))
+ id, err := r.GetID()
if err != nil {
return err
}
@@ -53,11 +53,11 @@ func (a *Auditor) Insert(key, ip string, user User, from, to map[string]interfac
reply := a.client.MultiCall(func(mc *redis.MultiCall) {
for _, change := range changes {
user_str := ""
- if change.User.ID != ruid.RUID(0) {
- user_str = change.User.ID.String()
+ if change.User.ID != 0 {
+ user_str = strconv.FormatUint(change.User.ID, 10)
}
- mc.Hmset("audit:"+change.Key+":item:"+change.ID.String(), "from", change.From, "to", change.To, "field", change.Field, "timestamp", change.Timestamp.Format(time.RFC3339), "user", user_str)
- mc.Lpush("audit:"+key, change.ID.String())
+ mc.Hmset("audit:"+change.Key+":item:"+strconv.FormatUint(change.ID, 10), "from", change.From, "to", change.To, "field", change.Field, "timestamp", change.Timestamp.Format(time.RFC3339), "user", user_str)
+ mc.Lpush("audit:"+key, change.ID)
}
})
return reply.Err
@@ -69,7 +69,7 @@ func (r *RequestBundle) Audit(key, field, fromstr, tostr string) {
from[field] = fromstr
to := map[string]interface{}{}
to[field] = tostr
- err := r.Auditor.Insert(key, r.Request.RemoteAddr, r.AuthUser, from, to)
+ err := r.Auditor.Insert(r, key, r.Request.RemoteAddr, r.AuthUser, from, to)
if err != nil {
r.Log.Error(err.Error())
}
@@ -78,7 +78,7 @@ func (r *RequestBundle) Audit(key, field, fromstr, tostr string) {
func (r *RequestBundle) AuditMap(key string, from, to map[string]interface{}) {
if r.Auditor != nil {
- err := r.Auditor.Insert(key, r.Request.RemoteAddr, r.AuthUser, from, to)
+ err := r.Auditor.Insert(r, key, r.Request.RemoteAddr, r.AuthUser, from, to)
if err != nil {
r.Log.Error(err.Error())
}
View
@@ -6,18 +6,19 @@ import (
)
type Config struct {
- UseSubscriptions bool `json:"subscriptions"`
- MaintenanceMode bool `json:"maintenance"`
- Database redis.Config `json:"db"`
- AuditDatabase redis.Config `json:"audit_db"`
- StatsDatabase redis.Config `json:"stats_db"`
- OAuth OAuthClient `json:"oauth"`
- TrialPeriod time.Duration `json:"trial_period"`
- GracePeriod time.Duration `json:"grace_period"`
+ UseSubscriptions bool `json:"subscriptions"`
+ MaintenanceMode bool `json:"maintenance"`
+ Database redis.Config `json:"db"`
+ AuditDatabase redis.Config `json:"audit_db"`
+ InstrumentationDatabase redis.Config `json:"instrumentation_db"`
+ OAuth OAuthClient `json:"oauth"`
+ TrialPeriod time.Duration `json:"trial_period"`
+ GracePeriod time.Duration `json:"grace_period"`
+ IDGenerators map[string]string `json:"id_gen"`
}
type OAuthClient struct {
- ClientID string
- ClientSecret string
- CallbackURL string
+ ClientID string `json:"client_id"`
+ ClientSecret string `json:"client_secret"`
+ CallbackURL string `json:"callback"`
}
Oops, something went wrong.

No commit comments for this range