Skip to content

Commit

Permalink
Add playground region (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd authored Apr 26, 2023
1 parent f87ae20 commit 7aed482
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
37 changes: 25 additions & 12 deletions pkg/plugin/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ func iterateRows(input io.Reader, readRowFn func(reader ion.Reader, index int) e

index := 0
for reader.Next() {
if status != nil {
return nil, errors.New("unexpected data after ::final_status annotation")
}

if reader.Type() != ion.StructType {
return nil, fmt.Errorf("expected 'struct' type, got '%s'", reader.Type().String())
}
Expand All @@ -454,7 +458,8 @@ func iterateRows(input io.Reader, readRowFn func(reader ion.Reader, index int) e
}

// Fail on unexpected annotations
if len(annotations) != 0 && (len(annotations) != 1 || annotations[0].Text == nil || *annotations[0].Text != "final_status") {
if len(annotations) != 0 && (len(annotations) != 1 || annotations[0].Text == nil ||
(*annotations[0].Text != "final_status" && *annotations[0].Text != "query_error")) {
labels := make([]string, len(annotations))
for i := range annotations {
if annotations[0].Text != nil {
Expand All @@ -471,18 +476,26 @@ func iterateRows(input io.Reader, readRowFn func(reader ion.Reader, index int) e
return nil, err
}

// Parse ::final_status annotation
if len(annotations) != 0 {
status, err = readFinalStatus(reader)
if len(annotations) == 0 {
// Process data row
err = readRowFn(reader, index)
if err != nil {
return nil, err
}
}

// Process data row
err = readRowFn(reader, index)
if err != nil {
return nil, err
} else {
if *annotations[0].Text != "final_status" {
// Parse ::final_status annotation
status, err = readFinalStatus(reader)
if err != nil {
return nil, err
}
} else {
// Parse ::query_error annotation
status, err = readFinalStatus(reader)
if err != nil {
return nil, err
}
}
}

err = reader.StepOut()
Expand Down Expand Up @@ -531,14 +544,14 @@ func readFinalStatus(reader ion.Reader) (*snellerFinalStatus, error) {
status.Scanned = *value
case "result_set":
// Ignore for now
case "error":
case "error", "error_message":
value, err := reader.StringValue()
if err != nil {
return nil, err
}
status.Error = *value
default:
return nil, fmt.Errorf("unexpected ::final_status field '%s'", name)
return nil, fmt.Errorf("unexpected ::final_status or ::query_error field '%s'", name)
}

}
Expand Down
30 changes: 22 additions & 8 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,36 @@ export function ConfigEditor(props: Props) {
label: 'Europe (Ireland)',
value: 'eu-west-1'
},
{
label: 'Playground',
value: 'play'
},
{
label: 'Custom Endpoint',
value: 'custom',
}
];

const onRegionChange = (value: SelectableValue<string>, actionMeta: ActionMeta) => {
let endpoint = (value.value === 'custom')
? options.jsonData.endpoint
: `https://snellerd-master.${value.value}.sneller-dev.io`
let endpoint = ''
switch (value.value) {
case 'custom':
endpoint = ''
break
case 'play':
endpoint = `https://play.sneller.io`
break
default:
endpoint = `https://snellerd-production.${value.value}.sneller.io`
break
}

const jsonData = {
...options.jsonData,
region: value.value,
endpoint: endpoint,
};

onOptionsChange({ ...options, jsonData });
};

Expand Down Expand Up @@ -86,29 +100,29 @@ export function ConfigEditor(props: Props) {

return (
<div className="gf-form-group">
<InlineField label="Sneller Region" labelWidth={24} tooltip='' grow>
<InlineField label="Sneller Region" labelWidth={24} tooltip='' required grow>
<Select
options={snellerRegions}
onChange={onRegionChange}
value={jsonData.region || 'us-east-1'}
/>
</InlineField>
<InlineField label="Sneller Endpoint" labelWidth={24} tooltip='' disabled={jsonData.region !== 'custom'} required grow>
<InlineField label="Sneller Endpoint" labelWidth={24} tooltip='' disabled={jsonData.region !== 'custom'} required={jsonData.region === 'custom'} grow>
<Input
onChange={onEndpointChange}
value={jsonData.endpoint}
placeholder="The Sneller query endpoint"
required
required={jsonData.region === 'custom'}
/>
</InlineField>
<InlineField label="Sneller Token" labelWidth={24} tooltip='' required grow>
<InlineField label="Sneller Token" labelWidth={24} tooltip='' disabled={jsonData.region === 'play'} required={jsonData.region !== 'play'} grow>
<SecretInput
isConfigured={(secureJsonFields && secureJsonFields.token) as boolean}
value={secureJsonData.token}
placeholder="The Sneller authentication token"
onReset={onResetToken}
onChange={onTokenChange}
required
required={jsonData.region !== 'play'}
/>
</InlineField>
</div>
Expand Down

0 comments on commit 7aed482

Please sign in to comment.