Retrieve workflow asset, package or packages
The discoveryUrl param tells us to retrieve from a remote instance.
For this case We retrieve the discovery package list on the server to avoid browser CORS complications.
512253
@Override
    @Path("/{package}/{asset}")
    @ApiOperation(value="Retrieve an asset, an asset package, or all the asset packages",
        response=PackageList.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name="discoveryUrls", paramType="query", dataType="array"),
        @ApiImplicitParam(name="branch", paramType="query", dataType="string"),
        @ApiImplicitParam(name="discoveryType", paramType="query", dataType="string"),
        @ApiImplicitParam(name="groupId", paramType="query", dataType="string"),
        @ApiImplicitParam(name="archiveDirs", paramType="query", dataType="string")})
    public JSONObject get(String path, Map<String,String> headers) throws ServiceException, JSONException {

        try {
            AssetServices assetServices = ServiceLocator.getAssetServices();
            Query query = getQuery(path, headers);
            String discoveryType = query.getFilter("discoveryType");
            if (discoveryType != null) {
                if (!discoveryType.isEmpty() && discoveryType.equals("central")) {
                    String groupId = query.getFilter("groupId");
                    try {
                        Discover discover = new Discover(groupId, true);
                        return discover.run().getPackages();
                    }
                    catch (JSONException e) {
                        throw new ServiceException(ServiceException.INTERNAL_ERROR,
                                "Invalid response from maven central search query", e);
                    }
                }
                else if ("git".equals(discoveryType)){
                    String[] repoUrls = query.getArrayFilter("discoveryUrls");
                    String branch = query.getFilter("branch");
                    if (branch != null)
                        return assetServices.discoverGitAssets(repoUrls[0], branch);
                    else
                        return assetServices.getGitBranches(repoUrls);
                }
            }

            if (query.getBooleanFilter("archiveDirs")) {
                List<ArchiveDir> archiveDirs = assetServices.getArchiveDirs();
                JSONObject json = new JsonObject();
                json.put("root", assetServices.getArchiveDir().getAbsolutePath());
                for (ArchiveDir archiveDir : archiveDirs)
                    json.put(archiveDir.getJsonName(), archiveDir.getJson());
                return json;
            }

            String pkg = getSegment(path, 1);
            String asset = pkg == null ? null : getSegment(path, 2);

            if (pkg == null) {
                if (query.hasFilters()) {
                    return assetServices.getAssetPackageList(query).getJson();
                }
                else {
                    JSONObject json = getPackages(query).getJson();
                    if (assetServices.getArchiveDir().isDirectory())
                        json.put("hasArchive", true);
                    return json;
                }
            }
            else {
                if (asset == null) {
                    return getPackage(pkg).getJson();
                }
                else {
                    return getAssetInfo(pkg + "/" + asset).getJson();
                }
            }
        }
        catch (ServiceException ex) {
            throw ex;
        }
        catch (Exception ex) {
            throw new ServiceException(ex.getMessage(), ex);
        }
    }
898380
async function getPkgReleases({ lookupName, registryUrls }) {
  const versions = [];
  const dependency = getDependencyParts(lookupName);
  if (!is.nonEmptyArray(registryUrls)) {
    logger.error(`No repositories defined for ${dependency.display}`);
    return null;
  }
  const repositories = registryUrls.map(repository =>
    repository.replace(/\/?$/, '/')
  );
  logger.debug(
    `Found ${repositories.length} repositories for ${dependency.display}`
  );
  const repoForVersions = {};
  for (let i = 0; i < repositories.length; i += 1) {
    const repoUrl = repositories[i];
    logger.debug(
      `Looking up ${dependency.display} in repository #${i} - ${repoUrl}`
    );
    const mavenMetadata = await downloadMavenXml(
      dependency,
      repoUrl,
      'maven-metadata.xml'
    );
    if (mavenMetadata) {
      const newVersions = extractVersions(mavenMetadata).filter(
        version => !versions.includes(version)
      );
      const latestVersion = getLatestVersion(newVersions);
      if (latestVersion) {
        repoForVersions[latestVersion] = repoUrl;
      }
      versions.push(...newVersions);
      logger.debug(`Found ${newVersions.length} new versions for ${dependency.display} in repository ${repoUrl}`); // prettier-ignore
    }
  }

  if (versions.length === 0) {
    logger.info(`No versions found for ${dependency.display} in ${repositories.length} repositories`); // prettier-ignore
    return null;
  }
  logger.debug(`Found ${versions.length} versions for ${dependency.display}`);
  const latestVersion = getLatestVersion(versions);
  const repoUrl = repoForVersions[latestVersion];
  const dependencyInfo = await getDependencyInfo(
    dependency,
    repoUrl,
    latestVersion
  );

  return {
    ...dependency,
    ...dependencyInfo,
    releases: versions.map(v => ({ version: v })),
  };
}
351954
def fetch_uri_contents(self, uri: str) -> URI:
        
        address, pkg_name, pkg_version = parse_registry_uri(uri)
        self.w3.enable_unstable_package_management_api()
        self.w3.pm.set_registry(address)
        _, _, manifest_uri = self.w3.pm.get_release_data(pkg_name, pkg_version)
        return manifest_uri
860810
def find_workflow(workflow_name, custom_id)
      params = { ATTR_ID => custom_id, ATTR_NAME => workflow_name }
      params[ATTR_PROG] = PROG
      data = @http.get(instance_website_url(params))['data']
      data && @properties.object_from(
        data['name'],
        @serializer.decode(data['properties'])
      )
    rescue Zenaton::InternalError => exception
      return nil if exception.message =~ /No workflow instance found/
      raise exception
    end
504472
function DiscoveryServerIopaWire(app) {
  if (!app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.Udp])
    throw ("Missing Dependency: UDP Server/Middleware in Pipeline");

  if (!app.properties[SERVER.Capabilities][DEVICESMIDDLEWARE.CAPABILITY])
    throw ("Missing Dependency: IOPA Devices Server/Middleware in Pipeline");

  app.properties[SERVER.Capabilities][THISMIDDLEWARE.CAPABILITY] = {};
  app.properties[SERVER.Capabilities][THISMIDDLEWARE.CAPABILITY][SERVER.Version] = packageVersion;

  //Also register as standard IOPA DISCOVERY SERVER MIDDLEWARE
  app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.DiscoveryServer] = {};
  app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.DiscoveryServer][SERVER.Version] = app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.App][SERVER.Version];

  this.app = app;
  this._devices = {};
  this._factory = new iopa.Factory();
  this._server = null;

  app.device = app.device || {};
  app.device.register = this.register.bind(this, app.device.register || function (device) { return Promise.resolve(device); });
  app.device.unregister = this.register.bind(this, app.device.unregister || function (id) { return Promise.resolve(id); });
}
478821
def package_url(self):
        """"""

        if self.resource_file == DEFAULT_METATAB_FILE or self.target_format in ('txt','ipynb'):
            u = self.inner.clone().clear_fragment()
            u.path = dirname(self.path) + '/'
            u.scheme_extension = 'metapack'
        else:
            u = self

        return MetapackPackageUrl(str(u.clear_fragment()), downloader=self._downloader)
532396
def get_urls(session, name, data, find_changelogs_fn, **kwargs):
    
    # check if there's a changelog in ../custom/pypi/map.txt
    map = get_url_map()
    if name.lower().replace("_", "-") in map:
        logger.info("Package {name}'s URL is in pypi/map.txt, returning".format(name=name))
        return [map[name.lower().replace("_", "-")]], set()
    # if this package has valid meta data, build up a list of URL candidates we can possibly
    # search for changelogs on
    if "info" in data:
        # add all URLs in pypi's meta data:
        # {
        #   "info": {
        #       "home_page":
        #       "docs_url":
        #       "bugtrack_url":
        #   }
        # }
        candidates = [
            url for url in
            [data["info"].get(attr) for attr in ("home_page", "docs_url", "bugtrack_url")]
            if url
        ]
        # the latest release page on pypi might also contain links, add it
        candidates.append("https://pypi.python.org/pypi/{name}/{latest_release}".format(
            name=name,
            latest_release=next(iter(get_releases(data)))
        ))
        # Check the download URL as well.
        if "download_url" in data:
            candidates.append(data["download_url"])
        if data['info']['description']:
            candidates.extend(changelogs.url_re.findall(data["info"]["description"]))
        return find_changelogs_fn(session=session, name=name, candidates=candidates)
    return set(), set()
303249
@Override
    @Path("/packages")
    @ApiOperation(value="Import discovered asset packages", response=StatusMessage.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name="discoveryUrl", paramType="query", dataType="string"),
        @ApiImplicitParam(name="branch", paramType="query", dataType="string"),
        @ApiImplicitParam(name="discoveryType", paramType="query", required=true),
        @ApiImplicitParam(name="groupId", paramType="query", dataType="string"),
        @ApiImplicitParam(name="packages", paramType="body", required=true, dataType="List")})
    public JSONObject put(String path, JSONObject content, Map<String,String> headers)
            throws ServiceException, JSONException {
        Query query = getQuery(path, headers);
        String discoveryType = query.getFilter("discoveryType");
        if (discoveryType == null)
            throw new ServiceException(ServiceException.BAD_REQUEST, "Missing param: discoveryType");
        List<String> pkgs = new JsonArray(content.getJSONArray("packages")).getList();
        Query discQuery = new Query(path);
        discQuery.setArrayFilter("packages", pkgs.toArray(new String[0]));
        File assetRoot = ApplicationContext.getAssetRoot();
        Bulletin bulletin = null;
        try {
            // central discovery
            if (!discoveryType.isEmpty() && discoveryType.equals("central")) {
                String groupId = query.getFilter("groupId");
                if (groupId == null)
                    throw new ServiceException(ServiceException.BAD_REQUEST, "Missing param: groupId");
                bulletin = SystemMessages.bulletinOn("Asset import in progress...");
                Import importer = new Import(groupId, pkgs);
                importer.setAssetLoc(assetRoot.getPath());
                importer.setForce(true);
                importer.run();
                SystemMessages.bulletinOff(bulletin, "Asset import completed");
                bulletin = null;
                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        this.setName("AssetsCacheRefresh-thread");
                        CacheRegistration.getInstance().refreshCaches(null);
                    }
                };
                thread.start();
            }
            else {
                String discoveryUrl = query.getFilter("discoveryUrl");
                if ("https://github.com/CenturyLinkCloud/mdw.git".equals(discoveryUrl)) {
                    Update update = new Update(null);
                    update.setAssetLoc(assetRoot.getPath());
                    update.setBaseAssetPackages(pkgs);
                    update.setMdwVersion(ApplicationContext.getMdwVersion());
                    update.run();
                }
                else {
                    String branch = query.getFilter("branch");
                    if (branch == null)
                        throw new ServiceException(ServiceException.BAD_REQUEST, "Missing param: groupId");
                    File gitLocalPath = new File(PropertyManager.getProperty(PropertyNames.MDW_GIT_LOCAL_PATH));
                    VersionControlGit vcGit = new VersionControlGit();
                    AssetServices assetServices = ServiceLocator.getAssetServices();
                    GitDiscoverer discoverer = assetServices.getDiscoverer(discoveryUrl);
                    discoverer.setRef(branch);
                    String assetPath = discoverer.getAssetPath();
                    if (discoveryUrl.indexOf('?') != -1)
                        discoveryUrl = discoveryUrl.substring(0, discoveryUrl.indexOf('?'));
                    URL url = new URL(discoveryUrl);
                    String[] userInfo = url.getUserInfo().split(":");
                    File test = new File(gitLocalPath.getAbsolutePath()).getParentFile();
                    if (test != null && gitLocalPath.getPath().length() <= 3)
                        test = new File( gitLocalPath.getAbsolutePath()).getParentFile().getParentFile().getParentFile();
                    File tempfile = new File ( test.getAbsolutePath() + "/" + "mdw_git_discovery_" + java.lang.System.currentTimeMillis());
                    vcGit.connect(discoveryUrl, null, null, tempfile);
                    vcGit.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userInfo[0], userInfo[1]));
                    vcGit.cloneBranch(branch);
                    for (String pkg : pkgs) {
                        String pkgPath = pkg.replace(".", "/");
                        String src = tempfile.getAbsolutePath() + "/" + assetPath + "/" + pkgPath;
                        String dest = ApplicationContext.getAssetRoot().getAbsolutePath() + "/" + pkgPath;
                        Files.createDirectories(Paths.get(dest));
                        Files.move(Paths.get(src), Paths.get(dest), StandardCopyOption.REPLACE_EXISTING);
                    }
                    new Delete(tempfile).run();
                }
            }
        }
        catch (Exception ex) {
            SystemMessages.bulletinOff(bulletin, Level.Error, "Asset import failed: " + ex.getMessage());
            throw new ServiceException(ServiceException.INTERNAL_ERROR, ex.getMessage(), ex);
        }

        return null;
    }
1118963
def get_data_urls(deployment_name,
                  endpoint_type='juttle',
                  token_manager=None,
                  app_url=defaults.APP_URL):
    
    deployment_details = deployments.get_deployment_details(deployment_name,
                                                            token_manager=token_manager,
                                                            app_url=app_url)

    # use a random juttle endpoint
    data_urls = []
    for endpoint in deployment_details['endpoints']:
        if endpoint_type in endpoint['type']:
            data_urls.append(endpoint['uri'])

    if len(data_urls) == 0:
        raise JutException('No data engine currently configured for '
                           'deployment "%s"' % deployment_name)

    return data_urls
804864
def retrieve
      raise RetrieverError.new("download retriever is unavailable") unless available?
      ::FileUtils.remove_entry_secure @repo_dir if File.exists?(@repo_dir)
      ::FileUtils.remove_entry_secure workdir if File.exists?(workdir)
      ::FileUtils.mkdir_p @repo_dir
      ::FileUtils.mkdir_p workdir
      file = ::File.join(workdir, "package")

      # TEAL FIX: we have to always-download the tarball before we can
      # determine if contents have changed, but afterward we can compare the
      # previous download against the latest downloaded and short-circuit the
      # remaining flow for the no-difference case.
      @logger.operation(:downloading) do
        credential_command = if @repository.first_credential && @repository.second_credential
          ['-u', "#{@repository.first_credential}:#{@repository.second_credential}"]
        else
          []
        end
        @output = ::RightScale::RightPopen::SafeOutputBuffer.new
        @cmd = [
          'curl',
          '--silent', '--show-error', '--location', '--fail',
          '--location-trusted', '-o', file, credential_command,
          @repository.url
        ].flatten
        begin
          ::RightScale::RightPopen.popen3_sync(
            @cmd,
            :target             => self,
            :pid_handler        => :pid_download,
            :timeout_handler    => :timeout_download,
            :size_limit_handler => :size_limit_download,
            :exit_handler       => :exit_download,
            :stderr_handler     => :output_download,
            :stdout_handler     => :output_download,
            :inherit_io         => true,  # avoid killing any rails connection
            :watch_directory    => workdir,
            :size_limit_bytes   => @max_bytes,
            :timeout_seconds    => @max_seconds)
        rescue Exception => e
          @logger.note_phase(:abort, :running_command, 'curl', e)
          raise
        end
      end

      note_tag(file)

      @logger.operation(:unpacking) do
        path = @repository.to_url.path
        if path =~ /\.gz$/
          extraction = "xzf"
        elsif path =~ /\.bz2$/
          extraction = "xjf"
        else
          extraction = "xf"
        end
        Dir.chdir(@repo_dir) do
          @output = ::RightScale::RightPopen::SafeOutputBuffer.new
          @cmd = ['tar', extraction, file]
          begin
            ::RightScale::RightPopen.popen3_sync(
              @cmd,
              :target             => self,
              :pid_handler        => :pid_download,
              :timeout_handler    => :timeout_download,
              :size_limit_handler => :size_limit_download,
              :exit_handler       => :exit_download,
              :stderr_handler     => :output_download,
              :stdout_handler     => :output_download,
              :inherit_io         => true,  # avoid killing any rails connection
              :watch_directory    => @repo_dir,
              :size_limit_bytes   => @max_bytes,
              :timeout_seconds    => @max_seconds)
          rescue Exception => e
            @logger.note_phase(:abort, :running_command, @cmd.first, e)
            raise
          end
        end
      end
      true
    end
1127705
function DiscoveryClientIopaWire(app) {
  if (!app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.Udp])
    throw ("Missing Dependency: UDP Server/Middleware in Pipeline");
  
  if (!app.properties[SERVER.Capabilities][DEVICESMIDDLEWARE.CAPABILITY])
    throw ("Missing Dependency: IOPA Devices Server/Middleware in Pipeline");

  app.properties[SERVER.Capabilities][THISMIDDLEWARE.CAPABILITY] = {};
  app.properties[SERVER.Capabilities][THISMIDDLEWARE.CAPABILITY][SERVER.Version] = packageVersion;

 //Also register as standard IOPA DISCOVERY CLIENT MIDDLEWARE
  app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.DiscoveryClient] = {};
  app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.DiscoveryClient][SERVER.Version] = app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.App][SERVER.Version];

  this.app = app;
  // this._devices = {};
  this._factory = new iopa.Factory();
 
  app.device = app.device || {};
  app.device.probe = this.probe.bind(this, app.device.probe || function(query, cb){return Promise.resolve(null);});
  app.device.resolve = this.resolve.bind(this, app.device.resolve || function(id, cb){return Promise.resolve(null);});
  
  this._client = null;
 }
512467
def _GetDiscoveryDocFromFlags(args):
    """"""
    if args.discovery_url:
        try:
            return util.FetchDiscoveryDoc(args.discovery_url)
        except exceptions.CommunicationError:
            raise exceptions.GeneratedClientError(
                'Could not fetch discovery doc')

    infile = os.path.expanduser(args.infile) or '/dev/stdin'
    with io.open(infile, encoding='utf8') as f:
        return json.loads(util.ReplaceHomoglyphs(f.read()))
829011
public URL findResourceURL(String resourcePath, String versionRange)
    {
        //if (ClassServiceBootstrap.repositoryAdmin == null)
        //    return null;

        URL url = this.getResourceFromBundle(null, resourcePath, versionRange);

        if (url == null) {
            Object resource = this.deployThisResource(ClassFinderActivator.getPackageName(resourcePath, true), versionRange, false);
            if (resource != null)
            	url = this.getResourceFromBundle(resource, resourcePath, versionRange);
        }

        return url;
    }
952295
function DiscoveryClientSSDP(app) {
  app.properties[SERVER.Capabilities][THISMIDDLEWARE.CAPABILITY] = {};
  app.properties[SERVER.Capabilities][THISMIDDLEWARE.CAPABILITY][SERVER.Version] = packageVersion;

  //Also register as standard IOPA DISCOVERY SERVER MIDDLEWARE
  app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.DiscoveryServer] = {};
  app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.DiscoveryServer][SERVER.Version] = app.properties[SERVER.Capabilities][IOPA.CAPABILITIES.App][SERVER.Version];

  this._seq = 0;
  this._factory = new iopa.Factory();
  this._SSDPserver = null;
  this._SSDPclient = null;
  this._HTTPClient = null;
  
  this.id = app.properties[SERVER.AppId] + ":";
  this.seq = 0;

  app.device = app.device || {};
  app.device.probe = this.probe.bind(this, app.device.probe || function(query, cb){return Promise.resolve(null);});
  
  this.ssdpApp = new iopa.App();
  this.ssdpApp.use(IopaUDP);
  this.ssdpApp.use(IopaSSDP);
  this.ssdpApp.use(IopaCache.Match);
    this.ssdpApp.use(IopaCache.Cache);
 this.ssdpApp.use(IopaMessageLogger);

 
  this.ssdpApp.use(this.invoke.bind(this));
  
}
965037
function discover(callback) {
      if (!callback) return discover.bind(this);
      get("/info/refs?service=git-upload-pack", {
        "Accept": "*/*",
        "Accept-Encoding": "gzip",
        "Pragma": "no-cache"
      }, function (err, code, headers, body) {
        if (err) return callback(err);
        if (code !== 200) return callback(new Error("Unexpected status code " + code));
        if (headers['content-type'] !== 'application/x-git-upload-pack-advertisement') {
          return callback(new Error("Wrong content-type in server response"));
        }

        body = deframer(body);
        if (trace) body = trace("input", body);

        body.read(function (err, line) {
          if (err) return callback(err);
          if (line.trim() !== '# service=git-upload-pack') {
            return callback(new Error("Missing expected service line"));
          }
          body.read(function (err, line) {
            if (err) return callback(err);
            if (line !== null) {
              return callback(new Error("Missing expected terminator"));
            }
            sharedDiscover(body, callback);
          });
        });
      });
    }
889788
def discover(self, transaction):
        
        transaction.response.code = defines.Codes.CONTENT.number
        payload = ""
        for i in self._parent.root.dump():
            if i == "/":
                continue
            resource = self._parent.root[i]
            if resource.visible:
                ret = self.valid(transaction.request.uri_query, resource.attributes)
                if ret:
                    payload += self.corelinkformat(resource)

        transaction.response.payload = payload
        transaction.response.content_type = defines.Content_types["application/link-format"]
        return transaction
374126
def package_url(self):
        """"""
        return MetapackDocumentUrl(str(self.clear_fragment()), downloader=self._downloader).package_url