Merge lp:~chipaca/ubuntu-push/appname-from-dbus-path into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 180
Merged at revision: 179
Proposed branch: lp:~chipaca/ubuntu-push/appname-from-dbus-path
Merge into: lp:ubuntu-push/automatic
Diff against target: 281 lines (+44/-70)
6 files modified
bus/endpoint.go (+4/-4)
bus/testing/testing_endpoint_test.go (+1/-1)
client/service/service.go (+19/-25)
client/service/service_test.go (+16/-39)
debian/changelog (+3/-0)
nih/nih.go (+1/-1)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/appname-from-dbus-path
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Review via email: mp+222320@code.launchpad.net

This proposal supersedes a proposal from 2014-06-06.

Commit message

switch dbus api to retrieve appname from dbus path

Description of the change

switch dbus api to retrieve appname from dbus path

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/endpoint.go'
2--- bus/endpoint.go 2014-05-15 11:28:06 +0000
3+++ bus/endpoint.go 2014-06-06 12:20:34 +0000
4@@ -29,7 +29,7 @@
5 * Endpoint (and its implementation)
6 */
7
8-type BusMethod func([]interface{}, []interface{}) ([]interface{}, error)
9+type BusMethod func(string, []interface{}, []interface{}) ([]interface{}, error)
10 type DispatchMap map[string]BusMethod
11
12 // bus.Endpoint represents the DBus connection itself.
13@@ -249,12 +249,12 @@
14 endp.log.Errorf("WatchMethod: unknown method %s", msg.Member)
15 } else {
16 args := msg.AllArgs()
17- rvals, err := meth(args, extra)
18+ rvals, err := meth(string(msg.Path), args, extra)
19 if err != nil {
20 reply = dbus.NewErrorMessage(msg, err_iface, err.Error())
21- endp.log.Errorf("WatchMethod: %s(%#v, %#v) failure: %#v", msg.Member, args, extra, err)
22+ endp.log.Errorf("WatchMethod: %s(%v, %#v, %#v) failure: %#v", msg.Member, msg.Path, args, extra, err)
23 } else {
24- endp.log.Debugf("WatchMethod: %s(%#v, %#v) success: %#v", msg.Member, args, extra, rvals)
25+ endp.log.Debugf("WatchMethod: %s(%v, %#v, %#v) success: %#v", msg.Member, msg.Path, args, extra, rvals)
26 reply = dbus.NewMethodReturnMessage(msg)
27 err = reply.AppendArgs(rvals...)
28 if err != nil {
29
30=== modified file 'bus/testing/testing_endpoint_test.go'
31--- bus/testing/testing_endpoint_test.go 2014-06-02 10:04:34 +0000
32+++ bus/testing/testing_endpoint_test.go 2014-06-06 12:20:34 +0000
33@@ -229,7 +229,7 @@
34 // Test that WatchMethod updates callArgs
35 func (s *TestingEndpointSuite) TestWatchMethodUpdatesCallArgs(c *C) {
36 endp := NewTestingEndpoint(nil, condition.Work(true))
37- foo := func([]interface{}, []interface{}) ([]interface{}, error) { return nil, nil }
38+ foo := func(string, []interface{}, []interface{}) ([]interface{}, error) { return nil, nil }
39 foomp := bus.DispatchMap{"foo": foo}
40 endp.WatchMethod(foomp)
41 c.Check(GetCallArgs(endp), DeepEquals, []callArgs{
42
43=== modified file 'client/service/service.go'
44--- client/service/service.go 2014-05-21 10:03:18 +0000
45+++ client/service/service.go 2014-06-06 12:20:34 +0000
46@@ -21,10 +21,12 @@
47 import (
48 "errors"
49 "os"
50+ "strings"
51 "sync"
52
53 "launchpad.net/ubuntu-push/bus"
54 "launchpad.net/ubuntu-push/logger"
55+ "launchpad.net/ubuntu-push/nih"
56 )
57
58 // Service is the dbus api
59@@ -51,7 +53,7 @@
60 AlreadyStarted = errors.New("already started")
61 BusAddress = bus.Address{
62 Interface: "com.ubuntu.PushNotifications",
63- Path: "/com/ubuntu/PushNotifications",
64+ Path: "/com/ubuntu/PushNotifications/*",
65 Name: "com.ubuntu.PushNotifications",
66 }
67 )
68@@ -133,31 +135,26 @@
69 BadArgType = errors.New("Bad argument type")
70 )
71
72-func (svc *Service) register(args []interface{}, _ []interface{}) ([]interface{}, error) {
73- if len(args) != 1 {
74+func (svc *Service) register(path string, args, _ []interface{}) ([]interface{}, error) {
75+ if len(args) != 0 {
76 return nil, BadArgCount
77 }
78- appname, ok := args[0].(string)
79- if !ok {
80- return nil, BadArgType
81- }
82+ raw_appname := path[strings.LastIndex(path, "/")+1:]
83+ appname := string(nih.Unquote([]byte(raw_appname)))
84
85- rv := os.Getenv("PUSH_REG_" + appname)
86+ rv := os.Getenv("PUSH_REG_" + raw_appname)
87 if rv == "" {
88- rv = "this-is-an-opaque-block-of-random-bits-i-promise"
89+ rv = appname + "::this-is-an-opaque-block-of-random-bits-i-promise"
90 }
91
92 return []interface{}{rv}, nil
93 }
94
95-func (svc *Service) notifications(args []interface{}, _ []interface{}) ([]interface{}, error) {
96- if len(args) != 1 {
97+func (svc *Service) notifications(path string, args, _ []interface{}) ([]interface{}, error) {
98+ if len(args) != 0 {
99 return nil, BadArgCount
100 }
101- appname, ok := args[0].(string)
102- if !ok {
103- return nil, BadArgType
104- }
105+ appname := string(nih.Unquote([]byte(path[strings.LastIndex(path, "/")+1:])))
106
107 svc.lock.Lock()
108 defer svc.lock.Unlock()
109@@ -171,18 +168,15 @@
110 return []interface{}{msgs}, nil
111 }
112
113-func (svc *Service) inject(args []interface{}, _ []interface{}) ([]interface{}, error) {
114- if len(args) != 2 {
115+func (svc *Service) inject(path string, args, _ []interface{}) ([]interface{}, error) {
116+ if len(args) != 1 {
117 return nil, BadArgCount
118 }
119- appname, ok := args[0].(string)
120- if !ok {
121- return nil, BadArgType
122- }
123- notif, ok := args[1].(string)
124- if !ok {
125- return nil, BadArgType
126- }
127+ notif, ok := args[0].(string)
128+ if !ok {
129+ return nil, BadArgType
130+ }
131+ appname := string(nih.Unquote([]byte(path[strings.LastIndex(path, "/")+1:])))
132
133 return nil, svc.Inject(appname, notif)
134 }
135
136=== modified file 'client/service/service_test.go'
137--- client/service/service_test.go 2014-05-21 10:05:24 +0000
138+++ client/service/service_test.go 2014-06-06 12:20:34 +0000
139@@ -97,23 +97,13 @@
140 // registration tests
141
142 func (ss *serviceSuite) TestRegistrationFailsIfBadArgs(c *C) {
143- for i, s := range []struct {
144- args []interface{}
145- errt error
146- }{
147- {nil, BadArgCount}, // no args
148- {[]interface{}{}, BadArgCount}, // still no args
149- {[]interface{}{42}, BadArgType}, // bad arg type
150- {[]interface{}{1, 2}, BadArgCount}, // too many args
151- } {
152- reg, err := new(Service).register(s.args, nil)
153- c.Check(reg, IsNil, Commentf("iteration #%d", i))
154- c.Check(err, Equals, s.errt, Commentf("iteration #%d", i))
155- }
156+ reg, err := new(Service).register("", []interface{}{1}, nil)
157+ c.Check(reg, IsNil)
158+ c.Check(err, Equals, BadArgCount)
159 }
160
161 func (ss *serviceSuite) TestRegistrationWorks(c *C) {
162- reg, err := new(Service).register([]interface{}{"this"}, nil)
163+ reg, err := new(Service).register("/this", nil, nil)
164 c.Assert(reg, HasLen, 1)
165 regs, ok := reg[0].(string)
166 c.Check(ok, Equals, true)
167@@ -125,7 +115,7 @@
168 os.Setenv("PUSH_REG_stuff", "42")
169 defer os.Setenv("PUSH_REG_stuff", "")
170
171- reg, err := new(Service).register([]interface{}{"stuff"}, nil)
172+ reg, err := new(Service).register("/stuff", nil, nil)
173 c.Assert(reg, HasLen, 1)
174 regs, ok := reg[0].(string)
175 c.Check(ok, Equals, true)
176@@ -138,10 +128,10 @@
177
178 func (ss *serviceSuite) TestInjectWorks(c *C) {
179 svc := NewService(ss.bus, ss.log)
180- rvs, err := svc.inject([]interface{}{"hello", "world"}, nil)
181+ rvs, err := svc.inject("/hello", []interface{}{"world"}, nil)
182 c.Assert(err, IsNil)
183 c.Check(rvs, IsNil)
184- rvs, err = svc.inject([]interface{}{"hello", "there"}, nil)
185+ rvs, err = svc.inject("/hello", []interface{}{"there"}, nil)
186 c.Assert(err, IsNil)
187 c.Check(rvs, IsNil)
188 c.Assert(svc.mbox, HasLen, 1)
189@@ -162,7 +152,7 @@
190 condition.Work(false))
191 svc := NewService(bus, ss.log)
192 svc.SetMessageHandler(func([]byte) error { return errors.New("fail") })
193- _, err := svc.inject([]interface{}{"hello", "xyzzy"}, nil)
194+ _, err := svc.inject("/hello", []interface{}{"xyzzy"}, nil)
195 c.Check(err, NotNil)
196 }
197
198@@ -173,13 +163,10 @@
199 }{
200 {nil, BadArgCount},
201 {[]interface{}{}, BadArgCount},
202- {[]interface{}{1}, BadArgCount},
203- {[]interface{}{1, 2}, BadArgType},
204- {[]interface{}{"1", 2}, BadArgType},
205- {[]interface{}{1, "2"}, BadArgType},
206- {[]interface{}{1, 2, 3}, BadArgCount},
207+ {[]interface{}{1}, BadArgType},
208+ {[]interface{}{1, 2}, BadArgCount},
209 } {
210- reg, err := new(Service).inject(s.args, nil)
211+ reg, err := new(Service).inject("", s.args, nil)
212 c.Check(reg, IsNil, Commentf("iteration #%d", i))
213 c.Check(err, Equals, s.errt, Commentf("iteration #%d", i))
214 }
215@@ -189,7 +176,7 @@
216 // Notifications tests
217 func (ss *serviceSuite) TestNotificationsWorks(c *C) {
218 svc := NewService(ss.bus, ss.log)
219- nots, err := svc.notifications([]interface{}{"hello"}, nil)
220+ nots, err := svc.notifications("/hello", nil, nil)
221 c.Assert(err, IsNil)
222 c.Assert(nots, NotNil)
223 c.Assert(nots, HasLen, 1)
224@@ -198,7 +185,7 @@
225 svc.mbox = make(map[string][]string)
226 }
227 svc.mbox["hello"] = append(svc.mbox["hello"], "this", "thing")
228- nots, err = svc.notifications([]interface{}{"hello"}, nil)
229+ nots, err = svc.notifications("/hello", nil, nil)
230 c.Assert(err, IsNil)
231 c.Assert(nots, NotNil)
232 c.Assert(nots, HasLen, 1)
233@@ -206,19 +193,9 @@
234 }
235
236 func (ss *serviceSuite) TestNotificationsFailsIfBadArgs(c *C) {
237- for i, s := range []struct {
238- args []interface{}
239- errt error
240- }{
241- {nil, BadArgCount}, // no args
242- {[]interface{}{}, BadArgCount}, // still no args
243- {[]interface{}{42}, BadArgType}, // bad arg type
244- {[]interface{}{1, 2}, BadArgCount}, // too many args
245- } {
246- reg, err := new(Service).notifications(s.args, nil)
247- c.Check(reg, IsNil, Commentf("iteration #%d", i))
248- c.Check(err, Equals, s.errt, Commentf("iteration #%d", i))
249- }
250+ reg, err := new(Service).notifications("/foo", []interface{}{1}, nil)
251+ c.Check(reg, IsNil)
252+ c.Check(err, Equals, BadArgCount)
253 }
254
255 func (ss *serviceSuite) TestMessageHandler(c *C) {
256
257=== modified file 'debian/changelog'
258--- debian/changelog 2014-06-06 11:20:41 +0000
259+++ debian/changelog 2014-06-06 12:20:34 +0000
260@@ -7,6 +7,9 @@
261 [ Roberto Alsina ]
262 * Make signing-helper generate a HTTP header instead of a querystring.
263
264+ [ John R. Lenton ]
265+ * Switch dbus api to retrieve app name from dbus path.
266+
267 -- John R. Lenton <john.lenton@canonical.com> Fri, 06 Jun 2014 12:02:56 +0100
268
269 ubuntu-push (0.3+14.10.20140605-0ubuntu1) utopic; urgency=medium
270
271=== modified file 'nih/nih.go'
272--- nih/nih.go 2014-05-23 12:56:27 +0000
273+++ nih/nih.go 2014-06-06 12:20:34 +0000
274@@ -45,7 +45,7 @@
275 return out
276 }
277
278-// Quote() takes a byte slice and undoes the damage done to it by the quoting.
279+// Unquote() takes a byte slice and undoes the damage done to it by Quote().
280 func Unquote(s []byte) []byte {
281 out := make([]byte, 0, len(s))
282

Subscribers

People subscribed via source and target branches