Build a sanitized, authenticated metadata hash for the given request

 @param [Hash] metadata A base metadata hash to build from
 @return [Hash] The compiled metadata hash that is ready to be transported over the wire
173455
def build_metadata(metadata = {})
      unless opts[:password].empty?
        username = opts.fetch(:username, 'grpc').to_s
        username = username.empty? ? '' : "#{username}:"
        auth_string = Base64.encode64("#{username}#{opts[:password]}")
        metadata[:authorization] = "Basic #{auth_string}".tr("\n", '')
      end
      metadata
    end
1198411
def build_http_request(klass, path, params = nil, body = nil)
      path += '?' + URI.encode_www_form(params) unless params.nil?
      req = klass.new(path)
      req.body = URI.encode_www_form(body) unless body.nil?
      Etcd::Log.debug("Built #{klass} path:'#{path}'  body:'#{req.body}'")
      req
    end
898322
def generated_metadata_json_readonly
      @logger.operation(:metadata_readonly) do
        # path constants
        freed_metadata_dir = (@cookbook.pos == '.' && freed_dir) || ::File.join(freed_dir, @cookbook.pos)
        freed_metadata_json_path = ::File.join(freed_metadata_dir, JSON_METADATA)

        # in the multi-pass case we will run this scanner only on the second
        # and any subsequent passed, which are outside of containment. the
        # metadata must have already been generated at this point or else it
        # should be considered an internal error.
        return ::File.read(freed_metadata_json_path)
      end
    end
793349
private ObjectMetadata toObjectMetadataEO(ObjectMetadata metadata) {
        // If we generated a symmetric key to encrypt the data, store it in the
        // object metadata.
        byte[] encryptedCEK = getEncryptedCEK();
        metadata.addUserMetadata(Headers.CRYPTO_KEY,
                                 Base64.encodeAsString(encryptedCEK));
        // Put the cipher initialization vector (IV) into the object metadata
        byte[] iv = cipherLite.getIV();
        metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv));
        // Put the materials description into the object metadata as JSON
        metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION,
                                 kekMaterialDescAsJson());
        return metadata;
    }
1143063
def query_metadata_agent(path)
      url = "#{@metadata_agent_url}/#{path}"
      @log.debug("Calling Metadata Agent: #{url}")
      open(url) do |f|
        response = f.read
        parsed_hash = parse_json_or_nil(response)
        if parsed_hash.nil?
          @log.error 'Response from Metadata Agent is not in valid json ' \
                     "format: '#{response.inspect}'."
          return nil
        end
        @log.debug "Response from Metadata Agent: #{parsed_hash}"
        return parsed_hash
      end
    rescue StandardError => e
      @log.error "Error calling Metadata Agent at #{url}.", error: e
      nil
    end
1199603
def _build_cache_key(request):
        
        str_hash = md5(
            (request.method + request.url + str(request.params) + str(request.data) + str(request.json)).encode(
                'utf-8')).hexdigest()
        return 'esi_%s' % str_hash
1007668
def generate_checksum(did, metadata):
        
        files_checksum = ''
        for file in metadata['base']['files']:
            if 'checksum' in file:
                files_checksum = files_checksum + file['checksum']
        return hashlib.sha3_256((files_checksum +
                                 metadata['base']['name'] +
                                 metadata['base']['author'] +
                                 metadata['base']['license'] +
                                 did).encode('UTF-8')).hexdigest()
621655
def as_json(options={})
      options = @options.merge(options)

      if options[:root]
        { options[:root].to_sym => serializable_hash }.merge(meta_hash).merge(data_hash)
      else
        serializable_hash
      end
    end
1126906
def prepare_params(params)
      # Create a new hash in case is a HashWithIndifferentAccess (keys are
      # always a String)
      params = Utils.symbolize_keys(Hash[params])
      # Only pull out the relevant parameters, other won't be included in the
      # signature so will cause false negatives
      keys = [:resource_id, :resource_type, :resource_uri, :state, :signature]
      params = Hash[params.select { |k,v| keys.include? k }]
      (keys - [:state]).each do |key|
        raise ArgumentError, "Parameters missing #{key}" if !params.key?(key)
      end
      params
    end
181751
def get_metadata(address=None, tx_hash=None, block_hash=None, api_key=None, private=True, coin_symbol='btc'):
    '''
    
    '''
    assert is_valid_coin_symbol(coin_symbol), coin_symbol
    assert api_key or not private, 'Cannot see private metadata without an API key'

    kwarg = get_valid_metadata_identifier(
        coin_symbol=coin_symbol,
        address=address,
        tx_hash=tx_hash,
        block_hash=block_hash,
        )

    url = make_url(coin_symbol, meta=True, **kwarg)

    params = {'token': api_key} if api_key else {'private': 'true'}

    r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    response_dict = get_valid_json(r)

    return response_dict
107665
def inspect_to_metadata(metadata_object, inspect_data):
    
    identifier = graceful_get(inspect_data, 'Id')
    if identifier:
        if ":" in identifier:
            # format of image name from docker inspect:
            # sha256:8f0e66c924c0c169352de487a3c2463d82da24e9442fc097dddaa5f800df7129
            metadata_object.identifier = identifier.split(':')[1]
        else:
            # container
            metadata_object.identifier = identifier

    # format of Environment Variables from docker inspect:
    # ['DISTTAG=f26container', 'FGC=f26']
    raw_env_vars = graceful_get(inspect_data, "Config", "Env") or []
    if raw_env_vars:
        metadata_object.env_variables = {}
        for env_variable in raw_env_vars:
            splits = env_variable.split("=", 1)
            name = splits[0]
            value = splits[1] if len(splits) > 1 else None
            if value is not None:
                metadata_object.env_variables.update({name: value})

    raw_exposed_ports = graceful_get(inspect_data, "Config", "ExposedPorts")
    if raw_exposed_ports:
        metadata_object.exposed_ports = list(raw_exposed_ports.keys())

    # specific to images
    raw_repo_tags = graceful_get(inspect_data, 'RepoTags')
    if raw_repo_tags:
        metadata_object.name = raw_repo_tags[0]
    metadata_object.labels = graceful_get(inspect_data, 'Config', 'Labels')
    metadata_object.command = graceful_get(inspect_data, 'Config', 'Cmd')
    metadata_object.creation_timestamp = inspect_data.get('Created', None)
    # specific to images
    metadata_object.image_names = inspect_data.get('RepoTags', None)
    # specific to images
    digests = inspect_data.get("RepoDigests", None)
    if digests:
        metadata_object.repo_digests = digests
        metadata_object.digest = digests[0]

    return metadata_object
1332431
def read
      @metadata = {}
      @content = File.read(path)

      if @content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
        @content = $POSTMATCH

        begin
          @metadata = YAML.load($1)
          raise unless @metadata.is_a? Hash
        rescue => ex
          $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{ex.to_s}"
          $stderr.puts "WARNING: Couldn't load metadata."
          @metadata = {}
        end

        @metadata.symbolize_keys!
        import_metadata
      end
    end
1045680
def encode_to_hash(resource, *args)
      if id = get_resource_identifier(resource)
        cache_key = "#{resource.class.name}:#{id}"
        cache[cache_key] ||= _encode_to_hash(resource, *args)
      else
        _encode_to_hash(resource, *args)
      end
    end
1115840
@VisibleForTesting
  static Map<String, byte[]> decodeMetadata(Map<String, String> metadata) {
    return Maps.transformValues(metadata, DECODE_METADATA_VALUES);
  }
1159695
def get_metadata(ident_hash):
    
    id, version = get_id_n_version(ident_hash)

    stmt = _get_sql('get-metadata.sql')
    args = dict(id=id, version=version)

    # FIXME The license_url and license_text metadata attributes need to
    # change to a License structure similar to what is used in cnx-authoring.

    with db_connect() as db_conn:
        with db_conn.cursor() as cursor:
            cursor.execute(stmt, args)
            try:
                metadata = cursor.fetchone()[0]
            except TypeError:
                raise NotFound(ident_hash)
    return metadata
1082671
def from_metadata(cls, metadata: Dict[str, Any]) -> 'LogFields':
        
        return cls(fields=json.loads(metadata.get(LOG_FIELDS_KEY_META, '{}')))
952480
def expanded
            h = Hash.new
            [:id, :email, :api_key, :name, :phone, :password,:states, :approval, :suspend,
            :registration_ip_address, :dates, :some_msg].each do |setting|
                if grouped = self.send("#{setting}").is_a?(Hash)
                    self.send("#{setting}").each {|k,v|   h[k.to_sym] = v}
                else
                    h[setting] = self.send("#{setting}")
                end
            end
            h
        end