diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-09-25 14:15:16 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-10-06 18:25:04 +0200 |
commit | 97ca1f277dc8b6973d6fa67add5593a9c395ce60 (patch) | |
tree | 761649d7771e8699a67567476c17fb2fa0e28e57 /lib/agent/project-pathmap.go | |
parent | 12a20d0905b0d3e7e0f4c9ec8ee619f683256d71 (diff) |
Added webapp Dashboard + logic to interact with server.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/agent/project-pathmap.go')
-rw-r--r-- | lib/agent/project-pathmap.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/agent/project-pathmap.go b/lib/agent/project-pathmap.go new file mode 100644 index 0000000..1de8e11 --- /dev/null +++ b/lib/agent/project-pathmap.go @@ -0,0 +1,79 @@ +package agent + +import ( + "path/filepath" +) + +// IPROJECT interface implementation for native/path mapping projects + +// PathMap . +type PathMap struct { + *Context + server *XdsServer + folder *FolderConfig +} + +// NewProjectPathMap Create a new instance of PathMap +func NewProjectPathMap(ctx *Context, svr *XdsServer) *PathMap { + p := PathMap{ + Context: ctx, + server: svr, + folder: &FolderConfig{}, + } + return &p +} + +// Add a new project +func (p *PathMap) Add(cfg ProjectConfig) (*ProjectConfig, error) { + var err error + + // SEB TODO: check local/server directory access + + err = p.server.FolderAdd(p.server.ProjectToFolder(cfg), p.folder) + if err != nil { + return nil, err + } + + return p.GetProject(), nil +} + +// Delete a project +func (p *PathMap) Delete() error { + return p.server.FolderDelete(p.folder.ID) +} + +// GetProject Get public part of project config +func (p *PathMap) GetProject() *ProjectConfig { + prj := p.server.FolderToProject(*p.folder) + prj.ServerID = p.server.ID + return &prj +} + +// SetProject Set project config +func (p *PathMap) SetProject(prj ProjectConfig) *ProjectConfig { + p.folder = p.server.ProjectToFolder(prj) + return p.GetProject() +} + +// GetServer Get the XdsServer that holds this project +func (p *PathMap) GetServer() *XdsServer { + return p.server +} + +// GetFullPath returns the full path of a directory (from server POV) +func (p *PathMap) GetFullPath(dir string) string { + if &dir == nil { + return p.folder.DataPathMap.ServerPath + } + return filepath.Join(p.folder.DataPathMap.ServerPath, dir) +} + +// Sync Force project files synchronization +func (p *PathMap) Sync() error { + return nil +} + +// IsInSync Check if project files are in-sync +func (p *PathMap) IsInSync() (bool, error) { + return true, nil +} |