cloud_controller/spec/support/cloud_spec_helpers.rb
# Generate a handy header Hash.
# At minimum it requires a User or email as the first argument.
# Optionally, you can pass a second User or email which will be the 'proxy user'.
# Finally, if you pass a String or Hash as the third argument, it will be
# JSON-ized and used as the request body.
Generate a handy header Hash.
At minimum it requires a User or email as the first argument.
Optionally, you can pass a second User or email which will be the 'proxy user'.
Finally, if you pass a String or Hash as the third argument, it will be
JSON-ized and used as the request body.
Generate a handy header Hash . At minimum it requires a User or email as the first argument . Optionally you can pass a second User or email which will be the ' proxy user ' . Finally if you pass a String or Hash as the third argument it will be JSON - ized and used as the request body .
def headers_for(user, proxy_user = nil, raw_data = nil, https = false)
    headers = {}
    if user
      email = User === user ? user.email : user.to_s
      if @@use_jwt_token
        token_body = {"resource_ids" => ["cloud_controller"], "foo" => "bar", "email" => email}
        token_coder = CF::UAA::TokenCoder.new(AppConfig[:uaa][:resource_id],
                                              AppConfig[:uaa][:token_secret])
        token = token_coder.encode(token_body)
        AppConfig[:uaa][:enabled] = true
        headers['HTTP_AUTHORIZATION'] = "bearer #{token}"
      else
        AppConfig[:uaa][:enabled] = false
        headers['HTTP_AUTHORIZATION'] = UserToken.create(email).encode
      end
    end
    if proxy_user
      proxy_email = User === proxy_user ? proxy_user.email : proxy_user.to_s
      headers['HTTP_PROXY_USER'] = proxy_email
    end
    if raw_data
      unless String === raw_data
        raw_data = Yajl::Encoder.encode(raw_data)
      end
      headers['RAW_POST_DATA'] = raw_data
    end
    headers['X-Forwarded_Proto'] = "https" if https
    headers
  end
def headers_for ( user , proxy_user = nil , raw_data = nil , https = false ) headers = { } if user email = User === user ? user . email : user . to_s if @@use_jwt_token token_body = { "resource_ids" => [ "cloud_controller" ] , "foo" => "bar" , "email" => email } token_coder = CF :: UAA :: TokenCoder . new ( AppConfig [ :uaa ] [ :resource_id ] , AppConfig [ :uaa ] [ :token_secret ] ) token = token_coder . encode ( token_body ) AppConfig [ :uaa ] [ :enabled ] = true headers [ 'HTTP_AUTHORIZATION' ] = "bearer #{token}" else AppConfig [ :uaa ] [ :enabled ] = false headers [ 'HTTP_AUTHORIZATION' ] = UserToken . create ( email ) . encode end end if proxy_user proxy_email = User === proxy_user ? proxy_user . email : proxy_user . to_s headers [ 'HTTP_PROXY_USER' ] = proxy_email end if raw_data unless String === raw_data raw_data = Yajl :: Encoder . encode ( raw_data ) end headers [ 'RAW_POST_DATA' ] = raw_data end headers [ 'X-Forwarded_Proto' ] = "https" if https headers end
Generate a handy header Hash.
Generate a handy header Hash .
user
proxy_user
raw_data
https