Skip to content

Commit

Permalink
API key and cluster ID string stripping (#84)
Browse files Browse the repository at this point in the history
* Trim API key and Cluster ID in config to avoid users adding whitespace.

Signed-off-by: Taras Priadka <[email protected]>

* Add string trimming on backend.

Signed-off-by: Taras Priadka <[email protected]>
  • Loading branch information
TarasPriadka authored Jul 19, 2022
1 parent 9596acb commit 0b300bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/pixie_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
Expand Down Expand Up @@ -70,6 +71,9 @@ func (td *PixieDatasource) QueryData(ctx context.Context, req *backend.QueryData

// Creates Pixie API client using API key and cloud Address
func createClient(ctx context.Context, apiKey string, cloudAddr string) (*pxapi.Client, error) {
// untrimmed apiKey string will cause an error when creating a client
apiKey = strings.TrimSpace(apiKey)

var client *pxapi.Client
var err error
// First, create a client connecting to Pixie Cloud.
Expand Down Expand Up @@ -169,6 +173,9 @@ func (td *PixieDatasource) query(ctx context.Context, query backend.DataQuery,
clusterID = qm.QueryBody.ClusterID
}

// untrimmed clusterID string will cause an error when creating a vizier client
clusterID = strings.TrimSpace(clusterID)

if qm.QueryType != GetClusters && (len(qm.QueryBody.ClusterID) == 0 && clusterID == "") {
return nil, fmt.Errorf("no clusterID present in the request or default clusterID configured. Please set `pixieCluster` dashboard variable to `Pixie Datasource`->`Clusters`")
}
Expand Down
2 changes: 1 addition & 1 deletion src/config_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
<SecretFormField
isConfigured={(secureJsonFields && secureJsonFields.clusterId) as boolean}
value={secureJsonData.clusterId || ''}
label="Cluster ID"
label="Default Cluster ID"
placeholder="Default Cluster ID"
labelWidth={20}
inputWidth={20}
Expand Down

0 comments on commit 0b300bb

Please sign in to comment.