Looked at this for initial solutions. However, the file I want to reference in my rails project is in a private file. When I perform the following code:
uri = URI("https://.../config.yml")
file = Net::HTTP.get(uri)
config = YAML.load(file)
The 'file' has the contents of the sign-in page of github. Is it possible to pass credentials to access this private repo's file? Additionally, is this safe to do?
CodePudding user response:
You have to set the credentials via a header. Something like this should work
token = "123"
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Token #{token}"
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
Otherwise I also suggest to just use the Github client library Octokit.