uffizzi_core 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 169a9ec674c81b791babc5049b74c807a9150da4534980f6b6eb2188b3b12771
4
- data.tar.gz: c3365c36312f14cf56a3d8c71b293939d667369b8a6df9da67925620127b514e
3
+ metadata.gz: 520b79e2bc010eab840b4a6c4d31fe236c7b1e1a04714a42319399d904208b09
4
+ data.tar.gz: 4cdf4a4e66308a13bcb9740ea3aafb63d1de49c128fef7fb4d59731045ac1877
5
5
  SHA512:
6
- metadata.gz: f8af4f54965d0557094566deb6d3bea447ede3071891aa4bd7d00139b3795a9644fd6b8d71a346b8b6aeff113cc578bdde3f4f64e45d21bb31f5d59b531e15e9
7
- data.tar.gz: aa2b7c6fce6745775164119324cd7298cd2382246764026c4aa4bf6ebba3f1c8c390eba3cd3a9bde9b512fb1ec3607da5fee8c376bcac79e953d9efaccd7d811
6
+ metadata.gz: 8e44e43bb064368f55ca82ad30eb989ee8503a65a2daad496f50608d983c39da93543ec8ea6cddeef7cbcf1367bd1916bc929fc7015b5fd0121d6eb987333f2e
7
+ data.tar.gz: 414e34bec819810a75c0fe13ca4652ab0a26d271f1bedd8d11d9e50f9ebbd918f83209205c5a0a5005f8db2c59889114268a961b8a4a93ea270c43e37b43f498
@@ -23,6 +23,15 @@ class UffizziCore::DockerHubClient
23
23
  nil
24
24
  end
25
25
 
26
+ def repository(namespace:, image:)
27
+ url = "#{BASE_URL}/v2/repositories/#{namespace}/#{image}"
28
+
29
+ response = connection.get(url) do |request|
30
+ request.headers['Authorization'] = "JWT #{jwt}"
31
+ end
32
+ RequestResult.new(status: response.status, result: response.body)
33
+ end
34
+
26
35
  def public_images(q:, page: 1, per_page: 25)
27
36
  url = "#{BASE_URL}/api/content/v1/products/search"
28
37
  params = { page_size: per_page, q: q, type: :image, page: page }
@@ -206,9 +206,11 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
206
206
 
207
207
  def build_docker_repo_attributes(image_data, credentials, scope, repo_type)
208
208
  credential = credentials.send(scope).first
209
- raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.invalid_credential', value: scope) if credential.nil?
209
+ if UffizziCore::ComposeFile::ContainerService.image_available?(credential, image_data, scope)
210
+ return docker_builder(repo_type).build_attributes(image_data)
211
+ end
210
212
 
211
- docker_builder(repo_type).build_attributes(image_data)
213
+ raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.unprocessable_image', value: scope)
212
214
  end
213
215
 
214
216
  def variables(variables_data, dependencies)
@@ -55,23 +55,32 @@ class UffizziCore::ComposeFile::ContainerService
55
55
 
56
56
  def credential_for_container(container, credentials)
57
57
  if UffizziCore::ComposeFile::ContainerService.azure?(container)
58
- detect_credential(credentials, :azure)
58
+ detect_credential(container, credentials, :azure)
59
59
  elsif UffizziCore::ComposeFile::ContainerService.docker_hub?(container)
60
- detect_credential(credentials, :docker_hub)
60
+ detect_credential(container, credentials, :docker_hub)
61
61
  elsif UffizziCore::ComposeFile::ContainerService.google?(container)
62
- detect_credential(credentials, :google)
62
+ detect_credential(container, ecredentials, :google)
63
63
  end
64
64
  end
65
65
 
66
- def detect_credential(credentials, type)
66
+ def detect_credential(container, credentials, type)
67
67
  credential = credentials.detect do |item|
68
68
  item.send("#{type}?")
69
69
  end
70
70
 
71
- error_message = "Invalid credential: #{type}"
72
- raise UffizziCore::ComposeFile::CredentialError.new(error_message) if credential.nil?
71
+ return credential if image_available?(credential, container[:image], type)
73
72
 
74
- credential
73
+ raise UffizziCore::ComposeFile::CredentialError.new(I18n.t('compose.unprocessable_image', value: type))
74
+ end
75
+
76
+ def image_available?(credential, image_data, type)
77
+ case type
78
+ when :docker_hub
79
+ UffizziCore::DockerHubService.image_available?(credential, image_data)
80
+ else
81
+ # TODO check image availability in other registry types
82
+ credential.present?
83
+ end
75
84
  end
76
85
  end
77
86
  end
@@ -11,6 +11,16 @@ class UffizziCore::DockerHubService
11
11
  accounts_response.nil? ? [] : accounts_response.namespaces
12
12
  end
13
13
 
14
+ def image_available?(credential, image_data)
15
+ namespace = image_data[:namespace]
16
+ repo_name = image_data[:name]
17
+ client = UffizziCore::DockerHubClient.new(credential)
18
+ response = client.repository(namespace: namespace, image: repo_name)
19
+ return false if not_found?(response)
20
+
21
+ true
22
+ end
23
+
14
24
  def user_client(credential)
15
25
  return @client if @client&.credential&.username == credential.username
16
26
 
@@ -36,5 +46,9 @@ class UffizziCore::DockerHubService
36
46
  def public_docker_hub_client
37
47
  @public_docker_hub_client ||= UffizziCore::DockerHubClient.new
38
48
  end
49
+
50
+ def not_found?(response)
51
+ response.status == 404
52
+ end
39
53
  end
40
54
  end
@@ -17,7 +17,7 @@ en:
17
17
  no_services: Service services has neither an image nor a build context specified. At least one must be provided.
18
18
  no_ingress: Service ingress has not been defined.
19
19
  invalid_image_value: Invalid image value '%{value}'
20
- invalid_credential: Invalid credential '%{value}'
20
+ unprocessable_image: Invalid credential '%{value} or image does not exist'
21
21
  invalid_repo_type: Unsupported repo type
22
22
  repo_not_found: The specified repository doesn't exist '%{name}'
23
23
  ingress_port_not_specified: Ingress port not specified
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UffizziCore
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-09-07 00:00:00.000000000 Z
12
+ date: 2022-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aasm