Skip to content

Commit

Permalink
Merge branch 'with_credentials' of https://github.com/mtanda/grafana
Browse files Browse the repository at this point in the history
…into mtanda-with_credentials
  • Loading branch information
torkelo committed Dec 9, 2015
2 parents 70542fb + cd74297 commit 2dba2f4
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/api/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func GetDataSourceById(c *middleware.Context) Response {
BasicAuth: ds.BasicAuth,
BasicAuthUser: ds.BasicAuthUser,
BasicAuthPassword: ds.BasicAuthPassword,
WithCredentials: ds.WithCredentials,
IsDefault: ds.IsDefault,
JsonData: ds.JsonData,
})
Expand Down
1 change: 1 addition & 0 deletions pkg/api/dtos/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type DataSource struct {
BasicAuth bool `json:"basicAuth"`
BasicAuthUser string `json:"basicAuthUser"`
BasicAuthPassword string `json:"basicAuthPassword"`
WithCredentials bool `json:"withCredentials"`
IsDefault bool `json:"isDefault"`
JsonData map[string]interface{} `json:"jsonData"`
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/frontendsettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
if ds.BasicAuth {
dsMap["basicAuth"] = util.GetBasicAuthHeader(ds.BasicAuthUser, ds.BasicAuthPassword)
}
if ds.WithCredentials {
dsMap["withCredentials"] = ds.WithCredentials
}

if ds.Type == m.DS_INFLUXDB_08 {
dsMap["username"] = ds.User
Expand Down
3 changes: 3 additions & 0 deletions pkg/models/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type DataSource struct {
BasicAuth bool
BasicAuthUser string
BasicAuthPassword string
WithCredentials bool
IsDefault bool
JsonData map[string]interface{}

Expand Down Expand Up @@ -83,6 +84,7 @@ type AddDataSourceCommand struct {
BasicAuth bool `json:"basicAuth"`
BasicAuthUser string `json:"basicAuthUser"`
BasicAuthPassword string `json:"basicAuthPassword"`
WithCredentials bool `json:"withCredentials"`
IsDefault bool `json:"isDefault"`
JsonData map[string]interface{} `json:"jsonData"`

Expand All @@ -103,6 +105,7 @@ type UpdateDataSourceCommand struct {
BasicAuth bool `json:"basicAuth"`
BasicAuthUser string `json:"basicAuthUser"`
BasicAuthPassword string `json:"basicAuthPassword"`
WithCredentials bool `json:"withCredentials"`
IsDefault bool `json:"isDefault"`
JsonData map[string]interface{} `json:"jsonData"`

Expand Down
2 changes: 2 additions & 0 deletions pkg/services/sqlstore/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
BasicAuth: cmd.BasicAuth,
BasicAuthUser: cmd.BasicAuthUser,
BasicAuthPassword: cmd.BasicAuthPassword,
WithCredentials: cmd.WithCredentials,
JsonData: cmd.JsonData,
Updated: time.Now(),
}

sess.UseBool("is_default")
sess.UseBool("basic_auth")
sess.UseBool("with_credentials")

_, err := sess.Where("id=? and org_id=?", ds.Id, ds.OrgId).Update(ds)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/services/sqlstore/migrations/datasource_mig.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ func addDataSourceMigration(mg *Migrator) {
}))

mg.AddMigration("Drop old table data_source_v1 #2", NewDropTableMigration("data_source_v1"))

// add column to activate withCredentials option
mg.AddMigration("Add column with_credentials", NewAddColumnMigration(tableV2, &Column{
Name: "with_credentials", Type: DB_Bool, Nullable: false, Default: "0",
}))
}
4 changes: 4 additions & 0 deletions pkg/services/sqlstore/migrator/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type AddColumnMigration struct {
column *Column
}

func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration {
return &AddColumnMigration{tableName: table.Name, column: col}
}

func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration {
m.tableName = tableName
return m
Expand Down
15 changes: 12 additions & 3 deletions public/app/features/org/partials/datasourceHttpConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h5>Http settings</h5>
</ul>
<div class="clearfix"></div>
</div>
<div class="tight-form last">
<div ng-if="!current.withCredentials" class="tight-form last">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 80px">
Basic Auth
Expand All @@ -40,5 +40,14 @@ <h5>Http settings</h5>
</ul>
<div class="clearfix"></div>
</div>


<div ng-if="!current.basicAuth" class="tight-form last">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 80px">
With Creds
</li>
<li class="tight-form-item">
<editor-checkbox text="Enable" model="current.withCredentials"></editor-checkbox>
</li>
</ul>
<div class="clearfix"></div>
</div>
5 changes: 4 additions & 1 deletion public/app/plugins/datasource/elasticsearch/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
function ElasticDatasource(datasource) {
this.type = 'elasticsearch';
this.basicAuth = datasource.basicAuth;
this.withCredentials = datasource.withCredentials;
this.url = datasource.url;
this.name = datasource.name;
this.index = datasource.index;
Expand All @@ -38,8 +39,10 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
data: data
};

if (this.basicAuth) {
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
if (this.basicAuth) {
options.headers = {
"Authorization": this.basicAuth
};
Expand Down
5 changes: 4 additions & 1 deletion public/app/plugins/datasource/prometheus/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function (angular, _, moment, dateMath) {
this.url = datasource.url;
this.directUrl = datasource.directUrl;
this.basicAuth = datasource.basicAuth;
this.withCredentials = datasource.withCredentials;
this.lastErrors = {};
}

Expand All @@ -32,8 +33,10 @@ function (angular, _, moment, dateMath) {
method: method
};

if (this.basicAuth) {
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
if (this.basicAuth) {
options.headers = {
"Authorization": this.basicAuth
};
Expand Down

0 comments on commit 2dba2f4

Please sign in to comment.