1717#include "parson/parson.h"
1818#include "str-replace/str-replace.h"
1919#include "version.h"
20+ #include <clib-secrets.h>
2021#include <curl/curl.h>
2122#include <libgen.h>
2223#include <limits.h>
24+ #include <registry-manager.h>
25+ #include <repository.h>
2326#include <stdio.h>
2427#include <stdlib.h>
2528#include <string.h>
@@ -251,21 +254,6 @@ static int install_package(const char *slug) {
251254 long path_max = 4096 ;
252255#endif
253256
254- if (!root_package ) {
255- const char * name = NULL ;
256- char * json = NULL ;
257- unsigned int i = 0 ;
258-
259- do {
260- name = manifest_names [i ];
261- json = fs_read (name );
262- } while (NULL != manifest_names [++ i ] && !json );
263-
264- if (json ) {
265- root_package = clib_package_new (json , opts .verbose );
266- }
267- }
268-
269257 if ('.' == slug [0 ]) {
270258 if (1 == strlen (slug ) || ('/' == slug [1 ] && 2 == strlen (slug ))) {
271259 char dir [path_max ];
@@ -291,10 +279,21 @@ static int install_package(const char *slug) {
291279 }
292280 }
293281
294- if (!pkg ) {
295- pkg = clib_package_new_from_slug (slug , opts .verbose );
282+ // Read local config files.
283+ clib_secrets_t secrets = clib_secrets_load_from_file ("clib_secrets.json" );
284+ repository_init (secrets ); // The repository requires the secrets for authentication.
285+ clib_package_t * package = clib_package_load_local_manifest (0 );
286+
287+ registries_t registries = registry_manager_init_registries (package -> registries , secrets );
288+ registry_manager_fetch_registries (registries );
289+ registry_package_ptr_t package_info = registry_manger_find_package (registries , slug );
290+ if (!package_info ) {
291+ debug (& debugger , "Package %s not found in any registry." , slug );
292+ return -1 ;
296293 }
297294
295+
296+ pkg = clib_package_new_from_slug_and_url (slug , registry_package_get_href (package_info ), opts .verbose );
298297 if (NULL == pkg )
299298 return -1 ;
300299
@@ -437,6 +436,21 @@ int main(int argc, char *argv[]) {
437436
438437 clib_package_set_opts (package_opts );
439438
439+ if (!root_package ) {
440+ const char * name = NULL ;
441+ char * json = NULL ;
442+ unsigned int i = 0 ;
443+
444+ do {
445+ name = manifest_names [i ];
446+ json = fs_read (name );
447+ } while (NULL != manifest_names [++ i ] && !json );
448+
449+ if (json ) {
450+ root_package = clib_package_new (json , opts .verbose );
451+ }
452+ }
453+
440454 int code = 0 == program .argc ? install_local_packages ()
441455 : install_packages (program .argc , program .argv );
442456
0 commit comments