module GraphQL::RakeTask::Validate
Helpers for graphql:pro:validate. Credentials are never passed to a subprocess, so they can’t leak into the process list or logs.
Constants
- CREDENTIALS_PATTERN
- DIGEST_PATTERN
Public Instance Methods
Source
# File lib/graphql/rake_task/validate.rb, line 31 def credentials creds = if defined?(Bundler) && Bundler.respond_to?(:settings) Bundler.settings["gems.graphql.pro"] end if creds.nil? # Array form doesn't use a shell, and no secrets are in the arguments output = IO.popen(["bundle", "config", "get", "gems.graphql.pro", "--parseable"], err: File::NULL, &:read) creds = output[/[a-z0-9]{11}:[a-z0-9]{11}/] end creds = creds&.strip creds && creds.match?(CREDENTIALS_PATTERN) ? creds : nil rescue SystemCallError nil end
Returns user:pass for gems.graphql.pro, or nil if it isn’t configured.
# File lib/graphql/rake_task/validate.rb, line 47 def fetch_gem_digest(version, creds) user, pass = creds.split(":", 2) uri = URI.parse("https://gems.graphql.pro/gems/graphql-pro-#{version}.gem") req = Net::HTTP::Get.new(uri) req.basic_auth(user, pass) res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) } res.is_a?(Net::HTTPSuccess) ? Digest::SHA512.hexdigest(res.body.to_s) : nil end
Returns the SHA512 hex digest of the downloaded gem, or nil if the download failed.
Source
# File lib/graphql/rake_task/validate.rb, line 57 def fetch_published_digest(uri) res = Net::HTTP.get_response(uri) return nil unless res.is_a?(Net::HTTPSuccess) # Remove final newline from .txt file digest = res.body.to_s.strip digest.match?(DIGEST_PATTERN) ? digest : nil end
Returns the published digest at uri, or nil if it couldn’t be fetched.
Source
# File lib/graphql/rake_task/validate.rb, line 20 def normalize_version(version) # `Gem::Version.correct?` accepts `nil` and `""`, so check those first if !version.is_a?(String) || version.strip.empty? || !Gem::Version.correct?(version) nil else # Strips surrounding whitespace, leaving only `[0-9a-zA-Z.]` Gem::Version.new(version).to_s end end
Returns a normalized version string, or nil if version isn’t a valid gem version.