Skip to content

Commit f2a6183

Browse files
committed
Improve admin API
1 parent 37c91bd commit f2a6183

7 files changed

Lines changed: 162 additions & 94 deletions

File tree

Gopkg.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mfgen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
//go:generate go-bindata -o templates.go -prefix ../manifest_templates ../manifest_templates/
1212

13-
const PackageVersion = "4.13.0"
13+
const PackageVersion = "4.14.1"
1414

1515
func main() {
1616
app := cli.NewApp()

tools/admincliserver/adminapi/adminapi.go

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,19 @@ func (a *apiProvider) ManifestAdd(ctx context.Context, p *ManifestAddParams) (*M
152152
},
153153
}, nil
154154
}
155+
if p.Deviceid == "" {
156+
return &ManifestAddResponse{
157+
Stat: &Status{
158+
Code: bte.InvalidParameter,
159+
Msg: "Device ID may not be empty",
160+
},
161+
}, nil
162+
}
155163
metadata := make(map[string]string)
156164
for _, kv := range p.Metadata {
157165
metadata[kv.Key] = kv.Value
158166
}
159-
dev := &manifest.ManifestDevice{Descriptor: p.Deviceid, Metadata: metadata, Streams: make(map[string]*manifest.ManifestDeviceStream)}
160-
success, err := manifest.UpsertManifestDeviceAtomically(ctx, a.ec, dev)
167+
md, err := manifest.RetrieveManifestDevice(ctx, a.ec, p.Deviceid)
161168
if err != nil {
162169
return &ManifestAddResponse{
163170
Stat: &Status{
@@ -166,15 +173,25 @@ func (a *apiProvider) ManifestAdd(ctx context.Context, p *ManifestAddParams) (*M
166173
},
167174
}, nil
168175
}
169-
if !success {
176+
if md != nil {
170177
return &ManifestAddResponse{
171178
Stat: &Status{
172179
Code: bte.ManifestDeviceDuplicated,
173180
Msg: err.Error(),
174181
},
175182
}, nil
176183
}
177-
return &ManifestAddResponse{}, nil
184+
dev := &manifest.ManifestDevice{Descriptor: p.Deviceid, Metadata: metadata, Streams: make(map[string]*manifest.ManifestDeviceStream)}
185+
err = manifest.UpsertManifestDevice(ctx, a.ec, dev)
186+
if err != nil {
187+
return &ManifestAddResponse{
188+
Stat: &Status{
189+
Code: bte.ManifestError,
190+
Msg: err.Error(),
191+
},
192+
}, nil
193+
}
194+
return &ManifestAddResponse{Deviceid: p.Deviceid}, nil
178195
}
179196

180197
func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*ManifestDelResponse, error) {
@@ -187,7 +204,7 @@ func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*M
187204
},
188205
}, nil
189206
}
190-
err := manifest.DeleteManifestDevice(ctx, a.ec, p.Deviceid)
207+
md, err := manifest.RetrieveManifestDevice(ctx, a.ec, p.Deviceid)
191208
if err != nil {
192209
return &ManifestDelResponse{
193210
Stat: &Status{
@@ -196,7 +213,24 @@ func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*M
196213
},
197214
}, nil
198215
}
199-
return &ManifestDelResponse{}, nil
216+
if md == nil {
217+
return &ManifestDelResponse{
218+
Stat: &Status{
219+
Code: bte.ManifestDeviceDoesntExist,
220+
Msg: "No device exists with that deviceid",
221+
},
222+
}, nil
223+
}
224+
err = manifest.DeleteManifestDevice(ctx, a.ec, p.Deviceid)
225+
if err != nil {
226+
return &ManifestDelResponse{
227+
Stat: &Status{
228+
Code: bte.ManifestError,
229+
Msg: err.Error(),
230+
},
231+
}, nil
232+
}
233+
return &ManifestDelResponse{Deviceid: p.Deviceid}, nil
200234
}
201235

202236
func (a *apiProvider) ManifestDelPrefix(ctx context.Context, p *ManifestDelPrefixParams) (*ManifestDelPrefixResponse, error) {
@@ -218,6 +252,14 @@ func (a *apiProvider) ManifestDelPrefix(ctx context.Context, p *ManifestDelPrefi
218252
},
219253
}, nil
220254
}
255+
if n == 0 {
256+
return &ManifestDelPrefixResponse{
257+
Stat: &Status{
258+
Code: bte.ManifestDeviceDoesntExist,
259+
Msg: "No devices exist with this device id pattern",
260+
},
261+
}, nil
262+
}
221263
return &ManifestDelPrefixResponse{
222264
Numdeleted: uint32(n),
223265
}, nil

0 commit comments

Comments
 (0)