Commit 6a90ae2c authored by ale's avatar ale

Add creation date to all resources

Fixes issue #10.
parent cb2259cf
Pipeline #5696 passed with stages
in 3 minutes and 56 seconds
......@@ -30,6 +30,7 @@ const (
u2fRegistrationsLDAPAttr = "u2fRegistration"
uidNumberLDAPAttr = "uidNumber"
gidNumberLDAPAttr = "gidNumber"
creationDateLDAPAttr = "creationDate"
)
// Interface to something that adds Resources to a User.
......@@ -134,11 +135,11 @@ func newUser(entry *ldap.Entry) (*as.RawUser, error) {
uidNumber, _ := strconv.Atoi(entry.GetAttributeValue(uidNumberLDAPAttr)) // nolint
user := &as.RawUser{
User: as.User{
Name: entry.GetAttributeValue("uid"),
Lang: entry.GetAttributeValue(preferredLanguageLDAPAttr),
UID: uidNumber,
Status: entry.GetAttributeValue("status"),
Shard: entry.GetAttributeValue("host"),
Name: entry.GetAttributeValue("uid"),
Lang: entry.GetAttributeValue(preferredLanguageLDAPAttr),
UID: uidNumber,
Status: entry.GetAttributeValue("status"),
Shard: entry.GetAttributeValue("host"),
LastPasswordChangeStamp: decodeShadowTimestamp(entry.GetAttributeValue(passwordLastChangeLDAPAttr)),
AccountRecoveryHint: entry.GetAttributeValue(recoveryHintLDAPAttr),
U2FRegistrations: decodeU2FRegistrations(entry.GetAttributeValues(u2fRegistrationsLDAPAttr)),
......
......@@ -115,6 +115,7 @@ func TestModel_GetUser(t *testing.T) {
Shard: "host2",
OriginalShard: "host2",
Status: as.ResourceStatusActive,
CreatedAt: "01-08-2013",
Database: &as.Database{
DBUser: "unodb",
},
......
......@@ -77,6 +77,11 @@ func (reg *resourceRegistry) ToLDAP(rsrc *as.Resource) (attrs []ldap.PartialAttr
return nil
}
if rsrc.CreatedAt != "" {
attrs = append(attrs, ldap.PartialAttribute{
Type: creationDateLDAPAttr, Vals: s2l(rsrc.CreatedAt)})
}
attrs = append(attrs, []ldap.PartialAttribute{
{Type: "status", Vals: s2l(rsrc.Status)},
{Type: "host", Vals: s2l(rsrc.Shard)},
......@@ -89,6 +94,7 @@ func setCommonResourceAttrs(entry *ldap.Entry, rsrc *as.Resource) {
rsrc.Status = entry.GetAttributeValue("status")
rsrc.Shard = entry.GetAttributeValue("host")
rsrc.OriginalShard = entry.GetAttributeValue("originalHost")
rsrc.CreatedAt = entry.GetAttributeValue(creationDateLDAPAttr)
}
func (reg *resourceRegistry) FromLDAP(entry *ldap.Entry) (rsrc *as.Resource, err error) {
......
......@@ -472,6 +472,11 @@ type Resource struct {
Shard string `json:"shard,omitempty"`
OriginalShard string `json:"original_shard,omitempty"`
// Creation date (no time recorded) of the resource. Since our
// database contains legacy values with different formats, the
// field is left unparsed as a string.
CreatedAt string `json:"created_at"`
// Resources can be 'grouped' together, for various reasons
// (display purposes, service integrity). All resources in the
// same group should have the same Shard. Group names can be
......
......@@ -10,6 +10,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"
"golang.org/x/net/publicsuffix"
)
......@@ -1010,6 +1011,8 @@ func (c *templateContext) setCommonResourceAttrs(ctx context.Context, r *Resourc
}
}
r.CreatedAt = time.Now().UTC().Format("2006-01-02")
c.setResourceStatus(r)
return c.setResourceShard(ctx, r, ref)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment