/
storage.go
773 lines (677 loc) · 21.7 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
package v1
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"strings"
"facette.io/facette/storage"
"facette.io/facette/template"
"facette.io/httputil"
"facette.io/jsonutil"
"facette.io/sliceutil"
"facette.io/sqlstorage"
"github.com/hashicorp/go-uuid"
"github.com/vbatoufflet/httprouter"
)
var storageTypes = []string{
"providers",
"collections",
"graphs",
"sourcegroups",
"metricgroups",
}
// api:method POST /api/v1/library/:type "Create a library item"
//
// This endpoint creates a new item and stores it to the storage database.
//
// The `inherit` query parameter can be used to inherit fields from an existing item, then applying new values with
// received body payload.
//
// If the instance is *read-only* the operation will be rejected with `403 Forbidden`.
//
// ---
// section: library
// parameters:
// - name: type
// type: string
// description: type of library items
// required: true
// in: path
// - name: inherit
// type: string
// description: identifier of the item to inherit from
// in: query
// responses:
// 201:
func (a *API) storageCreate(rw http.ResponseWriter, r *http.Request) {
if a.config.HTTP.ReadOnly {
httputil.WriteJSON(rw, newMessage(errReadOnly), http.StatusForbidden)
return
}
typ := httprouter.ContextParam(r, "type").(string)
// Initialize new storage item
item, ok := a.storageItem(typ)
if !ok {
rw.WriteHeader(http.StatusNotFound)
return
}
// Retrieve existing item data from storage if inheriting
rv := reflect.ValueOf(item)
if id := httprouter.QueryParam(r, "inherit"); id != "" {
if err := a.storage.SQL().Get("id", id, rv.Interface(), false); err == sqlstorage.ErrItemNotFound {
httputil.WriteJSON(rw, newMessage(err), http.StatusNotFound)
return
} else if err != nil {
a.logger.Error("failed to fetch item for deletion: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
for _, name := range []string{"ID", "Created", "Modifed", "Alias"} {
if f := reflect.Indirect(rv).FieldByName(name); f.IsValid() {
f.Set(reflect.Zero(f.Type()))
}
}
}
// Fill item with data received from request
if err := httputil.BindJSON(r, rv.Interface()); err == httputil.ErrInvalidContentType {
httputil.WriteJSON(rw, newMessage(err), http.StatusUnsupportedMediaType)
return
} else if err != nil {
a.logger.Error("unable to unmarshal JSON data: %s", err)
httputil.WriteJSON(rw, newMessage(errInvalidJSON), http.StatusBadRequest)
return
}
// Parse body for template keys potential errors
if typ == "collections" || typ == "graphs" {
if reflect.Indirect(rv).FieldByName("Template").Bool() {
data, _ := json.Marshal(rv.Interface())
if _, err := template.Parse(string(data)); err != nil {
a.logger.Error("failed to parse template: %s", err)
httputil.WriteJSON(rw, newMessage(template.ErrInvalidTemplate), http.StatusBadRequest)
return
}
}
}
// Set provider enabled by default
if typ == "providers" {
reflect.Indirect(rv).FieldByName("Enabled").SetBool(true)
}
// Insert item into storage
if err := a.storage.SQL().Save(rv.Interface()); err != nil {
switch err {
case sqlstorage.ErrItemConflict:
httputil.WriteJSON(rw, newMessage(err), http.StatusConflict)
case storage.ErrInvalidAlias, storage.ErrInvalidID, storage.ErrInvalidName, storage.ErrInvalidPattern,
sqlstorage.ErrMissingField, sqlstorage.ErrUnknownReference:
httputil.WriteJSON(rw, newMessage(err), http.StatusBadRequest)
default:
a.logger.Error("failed to insert item: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
}
return
}
id := reflect.Indirect(rv).FieldByName("ID").String()
a.logger.Debug("inserted %q item into storage", id)
// Start new provider upon creation
if typ == "providers" {
go a.poller.StartWorker(rv.Interface().(*storage.Provider))
}
http.Redirect(rw, r, strings.TrimRight(r.URL.Path, "/")+"/"+id, http.StatusCreated)
}
// api:method GET /api/v1/library/:type/:id "Get a library item"
//
// This endpoint returns a library item given its type and identifier.
//
// The `expand` query parameter _(available for collections and graphs)_ can be set to request item expansion. If the
// item is an instance of a template, all internal references will be resolved.
//
// ---
// section: library
// parameters:
// - name: type
// type: string
// description: type of library items
// required: true
// in: path
// - name: id
// type: string
// description: identifier of the item
// required: true
// in: path
// - name: expand
// type: boolean
// description: item expansion flag
// in: query
// responses:
// 200:
// type: object
// examples:
// - format: javascript
// body: |
// {
// "id": "eccd09c3-aaa9-592b-ad55-3d92b4acf119",
// "name": "load",
// "description": "Load average for \"{{ .source }}\"",
// "created": "2017-05-19T15:08:39Z",
// "modified": "2017-06-14T06:17:46Z",
// "groups": [
// {
// "name": "",
// "operator": 0,
// "consolidate": 1,
// "series": [
// {
// "name": "shortterm",
// "origin": "{{ .origin }}",
// "source": "{{ .source }}",
// "metric": "load.shortterm",
// "options": {
// "color": "#fff726"
// }
// }
// ]
// },
// {
// "name": "",
// "operator": 0,
// "consolidate": 1,
// "series": [
// {
// "name": "midterm",
// "origin": "{{ .origin }}",
// "source": "{{ .source }}",
// "metric": "load.midterm",
// "options": {
// "color": "#ff602a"
// }
// }
// ]
// },
// {
// "name": "",
// "operator": 0,
// "consolidate": 1,
// "series": [
// {
// "name": "longterm",
// "origin": "{{ .origin }}",
// "source": "{{ .source }}",
// "metric": "load.longterm",
// "options": {
// "color": "#be1732"
// }
// }
// ]
// }
// ],
// "options": {
// "title": "{{ .source }} - Load Average",
// "type": "line",
// "yaxis_unit": "fixed"
// },
// "template": true
// }
func (a *API) storageGet(rw http.ResponseWriter, r *http.Request) {
var result interface{}
typ := httprouter.ContextParam(r, "type").(string)
id := httprouter.ContextParam(r, "id").(string)
// Initialize new storage item
item, ok := a.storageItem(typ)
if !ok {
rw.WriteHeader(http.StatusNotFound)
return
}
// Check for aliased item if identifier value isn't valid
column := "id"
if typ == "collections" || typ == "graphs" {
if _, err := uuid.ParseUUID(id); err != nil {
column = "alias"
}
}
// Request item from storage
rv := reflect.ValueOf(item)
if err := a.storage.SQL().Get(column, id, rv.Interface(), true); err == sqlstorage.ErrItemNotFound {
httputil.WriteJSON(rw, newMessage(err), http.StatusNotFound)
return
} else if err != nil {
a.logger.Error("failed to fetch item: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
// Handle collection expansion request
if parseBoolParam(r, "expand") {
if typ == "collections" {
c := rv.Interface().(*storage.Collection)
c.Expand(nil)
} else if typ == "graphs" {
g := rv.Interface().(*storage.Graph)
g.Expand(nil)
}
}
if fields := parseListParam(r, "fields", nil); fields != nil {
result = jsonutil.FilterStruct(rv.Interface(), fields)
} else {
result = rv.Interface()
}
httputil.WriteJSON(rw, result, http.StatusOK)
}
// api:method PUT /api/v1/library/:type/:id "Update a library item"
//
// This endpoint updates a library item given its identifier. The request body is similar to the _Create a new library
// item_ endpoint.
//
// If the instance is *read-only* the operation will be rejected with `403 Forbidden`.
//
// ---
// section: library
// parameters:
// - name: type
// type: string
// description: type of library items
// required: true
// in: path
// - name: id
// type: string
// description: identifier of the item
// required: true
// in: path
// responses:
// 204:
// api:method PATCH /api/v1/library/:type/:id "Partially update a library item"
//
// This endpoint partially updates a library item given its identifier. The request body is similar to the _Update a
// library item_ endpoint, but only specified fields will be modified.
//
// If the instance is *read-only* the operation will be rejected with `403 Forbidden`.
//
// ---
// section: library
// parameters:
// - name: id
// type: string
// description: identifier of the provider
// required: true
// in: path
// responses:
// 204:
func (a *API) storageUpdate(rw http.ResponseWriter, r *http.Request) {
if a.config.HTTP.ReadOnly {
httputil.WriteJSON(rw, newMessage(errReadOnly), http.StatusForbidden)
return
}
typ := httprouter.ContextParam(r, "type").(string)
id := httprouter.ContextParam(r, "id").(string)
// Initialize new storage item
item, ok := a.storageItem(typ)
if !ok {
rw.WriteHeader(http.StatusNotFound)
return
}
// Retrieve existing item data from storage if patching
rv := reflect.ValueOf(item)
if r.Method == "PATCH" {
if err := a.storage.SQL().Get("id", id, rv.Interface(), true); err == sqlstorage.ErrItemNotFound {
httputil.WriteJSON(rw, newMessage(err), http.StatusNotFound)
return
} else if err != nil {
a.logger.Error("failed to fetch item for deletion: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
} else {
reflect.Indirect(rv).FieldByName("ID").SetString(id)
}
// Fill item with data received from request
if err := httputil.BindJSON(r, rv.Interface()); err == httputil.ErrInvalidContentType {
httputil.WriteJSON(rw, newMessage(err), http.StatusUnsupportedMediaType)
return
} else if err != nil {
a.logger.Error("unable to unmarshal JSON data: %s", err)
httputil.WriteJSON(rw, newMessage(errInvalidJSON), http.StatusBadRequest)
return
}
// Parse body for template keys potential errors
if typ == "collections" || typ == "graphs" {
if reflect.Indirect(rv).FieldByName("Template").Bool() {
data, _ := json.Marshal(rv.Interface())
if _, err := template.Parse(string(data)); err != nil {
a.logger.Error("failed to parse template: %s", err)
httputil.WriteJSON(rw, newMessage(template.ErrInvalidTemplate), http.StatusBadRequest)
return
}
}
}
// Update item in storage
if err := a.storage.SQL().Save(rv.Interface()); err != nil {
switch err {
case sqlstorage.ErrItemConflict:
httputil.WriteJSON(rw, newMessage(err), http.StatusConflict)
case storage.ErrInvalidAlias, storage.ErrInvalidID, storage.ErrInvalidName, storage.ErrInvalidPattern,
sqlstorage.ErrMissingField, sqlstorage.ErrUnknownReference:
httputil.WriteJSON(rw, newMessage(err), http.StatusBadRequest)
default:
a.logger.Error("failed to update item: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
}
return
}
a.logger.Debug("updated %s item from storage", id)
// Restart provider on update
if typ == "providers" {
if err := a.storage.SQL().Get("id", id, rv.Interface(), false); err == nil {
go a.poller.StopWorker(rv.Interface().(*storage.Provider), true)
}
}
rw.WriteHeader(http.StatusNoContent)
}
// api:method DELETE /api/v1/library/:type/:id "Delete a library item"
//
// This endpoint deletes a library item given its type and identifier.
//
// If the instance is *read-only* the operation will be rejected with `403 Forbidden`.
//
// ---
// section: library
// parameters:
// - name: type
// type: string
// description: type of library items
// required: true
// in: path
// - name: id
// type: string
// description: identifier of the item
// required: true
// in: path
// responses:
// 204:
func (a *API) storageDelete(rw http.ResponseWriter, r *http.Request) {
if a.config.HTTP.ReadOnly {
httputil.WriteJSON(rw, newMessage(errReadOnly), http.StatusForbidden)
return
}
typ := httprouter.ContextParam(r, "type").(string)
id := httprouter.ContextParam(r, "id").(string)
// Initialize new storage item
item, ok := a.storageItem(typ)
if !ok {
rw.WriteHeader(http.StatusNotFound)
return
}
// Request item from storage
rv := reflect.ValueOf(item)
if err := a.storage.SQL().Get("id", id, rv.Interface(), false); err == sqlstorage.ErrItemNotFound {
httputil.WriteJSON(rw, newMessage(err), http.StatusNotFound)
return
} else if err != nil {
a.logger.Error("failed to fetch item for deletion: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
// Delete item from storage
err := a.storage.SQL().Delete(rv.Interface())
if err == sqlstorage.ErrItemNotFound {
httputil.WriteJSON(rw, newMessage(err), http.StatusNotFound)
return
} else if err != nil {
a.logger.Error("failed to delete item: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
a.logger.Debug("deleted %s item from storage", id)
// Stop provider upon deletion
if typ == "providers" {
go a.poller.StopWorker(rv.Interface().(*storage.Provider), false)
}
rw.WriteHeader(http.StatusNoContent)
}
// api:method DELETE /api/v1/library/:type "Delete library items of a given type"
//
// This endpoint deletes all items of a given type.
//
// If the request header `X-Confirm-Action` is not present or if the instance is *read-only* the operation will be
// rejected with `403 Forbidden`.
//
// ---
// section: library
// parameters:
// - name: type
// type: string
// description: type of library items
// required: true
// in: path
// responses:
// 204:
func (a *API) storageDeleteAll(rw http.ResponseWriter, r *http.Request) {
var rv reflect.Value
if a.config.HTTP.ReadOnly {
httputil.WriteJSON(rw, newMessage(errReadOnly), http.StatusForbidden)
return
}
typ := httprouter.ContextParam(r, "type").(string)
// Initialize new storage item
item, ok := a.storageItem(typ)
if !ok {
rw.WriteHeader(http.StatusNotFound)
return
}
// Check for confirmation header
if r.Header.Get("X-Confirm-Action") != "1" {
rw.WriteHeader(http.StatusForbidden)
return
}
// Request items list from storage
if typ == "providers" {
rv = reflect.New(reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(item)), 0, 0).Type())
_, err := a.storage.SQL().List(rv.Interface(), nil, nil, 0, 0, false)
if err == sqlstorage.ErrUnknownColumn {
httputil.WriteJSON(rw, newMessage(err), http.StatusBadRequest)
return
} else if err != nil {
a.logger.Error("failed to fetch items for deletion: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
}
a.storage.SQL().Delete(reflect.ValueOf(item).Interface())
a.logger.Debug("deleted %s from storage", typ)
// Stop provider upon deletion
if typ == "providers" {
for i, n := 0, reflect.Indirect(rv).Len(); i < n; i++ {
go a.poller.StopWorker(reflect.Indirect(rv).Index(i).Interface().(*storage.Provider), false)
}
}
rw.WriteHeader(http.StatusNoContent)
}
// api:method GET /api/v1/library/:type "List library items of a given type"
//
// This endpoint returns library items of a given type. If a `filter` query parameter is given, only items having
// their name matching the filter will be returned.
//
// This endpoint supports pagination through the `offset` and `limit` query parameters and sorting using `sort` query
// parameter (separated by commas; prefix field name with "-" to reverse sort order).
//
// The `kind` query parameter _(available for collections and graphs)_ can be set in order to target or exclude
// templates from result:
//
// * `all`: return all kind of items (default)
// * `raw`: only return raw items, thus removing templates from result
// * `template`: only return templates
//
// The `link` parameter _(available for collection and graphs)_ can be set in order to only return items having the
// given item as template reference.
//
// The `parent` query parameter _(only available for collections)_ can be set in order to only return items having the
// given collection for parent.
//
// ---
// section: library
// parameters:
// - name: type
// type: string
// description: type of library items
// required: true
// in: path
// - name: filter
// type: string
// description: term to filter names on
// in: query
// - name: sort
// type: string
// description: fields to sort results on
// in: query
// - name: offset
// type: integer
// description: offset to return items from
// in: query
// - name: limit
// type: integer
// description: number of items to return
// in: query
// - name: kind
// type: string
// description: kind of item to return
// in: query
// - name: link
// type: string
// description: identifier of the linked item
// in: query
// - name: parent
// type: string
// description: identifier of the parent item
// in: query
// responses:
// 200:
// type: array
// examples:
// - format: javascript
// headers:
// X-Total-Records: 3
// body: |
// [
// {
// "created": "2017-05-19T15:08:40Z",
// "description": "CPU usage for \"{{ .source }}\"",
// "id": "c1c5ba71-428a-565e-94e3-304c16e9a92f",
// "modified": "2017-06-14T06:17:46Z",
// "name": "cpu"
// },
// {
// "created": "2017-05-19T15:08:39Z",
// "description": "Disk usage for \"{{ .volume }}\" on \"{{ .source }}\"",
// "id": "c77c2dae-b37f-5210-80b5-5d44ce5f7a97",
// "modified": "2017-06-14T06:17:46Z",
// "name": "df.bytes"
// },
// {
// "created": "2017-05-19T15:08:39Z",
// "description": "Load average for \"{{ .source }}\"",
// "id": "eccd09c3-aaa9-592b-ad55-3d92b4acf119",
// "modified": "2017-06-14T06:17:46Z",
// "name": "load"
// }
// ]
func (a *API) storageList(rw http.ResponseWriter, r *http.Request) {
typ := httprouter.ContextParam(r, "type").(string)
// Initialize new storage item
item, ok := a.storageItem(typ)
if !ok {
rw.WriteHeader(http.StatusNotFound)
return
}
// Check for list filter
filters := make(map[string]interface{})
if v := httprouter.QueryParam(r, "filter"); v != "" {
filters["name"] = applyModifier(v)
}
if typ == "collections" || typ == "graphs" {
switch httprouter.QueryParam(r, "kind") {
case "raw":
filters["template"] = false
case "template":
filters["template"] = true
case "all", "":
// no filtering
default:
httputil.WriteJSON(rw, newMessage(errInvalidParameter), http.StatusBadRequest)
return
}
if v := httprouter.QueryParam(r, "link"); v != "" {
filters["link"] = v
}
if typ == "collections" {
if v := httprouter.QueryParam(r, "parent"); v != "" {
filters["parent"] = v
}
}
}
// Request items list from storage
rv := reflect.New(reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(item)), 0, 0).Type())
offset, err := parseIntParam(r, "offset")
if err != nil || offset < 0 {
httputil.WriteJSON(rw, newMessage(errInvalidParameter), http.StatusBadRequest)
return
}
limit, err := parseIntParam(r, "limit")
if err != nil || limit < 0 {
httputil.WriteJSON(rw, newMessage(errInvalidParameter), http.StatusBadRequest)
return
}
sort := parseListParam(r, "sort", []string{"name"})
count, err := a.storage.SQL().List(rv.Interface(), filters, sort, offset, limit, true)
if err == sqlstorage.ErrUnknownColumn {
httputil.WriteJSON(rw, newMessage(err), http.StatusBadRequest)
return
} else if err != nil {
a.logger.Error("failed to fetch items: %s", err)
httputil.WriteJSON(rw, newMessage(errUnhandledError), http.StatusInternalServerError)
return
}
// Parse requested fields list or set defaults
fields := parseListParam(r, "fields", nil)
if fields == nil {
fields = []string{"id", "name", "description", "created", "modified"}
if typ == "providers" {
fields = append(fields, "enabled", "error")
}
}
// Fill items list
result := []map[string]interface{}{}
for i, n := 0, reflect.Indirect(rv).Len(); i < n; i++ {
var entry map[string]interface{}
if typ == "collections" && parseBoolParam(r, "expand") {
collection := reflect.Indirect(rv).Index(i).Interface().(*storage.Collection)
collection.Expand(nil)
entry = jsonutil.FilterStruct(collection, fields)
} else {
entry = jsonutil.FilterStruct(reflect.Indirect(rv).Index(i).Interface(), fields)
}
if typ == "providers" && sliceutil.Has(fields, "error") {
err := a.poller.WorkerError(reflect.Indirect(rv).Index(i).Elem().FieldByName("ID").String())
if err != nil {
entry["error"] = err.Error()
} else {
entry["error"] = nil
}
}
result = append(result, entry)
}
rw.Header().Set("X-Total-Records", fmt.Sprintf("%d", count))
httputil.WriteJSON(rw, result, http.StatusOK)
}
func (a *API) storageItem(typ string) (interface{}, bool) {
switch typ {
case "providers":
return a.storage.NewProvider(), true
case "collections":
return a.storage.NewCollection(), true
case "graphs":
return a.storage.NewGraph(), true
case "sourcegroups":
return a.storage.NewSourceGroup(), true
case "metricgroups":
return a.storage.NewMetricGroup(), true
}
return nil, false
}