Skip to content

Add a project method to Images #405

Open
@Temikus

Description

@Temikus

See:

 # This attribute is not available in the representation of an
        # 'image' returned by the GCE server (see GCE API). However,
        # images are a global resource and a user can query for images
        # across projects. Therefore we try to remember which project
        # the image belongs to by tracking it in this attribute.
        attribute :project
def get(identity, project = nil)
          if project
            image = service.get_image(identity, project).to_h
            image[:project] = project
            return new(image)
          elsif identity
            project.nil? ? projects = all_projects : projects = [project]
            projects.each do |proj|
              begin
                response = service.get_image(identity, proj).to_h
                # TODO: Remove this - see #405
                response[:project] = proj
                image = response
                return new(image)
              rescue ::Google::Apis::ClientError => e
                next if e.status_code == 404
                break
              else
                break
              end
            end
            # If nothing is found - return nil
            nil
          end
        end

This is really not optimal. This information is already available in self_link and we should just add an object method instead of mixing it in during get request.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions