Commit 51a509d3 authored by ale's avatar ale

Expose websites' statsId via the API

Fixes issue #15.
parent d148c470
Pipeline #6820 passed with stages
in 2 minutes and 8 seconds
......@@ -349,6 +349,7 @@ func (h *websiteResourceHandler) FromLDAP(entry *ldap.Entry) (*as.Resource, erro
//name := fmt.Sprintf("%s/%s", parentSite, alias)
url := fmt.Sprintf("https://www.%s/%s/", parentSite, alias)
uid, _ := strconv.Atoi(entry.GetAttributeValue(uidNumberLDAPAttr)) // nolint
statsID, _ := strconv.Atoi(entry.GetAttributeValue("statsId")) // nolint
return &as.Resource{
ID: as.ResourceID(entry.DN),
......@@ -361,10 +362,18 @@ func (h *websiteResourceHandler) FromLDAP(entry *ldap.Entry) (*as.Resource, erro
Options: entry.GetAttributeValues("option"),
DocumentRoot: entry.GetAttributeValue("documentRoot"),
AcceptMail: false,
StatsID: statsID,
},
}, nil
}
func nonZeroIntToList(i int) []string {
if i == 0 {
return nil
}
return []string{strconv.Itoa(i)}
}
func (h *websiteResourceHandler) ToLDAP(rsrc *as.Resource) []ldap.PartialAttribute {
//bareName := strings.Split(rsrc.Name, "/")[0]
return []ldap.PartialAttribute{
......@@ -374,6 +383,7 @@ func (h *websiteResourceHandler) ToLDAP(rsrc *as.Resource) []ldap.PartialAttribu
{Type: "option", Vals: rsrc.Website.Options},
{Type: "documentRoot", Vals: s2l(rsrc.Website.DocumentRoot)},
{Type: uidNumberLDAPAttr, Vals: s2l(strconv.Itoa(rsrc.Website.UID))},
{Type: "statsId", Vals: nonZeroIntToList(rsrc.Website.StatsID)},
}
}
......@@ -409,6 +419,7 @@ func (h *domainResourceHandler) FromLDAP(entry *ldap.Entry) (*as.Resource, error
cn := entry.GetAttributeValue("cn")
uid, _ := strconv.Atoi(entry.GetAttributeValue(uidNumberLDAPAttr)) // nolint
statsID, _ := strconv.Atoi(entry.GetAttributeValue("statsId")) // nolint
return &as.Resource{
ID: as.ResourceID(entry.DN),
......@@ -420,6 +431,7 @@ func (h *domainResourceHandler) FromLDAP(entry *ldap.Entry) (*as.Resource, error
Options: entry.GetAttributeValues("option"),
DocumentRoot: entry.GetAttributeValue("documentRoot"),
AcceptMail: s2b(entry.GetAttributeValue("acceptMail")),
StatsID: statsID,
},
}, nil
}
......@@ -432,6 +444,7 @@ func (h *domainResourceHandler) ToLDAP(rsrc *as.Resource) []ldap.PartialAttribut
{Type: "documentRoot", Vals: s2l(rsrc.Website.DocumentRoot)},
{Type: "acceptMail", Vals: s2l(b2s(rsrc.Website.AcceptMail))},
{Type: uidNumberLDAPAttr, Vals: s2l(strconv.Itoa(rsrc.Website.UID))},
{Type: "statsId", Vals: nonZeroIntToList(rsrc.Website.StatsID)},
}
}
......
......@@ -72,6 +72,7 @@ func TestResource_LDAPSerialization(t *testing.T) {
AcceptMail: true,
Options: []string{"php", "sendmail"},
DocumentRoot: "/home/web/root",
StatsID: 12345,
},
},
......
......@@ -572,6 +572,7 @@ type Website struct {
Description map[string]string `json:"description,omitempty"`
QuotaUsage int `json:"quota_usage"`
DocumentRoot string `json:"document_root"`
StatsID int `json:"stats_id"`
CMSInfo []*webappdb.App `json:"cms_info,omitempty"`
}
......
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