{
"webAppDir": "www",
- "httpPort": "8000",
+ "httpPort": "8010",
"shareRootDir": "${HOME}/.xds-server/projects",
"logsDir": "/tmp/xds-server/logs",
"sdkRootDir": "/xdt/sdk",
+++ /dev/null
-package apiv1
-
-import (
- "net/http"
- "path"
- "strings"
-
- "path/filepath"
-
- "github.com/gin-gonic/gin"
- common "github.com/iotbzh/xds-common/golib"
-)
-
-// XDSAgentTarball .
-type XDSAgentTarball struct {
- OS string `json:"os"`
- Arch string `json:"arch"`
- Version string `json:"version"`
- RawVersion string `json:"raw-version"`
- FileURL string `json:"fileUrl"`
-}
-
-// XDSAgentInfo .
-type XDSAgentInfo struct {
- Tarballs []XDSAgentTarball `json:"tarballs"`
-}
-
-// getXdsAgentInfo : return various information about Xds Agent
-func (s *APIService) getXdsAgentInfo(c *gin.Context) {
-
- res := XDSAgentInfo{}
- tarballURL := "assets/xds-agent-tarballs"
- tarballDir := filepath.Join(s.cfg.FileConf.WebAppDir, "assets", "xds-agent-tarballs")
- if common.Exists(tarballDir) {
- files, err := filepath.Glob(path.Join(tarballDir, "xds-agent_*.zip"))
- if err != nil {
- s.log.Debugf("Error while retrieving xds-agent tarballs: dir=%s, error=%v", tarballDir, err)
- }
- for _, ff := range files {
- file := filepath.Base(ff)
- // Assume that tarball name format is: xds-agent_OS-ARCH-RAWVERSION.zip
- fs := strings.TrimSuffix(strings.TrimPrefix(file, "xds-agent_"), ".zip")
- f := strings.Split(fs, "-")
-
- if len(f) >= 3 {
- vers := strings.Split(f[2], "_")
- ver := f[2]
- if len(vers) > 1 {
- ver = vers[0]
- }
-
- newT := XDSAgentTarball{
- OS: f[0],
- Arch: f[1],
- Version: ver,
- RawVersion: f[2],
- FileURL: filepath.Join(tarballURL, file),
- }
-
- s.log.Infof("Added XDS-Agent tarball: %s", file)
- res.Tarballs = append(res.Tarballs, newT)
-
- } else {
- s.log.Debugf("Error while retrieving xds-agent, decoding failure: file:%v", ff)
- }
- }
- }
-
- c.JSON(http.StatusOK, res)
-}
}
s.apiRouter.GET("/version", s.getVersion)
- s.apiRouter.GET("/xdsagent/info", s.getXdsAgentInfo)
s.apiRouter.GET("/config", s.getConfig)
s.apiRouter.POST("/config", s.setConfig)
)
type version struct {
+ ID string `json:"id"`
Version string `json:"version"`
APIVersion string `json:"apiVersion"`
VersionGitTag string `json:"gitTag"`
// getInfo : return various information about server
func (s *APIService) getVersion(c *gin.Context) {
response := version{
+ ID: s.cfg.ServerUID,
Version: s.cfg.Version,
APIVersion: s.cfg.APIVersion,
VersionGitTag: s.cfg.VersionGitTag,
package folder
// FolderType definition
-type FolderType int
+type FolderType string
const (
- TypePathMap = 1
- TypeCloudSync = 2
- TypeCifsSmb = 3
+ TypePathMap = "PathMap"
+ TypeCloudSync = "CloudSync"
+ TypeCifsSmb = "CIFS"
)
// Folder Status definition
// CloudSyncConfig CloudSync (AKA Syncthing) specific data
type CloudSyncConfig struct {
- SyncThingID string `json:"syncThingID"`
- BuilderSThgID string `json:"builderSThgID"`
+ SyncThingID string `json:"syncThingID"`
}
// getConfigArrUnsafe Same as GetConfigArr without mutex protection
func (f *Folders) getConfigArrUnsafe() []folder.FolderConfig {
- var conf []folder.FolderConfig
-
+ conf := []folder.FolderConfig{}
for _, v := range f.folders {
conf = append(conf, (*v).GetConfig())
}
f.fConfig = cfg
- f.fConfig.DataCloudSync.BuilderSThgID = f.st.MyID // FIXME - should be removed after local ST config rework
-
// Update Syncthing folder
// (expect if status is ErrorConfig)
// TODO: add cache to avoid multiple requests on startup
env := []string{
"STNODEFAULTFOLDER=1",
"STNOUPGRADE=1",
- "STNORESTART=1", // FIXME SEB remove ?
}
s.STCmd, err = s.startProc("syncthing", args, env, &s.exitSTChan)
return b, nil
}
-// Copy makes a real copy of BuilderConfig
-func (c *BuilderConfig) Copy(n BuilderConfig) {
- // TODO
-}
+/*** Private ***/
func getLocalIP() (string, error) {
addrs, err := net.InterfaceAddrs()
// Config parameters (json format) of /config command
type Config struct {
- Version string `json:"version"`
- APIVersion string `json:"apiVersion"`
- VersionGitTag string `json:"gitTag"`
- Builder BuilderConfig `json:"builder"`
+ ServerUID string `json:"id"`
+ Version string `json:"version"`
+ APIVersion string `json:"apiVersion"`
+ VersionGitTag string `json:"gitTag"`
+ SupportedSharing map[string]bool `json:"supportedSharing"`
+ Builder BuilderConfig `json:"builder"`
// Private (un-exported fields in REST GET /config route)
Options Options `json:"-"`
dfltSTHomeDir = resDir
}
+ uuid, err := ServerIDGet()
+ if err != nil {
+ return nil, err
+ }
+
// Define default configuration
c := Config{
- Version: cliCtx.App.Metadata["version"].(string),
- APIVersion: DefaultAPIVersion,
- VersionGitTag: cliCtx.App.Metadata["git-tag"].(string),
- Builder: BuilderConfig{},
+ ServerUID: uuid,
+ Version: cliCtx.App.Metadata["version"].(string),
+ APIVersion: DefaultAPIVersion,
+ VersionGitTag: cliCtx.App.Metadata["git-tag"].(string),
+ Builder: BuilderConfig{},
+ SupportedSharing: map[string]bool{ /*FIXME USE folder.TypePathMap*/ "PathMap": true},
Options: Options{
ConfigFile: cliCtx.GlobalString("config"),
--- /dev/null
+package xdsconfig
+
+import (
+ "encoding/xml"
+ "fmt"
+ "os"
+
+ common "github.com/iotbzh/xds-common/golib"
+ uuid "github.com/satori/go.uuid"
+ "github.com/syncthing/syncthing/lib/sync"
+)
+
+// xmlServerData contains persistent data stored/loaded by server
+type xmlServerData struct {
+ XMLName xml.Name `xml:"XDS-Server"`
+ Version string `xml:"version,attr"`
+ Data ServerData `xml:"server-data"`
+}
+
+type ServerData struct {
+ ID string `xml:"id"`
+}
+
+var sdMutex = sync.NewMutex()
+
+// ServerIDGet
+func ServerIDGet() (string, error) {
+ var f string
+ var err error
+
+ d := ServerData{}
+ if f, err = ServerDataFilenameGet(); err != nil {
+ return "", err
+ }
+ if err = serverDataRead(f, &d); err != nil || d.ID == "" {
+ // Create a new uuid when not found
+ d.ID = uuid.NewV1().String()
+ if err := serverDataWrite(f, d); err != nil {
+ return "", err
+ }
+ }
+ return d.ID, nil
+}
+
+// serverDataRead reads data saved on disk
+func serverDataRead(file string, data *ServerData) error {
+ if !common.Exists(file) {
+ return fmt.Errorf("No folder config file found (%s)", file)
+ }
+
+ sdMutex.Lock()
+ defer sdMutex.Unlock()
+
+ fd, err := os.Open(file)
+ defer fd.Close()
+ if err != nil {
+ return err
+ }
+
+ xsd := xmlServerData{}
+ err = xml.NewDecoder(fd).Decode(&xsd)
+ if err == nil {
+ *data = xsd.Data
+ }
+ return err
+}
+
+// serverDataWrite writes persistant data to disk
+func serverDataWrite(file string, data ServerData) error {
+ sdMutex.Lock()
+ defer sdMutex.Unlock()
+
+ fd, err := os.OpenFile(file, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
+ defer fd.Close()
+ if err != nil {
+ return err
+ }
+
+ xsd := &xmlServerData{
+ Version: "1",
+ Data: data,
+ }
+
+ enc := xml.NewEncoder(fd)
+ enc.Indent("", " ")
+ return enc.Encode(xsd)
+}
ConfigDir = ".xds-server"
// GlobalConfigFilename Global config filename
GlobalConfigFilename = "config.json"
+ // ServerDataFilename Server data filename
+ ServerDataFilename = "server-data.xml"
// FoldersConfigFilename Folders config filename
FoldersConfigFilename = "server-config_folders.xml"
)
return nil
}
-// FoldersConfigFilenameGet
-func FoldersConfigFilenameGet() (string, error) {
+func configFilenameGet(cfgFile string) (string, error) {
usr, err := user.Current()
if err != nil {
return "", err
}
- return path.Join(usr.HomeDir, ConfigDir, FoldersConfigFilename), nil
+ return path.Join(usr.HomeDir, ConfigDir, cfgFile), nil
+}
+
+// FoldersConfigFilenameGet
+func FoldersConfigFilenameGet() (string, error) {
+ return configFilenameGet(FoldersConfigFilename)
+}
+
+// ServerDataFilenameGet
+func ServerDataFilenameGet() (string, error) {
+ return configFilenameGet(ServerDataFilename)
}
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/iotbzh/xds-server/lib/crosssdk"
+ "github.com/iotbzh/xds-server/lib/folder"
"github.com/iotbzh/xds-server/lib/model"
"github.com/iotbzh/xds-server/lib/syncthing"
"github.com/iotbzh/xds-server/lib/webserver"
if ctx.Config.Builder, err = xdsconfig.NewBuilderConfig(ctx.SThg.MyID); err != nil {
return cli.NewExitError(err, -4)
}
+ ctx.Config.SupportedSharing[folder.TypeCloudSync] = true
}
// Init model folder