diff pkg/models/importbase.go @ 2036:74e24ae3205a unify_imports

Imports: Added a persistent model for the extra attributes.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 25 Jan 2019 11:52:54 +0100
parents 83108e90b223
children d29ac997eb34
line wrap: on
line diff
--- a/pkg/models/importbase.go	Fri Jan 25 11:26:20 2019 +0100
+++ b/pkg/models/importbase.go	Fri Jan 25 11:52:54 2019 +0100
@@ -15,8 +15,10 @@
 
 import (
 	"encoding/json"
+	"errors"
 	"time"
 
+	"gemma.intevation.de/gemma/pkg/common"
 	"github.com/robfig/cron"
 )
 
@@ -80,3 +82,32 @@
 	*cs = CronSpec(spec)
 	return nil
 }
+
+func (ut *URLType) MarshalAttributes(attrs common.Attributes) error {
+	attrs.Set("url", ut.URL)
+	if ut.Insecure {
+		attrs.SetBool("insecure", ut.Insecure)
+	}
+	if ut.User != nil {
+		attrs.Set("user", *ut.User)
+	}
+	if ut.Password != nil {
+		attrs.Set("password", *ut.Password)
+	}
+	return nil
+}
+
+func (ut *URLType) UnmarshalAttributes(attrs common.Attributes) error {
+	url, found := attrs.Get("url")
+	if !found {
+		return errors.New("missing 'url' attribute")
+	}
+	ut.URL = url
+	if user, found := attrs.Get("user"); found {
+		ut.User = &user
+	}
+	if password, found := attrs.Get("password"); found {
+		ut.Password = &password
+	}
+	return nil
+}