|
8 | 8 | "fmt" |
9 | 9 | "log/slog" |
10 | 10 | "net/http" |
11 | | - "os" |
12 | 11 |
|
13 | 12 | descriptor "ocm.software/open-component-model/bindings/go/descriptor/runtime" |
14 | 13 | v2 "ocm.software/open-component-model/bindings/go/descriptor/v2" |
@@ -171,42 +170,36 @@ func (r *RepositoryPlugin) AddLocalResource(ctx context.Context, request v1.Post |
171 | 170 | return &resources[0], nil |
172 | 171 | } |
173 | 172 |
|
174 | | -func (r *RepositoryPlugin) GetLocalResource(ctx context.Context, request v1.GetLocalResourceRequest[runtime.Typed], credentials map[string]string) error { |
| 173 | +func (r *RepositoryPlugin) GetLocalResource(ctx context.Context, request v1.GetLocalResourceRequest[runtime.Typed], credentials map[string]string) (v1.GetLocalResourceResponse, error) { |
175 | 174 | var params []plugins.KV |
176 | 175 | addParam := func(k, v string) { |
177 | 176 | params = append(params, plugins.KV{Key: k, Value: v}) |
178 | 177 | } |
179 | 178 | addParam("name", request.Name) |
180 | 179 | addParam("version", request.Version) |
181 | | - addParam("target_location_type", string(request.TargetLocation.LocationType)) |
182 | | - addParam("target_location_value", request.TargetLocation.Value) |
183 | 180 | identityEncoded, err := json.Marshal(request.Identity) |
| 181 | + var response v1.GetLocalResourceResponse |
184 | 182 | if err != nil { |
185 | | - return err |
| 183 | + return response, err |
186 | 184 | } |
187 | 185 | identityBase64 := base64.StdEncoding.EncodeToString(identityEncoded) |
188 | 186 | addParam("identity", identityBase64) |
189 | 187 |
|
190 | 188 | credHeader, err := toCredentials(credentials) |
191 | 189 | if err != nil { |
192 | | - return err |
| 190 | + return response, err |
193 | 191 | } |
194 | 192 |
|
195 | 193 | // We know we only have this single schema for all endpoints which require validation. |
196 | 194 | if err := r.validateEndpoint(request.Repository, r.jsonSchema); err != nil { |
197 | | - return err |
| 195 | + return response, err |
198 | 196 | } |
199 | 197 |
|
200 | | - if err := plugins.Call(ctx, r.client, r.config.Type, r.location, DownloadLocalResource, http.MethodGet, plugins.WithQueryParams(params), plugins.WithHeader(credHeader)); err != nil { |
201 | | - return fmt.Errorf("failed to get local resource %s:%s from %s: %w", request.Name, request.Version, r.ID, err) |
| 198 | + if err := plugins.Call(ctx, r.client, r.config.Type, r.location, DownloadLocalResource, http.MethodGet, plugins.WithQueryParams(params), plugins.WithHeader(credHeader), plugins.WithResult(&response)); err != nil { |
| 199 | + return response, fmt.Errorf("failed to get local resource %s:%s from %s: %w", request.Name, request.Version, r.ID, err) |
202 | 200 | } |
203 | 201 |
|
204 | | - _, err = os.Stat(request.TargetLocation.Value) |
205 | | - if err != nil { |
206 | | - return fmt.Errorf("failed to stat target file: %w", err) |
207 | | - } |
208 | | - |
209 | | - return nil |
| 202 | + return response, nil |
210 | 203 | } |
211 | 204 |
|
212 | 205 | func (r *RepositoryPlugin) GetIdentity(ctx context.Context, typ v1.GetIdentityRequest[runtime.Typed]) (runtime.Identity, error) { |
|
0 commit comments