MCPcopy Create free account
hub / github.com/docker/cli / getByID

Method getByID

cli/context/store/metadatastore.go:71–97  ·  view source on GitHub ↗
(id contextdir)

Source from the content-addressed store, hash-verified

69}
70
71func (s *metadataStore) getByID(id contextdir) (Metadata, error) {
72 fileName := filepath.Join(s.contextDir(id), metaFile)
73 bytes, err := os.ReadFile(fileName)
74 if err != nil {
75 if errors.Is(err, os.ErrNotExist) {
76 return Metadata{}, notFound(fmt.Errorf("context not found: %w", err))
77 }
78 return Metadata{}, err
79 }
80 var untyped untypedContextMetadata
81 r := Metadata{
82 Endpoints: make(map[string]any),
83 }
84 if err := json.Unmarshal(bytes, &untyped); err != nil {
85 return Metadata{}, fmt.Errorf("parsing %s: %v", fileName, err)
86 }
87 r.Name = untyped.Name
88 if r.Metadata, err = parseTypedOrMap(untyped.Metadata, s.config.contextType); err != nil {
89 return Metadata{}, fmt.Errorf("parsing %s: %v", fileName, err)
90 }
91 for k, v := range untyped.Endpoints {
92 if r.Endpoints[k], err = parseTypedOrMap(v, s.config.endpointTypes[k]); err != nil {
93 return Metadata{}, fmt.Errorf("parsing %s: %v", fileName, err)
94 }
95 }
96 return r, err
97}
98
99func (s *metadataStore) remove(name string) error {
100 if err := os.RemoveAll(s.contextDir(contextdirOf(name))); err != nil {

Callers 2

getMethod · 0.95
listMethod · 0.95

Calls 3

contextDirMethod · 0.95
parseTypedOrMapFunction · 0.85
notFoundFunction · 0.70

Tested by

no test coverage detected