Skip to content

Commit 7e2fad5

Browse files
committed
fix: rubocop suggestions are corrected
1 parent d911829 commit 7e2fad5

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/cloud_controller/diego/docker/docker_uri_converter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module VCAP::CloudController
44
class DockerURIConverter
55
def convert(docker_uri)
66
raise UriUtils::InvalidDockerURI.new "Docker URI [#{docker_uri}] should not contain scheme" if docker_uri.include? '://'
7+
78
host, path, tag_digest = UriUtils.parse_docker_uri(docker_uri)
89

910
# add tag or digest part as fragment to the uri, since ruby uri parser confuses with ':'

lib/utils/uri_utils.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ module UriUtils
55
GIT_REGEX = %r{ \A git:// .+? : .+? \.git \z }x
66
DOCKER_INDEX_SERVER = 'docker.io'.freeze
77
DOCKER_PATH_REGEX = %r{\A[a-z0-9_\-\.\/]{2,255}\Z}
8-
DOCKER_TAG_REGEX = %r{[a-zA-Z0-9_\-\.]{1,128}}
9-
DOCKER_DIGEST_REGEX = %r{sha256:[a-z0-9]{64}}
10-
DOCKER_TAG_DIGEST_REGEX = Regexp.new("\\A(#{DOCKER_TAG_REGEX.source} | (#{DOCKER_TAG_REGEX.source}@#{DOCKER_DIGEST_REGEX.source}) | #{DOCKER_DIGEST_REGEX.source})\\Z", Regexp::EXTENDED)
8+
DOCKER_TAG_REGEX = /[a-zA-Z0-9_\-\.]{1,128}/
9+
DOCKER_DIGEST_REGEX = /sha256:[a-z0-9]{64}/
10+
DOCKER_TAG_DIGEST_REGEX = Regexp.new("\\A(#{DOCKER_TAG_REGEX.source} |
11+
(#{DOCKER_TAG_REGEX.source}@#{DOCKER_DIGEST_REGEX.source}) | #{DOCKER_DIGEST_REGEX.source})\\Z", Regexp::EXTENDED)
1112

1213
class InvalidDockerURI < StandardError; end
1314

@@ -69,13 +70,13 @@ def self.parse_docker_uri(docker_uri)
6970
path, tag_digest = parse_docker_tag_digest_from_path(path)
7071

7172
raise InvalidDockerURI.new "Invalid image name [#{path}]" unless DOCKER_PATH_REGEX =~ path
72-
raise InvalidDockerURI.new "Invalid image tag [#{tag_digest}]" if tag_digest && !(DOCKER_TAG_DIGEST_REGEX =~ tag_digest)
73+
raise InvalidDockerURI.new "Invalid image tag [#{tag_digest}]" if tag_digest && DOCKER_TAG_DIGEST_REGEX !~ tag_digest
7374

7475
# if only sha256 presented, we add hash value as fragment to the uri,
7576
# since the ruby uri parser confuses because of second ':' in uri's path part.
7677
if tag_digest && tag_digest.start_with?('sha256:')
77-
hash_algo, hash_value = tag_digest.split(':')
78-
path = path + '@sha256'
78+
_, hash_value = tag_digest.split(':')
79+
path += '@sha256'
7980
tag_digest = hash_value
8081
end
8182

@@ -89,7 +90,7 @@ def self.parse_docker_uri(docker_uri)
8990
private_class_method def self.missing_registry(name_parts)
9091
host = name_parts[0]
9192
name_parts.length == 1 ||
92-
(host.exclude?('.') && host.exclude?(':') && host != 'localhost')
93+
(host.exclude?('.') && host.exclude?(':') && host != 'localhost')
9394
end
9495

9596
private_class_method def self.parse_docker_tag_digest_from_path(path)
@@ -116,6 +117,5 @@ def self.parse_docker_uri(docker_uri)
116117

117118
# Return path and tag (or nil if no tag)
118119
[base_path, tag]
119-
120120
end
121121
end

0 commit comments

Comments
 (0)