auth
auth/sql/postgres_init.sql
Implement postgres version of scopeStore. Update the authd server to use postgres as its scopeStore, instead of memstore. panic when starting the authd server if the CreateScopes call fails. This should, ideally, ignore ErrScopeAlreadyExists errors, but does not as of this commit. Update the simple.gotmpl template to properly display scopes, after switching to the Scope type instead of simply passing around the string the client supplied broke the template and I never bothered fixing it. Update the updateScopes method on the scopeStore (and the corresponding UpdateScopes method on the Context type) to be updateScope/UpdateScope. Operating on several scopes at a time like that is simply too challenging in SQL and I can't justify the complexity with a use case. Add a helper method to ScopeChange called Empty(), which returns true if the ScopeChange is full of nil values. Remove the ID from the ScopeChange type, because we're no longer accepting multiple ScopeChange types in UpdateScope, so we can supply that information outside the ScopeChange, which matches the rest of our update* methods. Correct our tests in scope_test.go to correctly use the updateScope method instead of the old updateScopes method. This generally just resulted in calling updateScope multiple times, as opposed to just once. Add a scope table initialization to the sql/postgres_init.sql script.
| paddy@149 | 1 CREATE TABLE IF NOT EXISTS profiles ( |
| paddy@149 | 2 id VARCHAR(36) PRIMARY KEY, |
| paddy@149 | 3 name VARCHAR(64) NOT NULL, |
| paddy@149 | 4 passphrase VARCHAR(64) NOT NULL, |
| paddy@149 | 5 iterations INTEGER NOT NULL, |
| paddy@149 | 6 salt VARCHAR(64) NOT NULL, |
| paddy@149 | 7 passphrase_scheme INTEGER NOT NULL, |
| paddy@149 | 8 compromised BOOLEAN NOT NULL, |
| paddy@149 | 9 locked_until TIMESTAMPTZ NOT NULL, |
| paddy@149 | 10 passphrase_reset VARCHAR(64) NOT NULL, |
| paddy@149 | 11 passphrase_reset_created TIMESTAMPTZ NOT NULL, |
| paddy@149 | 12 created TIMESTAMPTZ NOT NULL, |
| paddy@149 | 13 last_seen TIMESTAMPTZ NOT NULL, |
| paddy@149 | 14 deleted BOOLEAN NOT NULL |
| paddy@149 | 15 ); |
| paddy@149 | 16 |
| paddy@149 | 17 CREATE TABLE IF NOT EXISTS logins ( |
| paddy@149 | 18 type VARCHAR(16) NOT NULL, |
| paddy@149 | 19 value VARCHAR(64) PRIMARY KEY, |
| paddy@149 | 20 profile_id VARCHAR(36) NOT NULL, |
| paddy@149 | 21 created TIMESTAMPTZ NOT NULL, |
| paddy@149 | 22 last_used TIMESTAMPTZ NOT NULL |
| paddy@149 | 23 ); |
| paddy@151 | 24 |
| paddy@151 | 25 CREATE TABLE IF NOT EXISTS clients ( |
| paddy@151 | 26 id VARCHAR(36) PRIMARY KEY, |
| paddy@151 | 27 secret VARCHAR(64) NOT NULL, |
| paddy@151 | 28 owner_id VARCHAR(36) NOT NULL, |
| paddy@151 | 29 name VARCHAR(32) NOT NULL, |
| paddy@151 | 30 logo VARCHAR(512) NOT NULL, |
| paddy@151 | 31 website VARCHAR(140) NOT NULL, |
| paddy@151 | 32 type VARCHAR(16) NOT NULL, |
| paddy@151 | 33 deleted BOOLEAN NOT NULL |
| paddy@151 | 34 ); |
| paddy@151 | 35 |
| paddy@151 | 36 CREATE TABLE IF NOT EXISTS endpoints ( |
| paddy@151 | 37 id VARCHAR(36) PRIMARY KEY, |
| paddy@151 | 38 client_id VARCHAR(36) NOT NULL, |
| paddy@151 | 39 uri VARCHAR(512) NOT NULL, |
| paddy@151 | 40 normalized_uri VARCHAR(512) NOT NULL, |
| paddy@151 | 41 added TIMESTAMPTZ NOT NULL |
| paddy@151 | 42 ); |
| paddy@152 | 43 |
| paddy@152 | 44 CREATE TABLE IF NOT EXISTS scopes ( |
| paddy@152 | 45 id VARCHAR(64) PRIMARY KEY, |
| paddy@152 | 46 name VARCHAR(64) NOT NULL, |
| paddy@152 | 47 description TEXT NOT NULL |
| paddy@152 | 48 ); |