| 101 | } |
| 102 | |
| 103 | func LookupPoolByID(ctx context.Context, api Interface, id ksuid.KSUID) (*pools.Config, error) { |
| 104 | b := newBuffer(pools.Config{}) |
| 105 | query := fmt.Sprintf("from :pools | id == hex('%s')", idToHex(id)) |
| 106 | q, err := api.Query(ctx, srcfiles.Plain(query)) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | defer q.Pull(true) |
| 111 | if err := vio.Copy(b, q); err != nil { |
| 112 | return nil, err |
| 113 | } |
| 114 | switch len(b.results) { |
| 115 | case 0: |
| 116 | return nil, fmt.Errorf("%s: pool not found", id) |
| 117 | case 1: |
| 118 | pool, ok := b.results[0].(*pools.Config) |
| 119 | if !ok { |
| 120 | return nil, fmt.Errorf("internal error: pool record has wrong type: %T", b.results[0]) |
| 121 | } |
| 122 | return pool, nil |
| 123 | default: |
| 124 | return nil, fmt.Errorf("internal error: multiple pools found with same id: %s", id) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | func LookupBranchByName(ctx context.Context, api Interface, poolName, branchName string) (*db.BranchMeta, error) { |
| 129 | b := newBuffer(db.BranchMeta{}) |