docker_distribution 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 021cf69a8cf9e64b6b76e760c4799618223d4a0ddd9fe725e93fcec9597b83f7
4
+ data.tar.gz: e6d343476659fe83acefe2bd3639f57fe05adf97393462ae0e99f892733a09c5
5
+ SHA512:
6
+ metadata.gz: c3f465e02c2460adbf79ffd76c046c99907d88085b9ce1ddd5c3f66592a689df85a0c31f01d43f3ac6eb8ff69238378720a9ddebe44298346f5246974d66493c
7
+ data.tar.gz: cc34f6053e2b17f0a9f433271391b02dfb4ce3cf21cc22658e4362c0031dbb2ef38e2d650d373fc0ed5067d60f2938433c78495ffaf865da407968f192d7ca8d
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ require:
2
+ - rubocop-minitest
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - bin/*
7
+ - docker_distribution.gemspec
8
+ - test/*/**
9
+ SuggestExtensions: false
10
+ NewCops: disable
11
+
12
+ Style/StringLiterals:
13
+ Enabled: true
14
+ EnforcedStyle: double_quotes
15
+
16
+ Style/StringLiteralsInInterpolation:
17
+ Enabled: true
18
+ EnforcedStyle: double_quotes
19
+
20
+ Layout/LineLength:
21
+ Max: 140
22
+
23
+ Metrics/ClassLength:
24
+ Max: 120
25
+
26
+ Style/Documentation:
27
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-26
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at partos0511@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM ruby:3.0.2-alpine3.14
2
+
3
+ RUN apk update && apk upgrade && apk add bash curl-dev ruby-dev build-base git curl
4
+
5
+ RUN mkdir -p /gem
6
+ WORKDIR /gem
7
+
8
+ COPY . /gem
9
+
10
+ RUN bundle install --jobs 4
11
+
12
+ ENV PATH /gem/bin:$PATH
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13"
8
+
9
+ gem "minitest", "~> 5"
10
+ gem "minitest-power_assert"
11
+
12
+ gem "rubocop", "~> 1"
13
+
14
+ gem "rubocop-minitest", "~> 0"
15
+
16
+ gem "awesome_print"
17
+ gem "byebug"
18
+
19
+ gem "warning"
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ docker_distribution (0.1.0)
5
+ digest (~> 3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ awesome_print (1.9.2)
12
+ byebug (11.1.3)
13
+ digest (3.1.0)
14
+ json (2.6.2)
15
+ minitest (5.16.3)
16
+ minitest-power_assert (0.3.1)
17
+ minitest
18
+ power_assert (>= 1.1)
19
+ parallel (1.22.1)
20
+ parser (3.1.2.1)
21
+ ast (~> 2.4.1)
22
+ power_assert (2.0.1)
23
+ rainbow (3.1.1)
24
+ rake (13.0.6)
25
+ regexp_parser (2.5.0)
26
+ rexml (3.2.5)
27
+ rubocop (1.36.0)
28
+ json (~> 2.3)
29
+ parallel (~> 1.10)
30
+ parser (>= 3.1.2.1)
31
+ rainbow (>= 2.2.2, < 4.0)
32
+ regexp_parser (>= 1.8, < 3.0)
33
+ rexml (>= 3.2.5, < 4.0)
34
+ rubocop-ast (>= 1.20.1, < 2.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (>= 1.4.0, < 3.0)
37
+ rubocop-ast (1.21.0)
38
+ parser (>= 3.1.1.0)
39
+ rubocop-minitest (0.22.1)
40
+ rubocop (>= 0.90, < 2.0)
41
+ ruby-progressbar (1.11.0)
42
+ unicode-display_width (2.3.0)
43
+ warning (1.3.0)
44
+
45
+ PLATFORMS
46
+ x86_64-linux-musl
47
+
48
+ DEPENDENCIES
49
+ awesome_print
50
+ byebug
51
+ docker_distribution!
52
+ minitest (~> 5)
53
+ minitest-power_assert
54
+ rake (~> 13)
55
+ rubocop (~> 1)
56
+ rubocop-minitest (~> 0)
57
+ warning
58
+
59
+ BUNDLED WITH
60
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Artem Petrov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,9 @@
1
+ .PHONY: test lint
2
+
3
+ test:
4
+ bundle exec rake test
5
+
6
+ lint:
7
+ bundle exec rubocop -A
8
+
9
+
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # DockerDistribution
2
+
3
+ Implementation of OCI Distribution Specification on Ruby. Implementation copied from Golang version which used in Docker Cli and Kubectl Cli.
4
+
5
+ [OCI Distribution Specification](https://github.com/opencontainers/distribution-spec)
6
+
7
+ [Golang implementation](https://github.com/docker/distribution/tree/main/reference)
8
+
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ gem install docker_distribution
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Reference
19
+ * Add description from implementation comments
20
+ ```
21
+ DockerDistribution::Reference.parse(image_name)
22
+ DockerDistribution::Reference.parse_named(str)
23
+ DockerDistribution::Reference.with_name(name)
24
+ DockerDistribution::Reference.with_tag(named, tag)
25
+ DockerDistribution::Reference.with_digest(named, digest)
26
+ DockerDistribution::Reference.split_domain(name)
27
+ DockerDistribution::Reference.split_hostname(named)
28
+ ```
29
+
30
+ ### Normalize
31
+ * Add description from implementation comments
32
+ ```
33
+ DockerDistribution::Normalize.parse_normalized_named(str)
34
+ DockerDistribution::Normalize.parse_docker_ref(ref)
35
+ DockerDistribution::Normalize.split_docker_domain(name)
36
+ DockerDistribution::Normalize.familiarize_name(repo)
37
+ DockerDistribution::Normalize.tag_name_only(ref)
38
+ DockerDistribution::Normalize.parse_any_reference(ref)
39
+ DockerDistribution::Normalize.parse_any_reference_with_set(ref, digest_set)
40
+ ```
41
+
42
+ ### Regexp
43
+ * Add description from implementation comments
44
+ ```
45
+ DockerDistribution::Regexp.alpha_numeric
46
+ DockerDistribution::Regexp.separator
47
+ DockerDistribution::Regexp.name_component
48
+ DockerDistribution::Regexp.domain_name_component
49
+ DockerDistribution::Regexp.ipv6address
50
+ DockerDistribution::Regexp.domain_name
51
+ DockerDistribution::Regexp.host
52
+ DockerDistribution::Regexp.domain
53
+ DockerDistribution::Regexp.domain_regexp
54
+ DockerDistribution::Regexp.tag
55
+ DockerDistribution::Regexp.tag_regexp
56
+ DockerDistribution::Regexp.anchored_tag
57
+ DockerDistribution::Regexp.anchored_tag_regexp
58
+ DockerDistribution::Regexp.digest_pat
59
+ DockerDistribution::Regexp.digest_regexp
60
+ DockerDistribution::Regexp.anchored_digest
61
+ DockerDistribution::Regexp.anchored_digest_regexp
62
+ DockerDistribution::Regexp.name_pat
63
+ DockerDistribution::Regexp.name_regexp
64
+ DockerDistribution::Regexp.anchored_name
65
+ DockerDistribution::Regexp.anchored_name_regexp
66
+ DockerDistribution::Regexp.reference_pat
67
+ DockerDistribution::Regexp.reference_regexp
68
+ DockerDistribution::Regexp.identifier
69
+ DockerDistribution::Regexp.identifier_regexp
70
+ DockerDistribution::Regexp.short_identifier
71
+ DockerDistribution::Regexp.short_identifier_regexp
72
+ DockerDistribution::Regexp.anchored_identifier
73
+ DockerDistribution::Regexp.anchored_identifier_regexp
74
+ DockerDistribution::Regexp.anchored_short_identifier
75
+ DockerDistribution::Regexp.anchored_short_identifier_regexp
76
+ ```
77
+
78
+ ### Digest
79
+ * Add description from implementation comments
80
+ ```
81
+ DockerDistribution::Digest.parse(digest_string)
82
+ ```
83
+
84
+ ## Examples
85
+ ...
86
+
87
+ More examples in tests
88
+
89
+ ## Development
90
+ ```
91
+ docker-compose build gem
92
+ docker-compose run --rm gem bash
93
+ bundle install
94
+ ...
95
+ make test
96
+ make lint
97
+ ```
98
+
99
+ ## Release
100
+ 1. [Read this](https://guides.rubygems.org/publishing/)
101
+ 2. Make sure you logged in into Rubygems
102
+ 3. Update version accoring [semver](https://semver.org/)
103
+ 4. `gem build docker_distribution.gemspec`
104
+ 5. `gem push docker_distribution-[version].gem`
105
+
106
+ ## Todo
107
+ - Finish readme description / examples / installation guide / development guide / examples / ruby version support
108
+ - Add correct workflow in github to run tests and linters in docker env
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,26 @@
1
+ version: '3.9'
2
+
3
+ x-shared-environment: &shared-environment
4
+ BUNDLE_PATH: /bundle_cache
5
+ GEM_HOME: /bundle_cache
6
+ GEM_PATH: /bundle_cache
7
+ RUBYGEMS_API_KEY: ${RUBYGEMS_API_KEY}
8
+
9
+ services:
10
+ gem:
11
+ build: .
12
+ environment: *shared-environment
13
+ volumes:
14
+ - .:/gem:cached
15
+ - ~/.ssh:/root/.ssh
16
+ - ~/.bash_history:/root/.bash_history
17
+ - bundle_cache:/bundle_cache
18
+ command: bash
19
+
20
+ bundle_cache:
21
+ image: busybox
22
+ volumes:
23
+ - bundle_cache:/bundle_cache
24
+
25
+ volumes:
26
+ bundle_cache:
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DockerDistribution
4
+ class CanonicalReference
5
+ extend ::Forwardable
6
+ def_delegators :repository, :name, :domain, :path
7
+
8
+ attr_accessor :repository, :digest
9
+
10
+ def initialize(repository, digest)
11
+ @repository = repository
12
+ @digest = digest
13
+ end
14
+
15
+ def to_s
16
+ [repository.name, digest].join("@")
17
+ end
18
+
19
+ def to_h
20
+ {
21
+ repository: name,
22
+ domain: domain,
23
+ path: path,
24
+ digest: digest
25
+ }
26
+ end
27
+
28
+ def familiar
29
+ self.class.new(Normalize.familiarize_name(self), digest)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+
5
+ module DockerDistribution
6
+ class Digest
7
+ DEFAULT_ALGORITHM = "sha256"
8
+ attr_accessor :digest_string, :encoded, :algorithm_type
9
+
10
+ # Parse parses digest_string and returns the validated digest object. An error will
11
+ # be raised if the format is invalid.
12
+ def self.parse!(digest_string)
13
+ dgst = new(digest_string)
14
+ dgst.validate!
15
+ dgst
16
+ end
17
+
18
+ def initialize(digest_string)
19
+ @digest_string = digest_string
20
+ @algorithm_type, @encoded = digest_string.index(":") ? digest_string.split(":") : [DEFAULT_ALGORITHM, digest_string]
21
+ end
22
+
23
+ def digest
24
+ [algorithm_type, encoded].compact.join(":")
25
+ end
26
+
27
+ def to_s
28
+ digest
29
+ end
30
+
31
+ # rubocop:disable Metrics/AbcSize
32
+ def validate!
33
+ index = digest_string.index(":")
34
+ raise DigestInvalidFormat if index.nil? || index + 1 == digest_string.length
35
+
36
+ raise DigestInvalidLength if algorithm.block_length != encoded.length
37
+
38
+ return true if Regexp.anchored_encoded_regexp(algorithm_type.upcase).match?(encoded)
39
+
40
+ raise DigestInvalidFormat
41
+ end
42
+ # rubocop:enable Metrics/AbcSize
43
+
44
+ def algorithm
45
+ send(:Digest, algorithm_type.upcase).new
46
+ rescue NameError, LoadError
47
+ raise DigestUnsupported
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DockerDistribution
4
+ class DigestReference
5
+ attr_accessor :digest
6
+
7
+ def initialize(digest)
8
+ @digest = digest
9
+ end
10
+
11
+ def to_s
12
+ digest
13
+ end
14
+
15
+ def to_h
16
+ { digest: digest }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+
5
+ module DockerDistribution
6
+ class DigestSet
7
+ attr_writer :entries
8
+
9
+ def initialize(digest_strings)
10
+ @entries = digest_strings.map { |digest_string| Digest.new(digest_string) }
11
+ end
12
+
13
+ def entries
14
+ @entries ||= []
15
+ end
16
+
17
+ def add(digest_string)
18
+ @entries << Digest.new(digest_string)
19
+ end
20
+
21
+ def lookup!(digest_string)
22
+ raise DigestNotFound if entries.length.zero?
23
+
24
+ search_func, encoded, alg = parse!(digest_string)
25
+
26
+ entry = search(search_func, encoded, alg)
27
+ entry.digest
28
+ end
29
+
30
+ private
31
+
32
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
33
+ def parse!(digest_string)
34
+ dgst = Digest.parse!(digest_string)
35
+ alg = dgst.algorithm_type
36
+ encoded = dgst.encoded
37
+ search_func = lambda do |i|
38
+ return entries[i].algorithm_type >= dgst.algorithm_type if entries[i].encoded == encoded
39
+
40
+ entries[i].encoded >= encoded
41
+ end
42
+ [search_func, encoded, alg]
43
+ rescue DigestInvalidFormat
44
+ alg = Digest::DEFAULT_ALGORITHM
45
+ encoded = digest_string
46
+ search_func = lambda do |i|
47
+ entries[i].encoded >= digest_string
48
+ end
49
+ [search_func, encoded, alg]
50
+ end
51
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
52
+
53
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
54
+ def search(search_func, encoded, alg)
55
+ idx = entries.each_with_index.filter_map { |_el, i| i if search_func.call(i) }.first || entries.length
56
+ raise DigestNotFound if idx == entries.length || !check_short_match(entries[idx].algorithm_type, entries[idx].encoded, alg.to_s,
57
+ encoded)
58
+ return entries[idx] if entries[idx].algorithm_type == alg && entries[idx].encoded == encoded
59
+
60
+ raise DigestAmbiguous if idx + 1 < entries.length && check_short_match(entries[idx + 1].algorithm_type, entries[idx + 1].encoded,
61
+ alg.to_s, encoded)
62
+
63
+ entries[idx]
64
+ end
65
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
66
+
67
+ # rubocop:disable Metrics/CyclomaticComplexity
68
+ def check_short_match(alg, encoded, short_alg, short_encoded)
69
+ if encoded.length == short_encoded.length
70
+ return false if encoded != short_encoded
71
+
72
+ return false if short_alg.length.positive? && alg != short_alg
73
+ end
74
+
75
+ return false unless encoded.start_with?(short_encoded)
76
+
77
+ return false if short_alg.length.positive? && alg != short_alg
78
+
79
+ true
80
+ end
81
+ # rubocop:enable Metrics/CyclomaticComplexity
82
+ end
83
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DockerDistribution
4
+ # NameEmpty is raised for empty, invalid repository names.
5
+ class NameEmpty < StandardError; end
6
+ # ReferenceInvalidFormat represents an error while trying to parse a string as a reference.
7
+ class ReferenceInvalidFormat < StandardError; end
8
+ # TagInvalidFormat represents an error while trying to parse a string as a tag.
9
+ class TagInvalidFormat < StandardError; end
10
+ # DigestError raised when something wrong with Digest
11
+ class DigestError < StandardError; end
12
+ # DigestInvalidLength raised when digest has invalid length.
13
+ class DigestInvalidLength < DigestError; end
14
+ # DigestInvalidFormat raised when digest format invalid.
15
+ class DigestInvalidFormat < DigestError; end
16
+ # DigestUnsupported raised when the digest algorithm is unsupported.
17
+ class DigestUnsupported < DigestError; end
18
+ # DigestNotFound raised when the digest set not found
19
+ class DigestNotFound < DigestError; end
20
+ # DigestAmbiguous raised when the digest set has two same digests
21
+ class DigestAmbiguous < DigestError; end
22
+ # NameContainsUppercase is raised for invalid repository names that contain uppercase characters.
23
+ class NameContainsUppercase < StandardError; end
24
+ # NameTooLong is raised when a repository name is longer than 255 symbols.
25
+ class NameTooLong < StandardError; end
26
+ # NameNotCanonical is raised when a name is not canonical.
27
+ class NameNotCanonical < StandardError; end
28
+ # # ParseNormalizedNamedError is raised when a parse normalized error failed
29
+ class ParseNormalizedNamedError < StandardError; end
30
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DockerDistribution
4
+ class Helpers
5
+ class << self
6
+ def familiar_name(named)
7
+ return named.familiar.name if named.respond_to?(:familiar)
8
+
9
+ named.name
10
+ end
11
+
12
+ def familiar_string(named)
13
+ return named.familiar.to_s if named.respond_to?(:familiar)
14
+
15
+ named.to_s
16
+ end
17
+
18
+ def familiar_match(pattern, ref)
19
+ string_match = File.fnmatch(pattern, familiar_string(ref), File::FNM_PATHNAME)
20
+ name_match = File.fnmatch(pattern, familiar_name(ref), File::FNM_PATHNAME)
21
+
22
+ string_match || name_match
23
+ end
24
+
25
+ def tagged?(ref)
26
+ ref.respond_to?(:tag)
27
+ end
28
+
29
+ def canonical?(ref)
30
+ ref.respond_to?(:digest)
31
+ end
32
+
33
+ def named?(ref)
34
+ ref.respond_to?(:name)
35
+ end
36
+
37
+ def familiar?(ref)
38
+ ref.respond_to?(:familiar)
39
+ end
40
+
41
+ def name_only?(ref)
42
+ named?(ref) && !tagged?(ref) && !canonical?(ref)
43
+ end
44
+
45
+ def normalized_named?(ref)
46
+ named?(ref) && familiar?(ref)
47
+ end
48
+
49
+ def from(str, index)
50
+ str[index..]
51
+ end
52
+
53
+ def to(str, index)
54
+ str[0...index]
55
+ end
56
+
57
+ def empty?(object)
58
+ object == "" || object.nil?
59
+ end
60
+ end
61
+ end
62
+ end