Skip to content

Vision API should not require project #966

Description

@gguuss

When trying to run the Cloud Vision API sample from Ruby for the first time, I encountered the following error:

bundle exec ruby vision_samples.rb labels images/cat.jpg 
/usr/local/google/home/class/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/google-cloud-vision-   0.20.2/lib/google-cloud-vision.rb:106:in `vision': project is missing (ArgumentError)
from /usr/local/google/home/class/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/google-cloud-   vision-0.20.2/lib/google-cloud-vision.rb:63:in `vision'
from vision_samples.rb:25:in `detect_labels'
from vision_samples.rb:120:in `<main>'

To resolve the issue, I commented out lines in the file google-cloud-vision-0.20.2/lib/google-cloud-vision.rb client library:

def self.vision project = nil, keyfile = nil, scope: nil, retries: nil,     
                timeout: nil                                                
  require "google/cloud/vision"                                             
  #project ||= Google::Cloud::Vision::Project.default_project               
  #project = project.to_s # Always cast to a string                         
  #fail ArgumentError, "project is missing" if project.empty? 

After commenting out the files, the sample worked, indicating that the project name was not important for what I was doing. Curious to find out whether project was necessary here, I grepped around within the project to see if we ever are using this required parameter:

google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:require "google/cloud/vision/project"
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:    # provide the project and credential information to connect to the Cloud
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:    # Use {Vision::Project#image} to create images for the Cloud Vision service.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:    # {Vision::Project#annotate}, below.)
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:    # (or a string file path or Storage URI) to {Vision::Project#annotate}: 
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # is used on {Project#annotate} as well as {Image#faces}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # This is used on {Project#annotate} as well as {Image#landmarks}.      
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # used on {Project#annotate} as well as {Image#logos}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # is used on {Project#annotate} as well as {Image#labels}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:        # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb:      # See {Project#annotate}.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb:        def initialize project
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb:          @project = project
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb:        # See {Project#annotate} for requests that do not involve multiple      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb:          Image.from_source source, @project
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb:        attr_accessor :project
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb:        def initialize project, credentials, retries: nil, timeout: nil
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb:          @project = project
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb:          "#{self.class}(#{@project})"
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation.rb:      # See {Project#annotate} and {Image}.
google-cloud-vision-0.20.2/lib/google/cloud/vision/image.rb:      # See {Project#image}.
google-cloud-vision-0.20.2/lib/google/cloud/vision/image.rb:        # Raise an error unless an active vision project object is available.   
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:      # # Project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:      class Project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        # @private Creates a new Project instance.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        # The Vision project connected to.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        #   gcloud = Google::Cloud.new "my-todo-project",
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        #   vision.project #=> "my-todo-project"
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        def project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:          service.project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        # @private Default project.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:        def self.default_project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:          ENV["VISION_PROJECT"] ||
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:            ENV["GOOGLE_CLOUD_PROJECT"] ||
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:            ENV["GCLOUD_PROJECT"] ||
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb:            Google::Cloud::Core::GCE.project_id
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:          # mirror projections typical of photos. So `face.features.eyes.left`    
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb:            # image, without considering mirror projections typical of photos.      
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:    # @return [Google::Cloud::Vision::Project]
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:      Google::Cloud.vision @project, @keyfile, scope: scope,
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:    # @param [String] project Project identifier for the Vision service you are
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:    # @return [Google::Cloud::Vision::Project]
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:    def self.vision project = nil, keyfile = nil, scope: nil, retries: nil, 
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:      project ||= Google::Cloud::Vision::Project.default_project
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:      project = project.to_s # Always cast to a string
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:      fail ArgumentError, "project is missing" if project.empty?
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:      Google::Cloud::Vision::Project.new(
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb:          project, credentials, retries: retries, timeout: timeout))

As far as I can tell, the project field is not being used anywhere and is not required for this API.

As such, I'm proposing either we update the client library to not exit and instead warn the user if the project name is not specified or we should never use the project field in this client library.

Additionally, in other cases where the client library requires the project but it is unused, we should remove the project name requirement.

Activity

  1. blowmage commented on Oct 11, 2016

    @blowmage
    Contributor

    I believe we do need project. #869 requests project_id is sent in the headers (until the GRPC library provides a mechanism to do so).

  2. gguuss commented on Oct 11, 2016

    @gguuss
    Author

    If we do require a project, then why does commenting out the project fields resolve the issue?

    To resolve the issue, I commented out lines in the file google-cloud-vision-0.20.2/lib/google-cloud-vision.rb client library:

  3. quartzmo commented on Oct 13, 2016

    @quartzmo
    Member

    @gguuss How are you authenticating? With an API key? Can you paste in any relevant client code in vision_samples.rb? (Keeping auth details hidden, of course.)

  4. added a commit that references this issue on Oct 14, 2016
    59a31f1
  5. gguuss commented on Oct 14, 2016

    @gguuss
    Author

    I'm authenticating using default application credentials from the gcloud tool. All of the relevant code is from the Ruby Vision sample and is completely unchanged.

    The client library does not seem to correctly detect the project name so explicitly setting it on the path is necessary using export GOOGLE_CLOUD_PROJECT="ANY_STRING_WORKS".

  6. blowmage commented on Oct 15, 2016

    @blowmage
    Contributor

    The project_id is now being used and sent in an HTTP header and so this issue is closed. The larger discussion about retrieving the project_id from the gcloud SDK credentials should continue on #951.

  7. quartzmo commented on Oct 15, 2016

    @quartzmo
    Member

    @gguuss Is it ok to close this issue given that a solution for #951 will automate setting the project name when authenticating with the gcloud tool and using the application default credentials? It's not quite the same as not requiring the project, so I want to be sure you are ok with the difference.

  8. gguuss commented on Oct 15, 2016

    @gguuss
    Author

    Thanks @quartzmo @blowmage - I'm all for closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: visionIssues related to the Cloud Vision API.auth

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions