An atproto PDS written in Go

better formatting for acocunt info

Changed files
+31 -10
server
+1
go.mod
··· 14 github.com/google/uuid v1.4.0 15 github.com/gorilla/sessions v1.4.0 16 github.com/gorilla/websocket v1.5.1 17 github.com/hashicorp/golang-lru/v2 v2.0.7 18 github.com/ipfs/go-block-format v0.2.0 19 github.com/ipfs/go-cid v0.4.1
··· 14 github.com/google/uuid v1.4.0 15 github.com/gorilla/sessions v1.4.0 16 github.com/gorilla/websocket v1.5.1 17 + github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b 18 github.com/hashicorp/golang-lru/v2 v2.0.7 19 github.com/ipfs/go-block-format v0.2.0 20 github.com/ipfs/go-cid v0.4.1
+2
go.sum
··· 91 github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= 92 github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= 93 github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= 94 github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= 95 github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= 96 github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
··· 91 github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= 92 github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= 93 github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= 94 + github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4= 95 + github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0= 96 github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= 97 github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= 98 github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
+24 -6
server/handle_account.go
··· 6 "github.com/haileyok/cocoon/oauth" 7 "github.com/haileyok/cocoon/oauth/constants" 8 "github.com/haileyok/cocoon/oauth/provider" 9 "github.com/labstack/echo/v4" 10 ) 11 12 func (s *Server) handleAccount(e echo.Context) error { 13 repo, sess, err := s.getSessionRepoOrErr(e) 14 if err != nil { 15 return e.Redirect(303, "/account/signin") ··· 36 filtered = append(filtered, t) 37 } 38 39 tokenInfo := []map[string]string{} 40 for _, t := range tokens { 41 tokenInfo = append(tokenInfo, map[string]string{ 42 - "ClientId": t.ClientId, 43 - "CreatedAt": t.CreatedAt.Format("02 Jan 06 15:04 MST"), 44 - "UpdatedAt": t.CreatedAt.Format("02 Jan 06 15:04 MST"), 45 - "ExpiresAt": t.CreatedAt.Format("02 Jan 06 15:04 MST"), 46 - "Token": t.Token, 47 - "Ip": t.Ip, 48 }) 49 } 50
··· 6 "github.com/haileyok/cocoon/oauth" 7 "github.com/haileyok/cocoon/oauth/constants" 8 "github.com/haileyok/cocoon/oauth/provider" 9 + "github.com/hako/durafmt" 10 "github.com/labstack/echo/v4" 11 ) 12 13 func (s *Server) handleAccount(e echo.Context) error { 14 + ctx := e.Request().Context() 15 repo, sess, err := s.getSessionRepoOrErr(e) 16 if err != nil { 17 return e.Redirect(303, "/account/signin") ··· 38 filtered = append(filtered, t) 39 } 40 41 + now := time.Now() 42 + 43 tokenInfo := []map[string]string{} 44 for _, t := range tokens { 45 + ageRes := oauth.GetSessionAgeFromToken(t) 46 + maxTime := constants.PublicClientSessionLifetime 47 + if t.ClientAuth.Method != "none" { 48 + maxTime = constants.ConfidentialClientSessionLifetime 49 + } 50 + 51 + var clientName string 52 + metadata, err := s.oauthProvider.ClientManager.GetClient(ctx, t.ClientId) 53 + if err != nil { 54 + clientName = t.ClientId 55 + } else { 56 + clientName = metadata.Metadata.ClientName 57 + } 58 + 59 tokenInfo = append(tokenInfo, map[string]string{ 60 + "ClientName": clientName, 61 + "Age": durafmt.Parse(ageRes.SessionAge).LimitFirstN(2).String(), 62 + "LastUpdated": durafmt.Parse(now.Sub(t.UpdatedAt)).LimitFirstN(2).String(), 63 + "ExpiresIn": durafmt.Parse(now.Add(maxTime).Sub(now)).LimitFirstN(2).String(), 64 + "Token": t.Token, 65 + "Ip": t.Ip, 66 }) 67 } 68
+4 -4
server/templates/account.html
··· 24 </div> 25 {{ else }} {{ range .Tokens }} 26 <div class="base-container"> 27 - <h4>{{ .ClientId }}</h4> 28 - <p>Created: {{ .CreatedAt }}</p> 29 - <p>Updated: {{ .UpdatedAt }}</p> 30 - <p>Expires: {{ .ExpiresAt }}</p> 31 <p>IP Address: {{ .Ip }}</p> 32 <form action="/account/revoke" method="post"> 33 <input type="hidden" name="token" value="{{ .Token }}" />
··· 24 </div> 25 {{ else }} {{ range .Tokens }} 26 <div class="base-container"> 27 + <h4>{{ .ClientName }}</h4> 28 + <p>Session Age: {{ .Age}}</p> 29 + <p>Last Updated: {{ .LastUpdated }} ago</p> 30 + <p>Expires In: {{ .ExpiresIn }}</p> 31 <p>IP Address: {{ .Ip }}</p> 32 <form action="/account/revoke" method="post"> 33 <input type="hidden" name="token" value="{{ .Token }}" />