|
| 1 | +// Copyright 2016 The Linux Foundation |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +// Package refs implements generic name-based reference access. |
| 16 | +package refs |
| 17 | + |
| 18 | +import ( |
| 19 | + "github.com/opencontainers/image-spec/specs-go" |
| 20 | + "golang.org/x/net/context" |
| 21 | +) |
| 22 | + |
| 23 | +// ListNameCallback templates an Engine.List callback used for |
| 24 | +// processing names. See Engine.List for more details. |
| 25 | +type ListNameCallback func(ctx context.Context, name string) (err error) |
| 26 | + |
| 27 | +// Engine represents a name-based reference storage engine. |
| 28 | +type Engine interface { |
| 29 | + |
| 30 | + // Put adds a new reference to the store. The action is idempotent; |
| 31 | + // a nil return means "that descriptor is stored at NAME" without |
| 32 | + // implying "because of your Put()". |
| 33 | + Put(ctx context.Context, name string, descriptor *specs.Descriptor) (err error) |
| 34 | + |
| 35 | + // Get returns a reference from the store. Returns os.ErrNotExist |
| 36 | + // if the name is not found. |
| 37 | + Get(ctx context.Context, name string) (descriptor *specs.Descriptor, err error) |
| 38 | + |
| 39 | + // List returns available names from the store. |
| 40 | + // |
| 41 | + // Results are sorted alphabetically. |
| 42 | + // |
| 43 | + // Arguments: |
| 44 | + // |
| 45 | + // * ctx: gives callers a way to gracefully cancel a long-running |
| 46 | + // list. |
| 47 | + // * prefix: limits the result set to names starting with that |
| 48 | + // value. |
| 49 | + // * size: limits the length of the result set to the first 'size' |
| 50 | + // matches. A value of -1 means "all results". |
| 51 | + // * from: shifts the result set to start from the 'from'th match. |
| 52 | + // * nameCallback: called for every matching name. List returns any |
| 53 | + // errors returned by nameCallback and aborts further listing. |
| 54 | + // |
| 55 | + // For example, a store with names like: |
| 56 | + // |
| 57 | + // * 123 |
| 58 | + // * abcd |
| 59 | + // * abce |
| 60 | + // * abcf |
| 61 | + // * abcg |
| 62 | + // |
| 63 | + // will have the following call/result pairs: |
| 64 | + // |
| 65 | + // * List(ctx, "", -1, 0, printName) -> "123", "abcd", "abce", "abcf", "abcg" |
| 66 | + // * List(ctx, "", 2, 0, printName) -> "123", "abcd" |
| 67 | + // * List(ctx, "", 2, 1, printName) -> "abcd", "abce" |
| 68 | + // * List(ctx,"abc", 2, 1, printName) -> "abce", "abcf" |
| 69 | + List(ctx context.Context, prefix string, size int, from int, nameCallback ListNameCallback) (err error) |
| 70 | + |
| 71 | + // Delete removes a reference from the store. Returns |
| 72 | + // os.ErrNotExist if the name is not found. |
| 73 | + Delete(ctx context.Context, name string) (err error) |
| 74 | + |
| 75 | + // Close releases resources held by the engine. Subsequent engine |
| 76 | + // method calls will fail. |
| 77 | + Close() (err error) |
| 78 | +} |
0 commit comments