CreateProfile takes attributes
continuous-integration/drone/pr Build is passing Details

createProfileAttr
Dan Ballard 2 months ago
parent 667fc15294
commit 32a02b68dc

@ -34,6 +34,8 @@ type application struct {
// Application is a full cwtch peer application. It allows management, usage and storage of multiple peers
type Application interface {
LoadProfiles(password string)
CreatePeer(name string, password string, attributes map[attr.ZonedPath]string)
// Deprecated in 1.10
CreateTaggedPeer(name string, password string, tag string)
ImportProfile(exportedCwtchFile string, password string) (peer.CwtchPeer, error)
DeletePeer(onion string, currentPassword string)
@ -122,7 +124,12 @@ func (ap *application) AddPlugin(peerid string, id plugins.PluginID, bus event.M
}
}
// Deprecated in 1.10
func (app *application) CreateTaggedPeer(name string, password string, tag string) {
app.CreatePeer(name, password, map[attr.ZonedPath]string{attr.ProfileZone.ConstructZonedPath(constants.Tag): tag})
}
func (app *application) CreatePeer(name string, password string, attributes map[attr.ZonedPath]string) {
app.appmutex.Lock()
defer app.appmutex.Unlock()
@ -140,9 +147,11 @@ func (app *application) CreateTaggedPeer(name string, password string, tag strin
profile.Init(app.eventBuses[profile.GetOnion()])
app.peers[profile.GetOnion()] = profile
if tag != "" {
profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag, tag)
for zp, val := range attributes {
zone, key := attr.ParseZone(zp.ToString())
profile.SetScopedZonedAttribute(attr.LocalScope, zone, key, val)
}
app.AddPeerPlugin(profile.GetOnion(), plugins.CONNECTIONRETRY) // Now Mandatory
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.GetOnion(), event.Created: event.True}))
}

@ -40,6 +40,10 @@ func (zone Zone) ConstructZonedPath(path string) ZonedPath {
return ZonedPath(string(zone) + Separator + path)
}
func (zp ZonedPath) ToString() string {
return string(zp)
}
// ParseZone takes in an untyped string and returns an explicit Zone along with the rest of the untyped path
func ParseZone(path string) (Zone, string) {
parts := strings.SplitN(path, Separator, 2)

Loading…
Cancel
Save