Skip to content

Commit de26bc6

Browse files
committed
Adds a call to fetch the regions
1 parent eb49bcf commit de26bc6

24 files changed

+139
-132
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ _testmain.go
2323
*.test
2424
*.prof
2525

26-
./identity
27-
!./client/identity
26+
27+
2828
/vendor/**
2929
!/vendor/vendor.json
30-
/.wercker
31-
3230
.DS_Store
3331
*.swp
3432

datasource.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"log"
78
"time"
8-
"context"
99

1010
"github.com/davecgh/go-spew/spew"
1111
"github.com/grafana/grafana_plugin_model/go/datasource"
@@ -103,6 +103,8 @@ func (o *OCIDatasource) Query(ctx context.Context, tsdbReq *datasource.Datasourc
103103
return o.dimensionResponse(ctx, tsdbReq)
104104
case "namespaces":
105105
return o.namespaceResponse(ctx, tsdbReq)
106+
case "regions":
107+
return o.regionsResponse(ctx, tsdbReq)
106108
case "search":
107109
return o.searchResponse(ctx, tsdbReq)
108110
case "test":
@@ -452,3 +454,41 @@ func (o *OCIDatasource) queryResponse(ctx context.Context, tsdbReq *datasource.D
452454

453455
return response, nil
454456
}
457+
458+
func (o *OCIDatasource) regionsResponse(ctx context.Context, tsdbReq *datasource.DatasourceRequest) (*datasource.DatasourceResponse, error) {
459+
table := datasource.Table{
460+
Columns: []*datasource.TableColumn{
461+
&datasource.TableColumn{Name: "text"},
462+
},
463+
Rows: make([]*datasource.TableRow, 0),
464+
}
465+
for _, query := range tsdbReq.Queries {
466+
var ts GrafanaOCIRequest
467+
json.Unmarshal([]byte(query.ModelJson), &ts)
468+
res, err := o.identityClient.ListRegions(ctx)
469+
if err != nil {
470+
return nil, errors.Wrap(err, "error fetching regions")
471+
}
472+
rows := make([]*datasource.TableRow, 0, len(res.Items))
473+
o.logger.Debug("successful req", spew.Sdump(res))
474+
for _, item := range res.Items {
475+
rows = append(rows, &datasource.TableRow{
476+
Values: []*datasource.RowValue{
477+
&datasource.RowValue{
478+
Kind: datasource.RowValue_TYPE_STRING,
479+
StringValue: *(item.Name),
480+
},
481+
},
482+
})
483+
}
484+
table.Rows = rows
485+
}
486+
return &datasource.DatasourceResponse{
487+
Results: []*datasource.QueryResult{
488+
&datasource.QueryResult{
489+
RefId: "regions",
490+
Tables: []*datasource.Table{&table},
491+
},
492+
},
493+
}, nil
494+
}

dist/constants.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/constants.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/datasource.js

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

dist/datasource.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/partials/query.editor.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
<div class="gf-form-inline">
77
<div class="gf-form">
88
<label class="gf-form-label query-keyword">Region</label>
9-
<select
10-
class="gf-form-input width-10"
11-
ng-model="ctrl.target.region"
12-
ng-options="o as o for o in ctrl.getRegions()"
13-
on-change="ctrl.onChangeInternal()">
14-
</select>
9+
<div class="gf-form-select-wrapper width-10">
10+
<gf-form-dropdown
11+
model="ctrl.target.region"
12+
get-options="ctrl.getRegions()"
13+
on-change="ctrl.onChangeInternal()">
14+
</gf-form-dropdown>
15+
</div>
1516
<label class="gf-form-label query-keyword width-10">Compartment</label>
1617
<div class="gf-form-select-wrapper width-10">
1718
<gf-form-dropdown model="ctrl.target.compartment"

dist/query_ctrl.js

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

0 commit comments

Comments
 (0)