GOCli check provider region (#15474)

## Summary
- add CLI command `CHECK PROVIDER 'provider_name' REGION 'region_name'
KEY 'api_key';`
  - route the command through CLI parser and command dispatcher
- call `GET /api/v1/providers/:provider_name/connection` with `region`
and `api_key`

  ## Testing
  - `go test ./internal/cli/...`
  - manually verified CLI command parsing and request flow
This commit is contained in:
Hz_
2026-06-02 19:34:25 +08:00
committed by GitHub
parent 5f8926410d
commit 9799f33549
3 changed files with 133 additions and 0 deletions

View File

@@ -3118,6 +3118,17 @@ func (p *Parser) parseModelParseCommand() (*Command, error) {
func (p *Parser) parseCheckCommand() (*Command, error) {
p.nextToken() // consume CHECK
switch p.curToken.Type {
case TokenInstance:
return p.parseCheckInstanceCommand()
case TokenProvider:
return p.parseCheckProviderByKeyCommand()
default:
return nil, fmt.Errorf("expected INSTANCE or PROVIDER after CHECK")
}
}
func (p *Parser) parseCheckInstanceCommand() (*Command, error) {
if p.curToken.Type != TokenInstance {
return nil, fmt.Errorf("expected INSTANCE after CHECK")
}
@@ -3151,6 +3162,68 @@ func (p *Parser) parseCheckCommand() (*Command, error) {
return cmd, nil
}
func (p *Parser) parseCheckProviderByKeyCommand() (*Command, error) {
if p.curToken.Type != TokenProvider {
return nil, fmt.Errorf("expected PROVIDER after CHECK")
}
p.nextToken()
if p.curToken.Type != TokenQuotedString {
return nil, fmt.Errorf("expected provider name after PROVIDER")
}
providerName := p.curToken.Value
p.nextToken()
if p.curToken.Type != TokenRegion {
return nil, fmt.Errorf("expected REGION after provider name")
}
p.nextToken()
if p.curToken.Type != TokenQuotedString {
return nil, fmt.Errorf("expected region name after REGION")
}
regionName := p.curToken.Value
p.nextToken()
if p.curToken.Type != TokenKey {
return nil, fmt.Errorf("expected KEY after region name")
}
p.nextToken()
if p.curToken.Type != TokenQuotedString {
return nil, fmt.Errorf("expected API key after KEY")
}
apiKey := p.curToken.Value
p.nextToken()
baseURL := ""
if p.curToken.Type == TokenURL {
p.nextToken()
if p.curToken.Type != TokenQuotedString {
return nil, fmt.Errorf("expected base URL after URL")
}
baseURL = p.curToken.Value
p.nextToken()
}
if p.curToken.Type == TokenSemicolon {
p.nextToken()
}
if p.curToken.Type != TokenEOF {
return nil, fmt.Errorf("unexpected token: %s", p.curToken.Value)
}
cmd := NewCommand("check_provider_with_key")
cmd.Params["provider_name"] = providerName
cmd.Params["region"] = regionName
cmd.Params["api_key"] = apiKey
if baseURL != "" {
cmd.Params["base_url"] = baseURL
}
return cmd, nil
}
func (p *Parser) parseUseCommand() (*Command, error) {
p.nextToken() // consume USE