| 59 | } |
| 60 | |
| 61 | func LookupPoolByName(ctx context.Context, api Interface, name string) (*pools.Config, error) { |
| 62 | b := newBuffer(pools.Config{}) |
| 63 | query := fmt.Sprintf("from :pools | name == '%s'", name) |
| 64 | q, err := api.Query(ctx, srcfiles.Plain(query)) |
| 65 | if err != nil { |
| 66 | return nil, err |
| 67 | } |
| 68 | defer q.Pull(true) |
| 69 | if err := vio.Copy(b, q); err != nil { |
| 70 | return nil, err |
| 71 | } |
| 72 | switch len(b.results) { |
| 73 | case 0: |
| 74 | return nil, fmt.Errorf("%q: pool not found", name) |
| 75 | case 1: |
| 76 | pool, ok := b.results[0].(*pools.Config) |
| 77 | if !ok { |
| 78 | return nil, fmt.Errorf("internal error: pool record has wrong type: %T", b.results[0]) |
| 79 | } |
| 80 | return pool, nil |
| 81 | default: |
| 82 | return nil, fmt.Errorf("internal error: multiple pools found with same name: %s", name) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func GetPools(ctx context.Context, api Interface) ([]*pools.Config, error) { |
| 87 | b := newBuffer(pools.Config{}) |