Sha256: df3449b317319eced81de81393f86518350d902ccabeb5689be6cab16b641329

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

require 'aws-sdk'
require 'base64'

module OdaniaOps
	module Helper
		module Aws
			class << self
				def configure
					::Aws.config.update(
						{
							region: $config['aws']['region'],
							credentials: ::Aws::Credentials.new($config['aws']['access_key_id'], $config['aws']['secret_access_key'])
						}
					)
				end

				def tags(repository_name)
					client = ::Aws::ECR::Client.new(
							{
									region: $config['aws']['region'],
									credentials: ::Aws::Credentials.new($config['aws']['access_key_id'], $config['aws']['secret_access_key'])
							}
					)
					result = []
					response = client.describe_images(repository_name: repository_name)
					response.image_details.each do |aws_image_details|
						result += aws_image_details.image_tags
					end

					result.uniq
				end

				def docker_login
					client = ::Aws::ECR::Client.new(
							{
									region: $config['aws']['region'],
									credentials: ::Aws::Credentials.new($config['aws']['access_key_id'], $config['aws']['secret_access_key'])
							}
					)

					response = client.get_authorization_token
					return Base64.decode64(response.authorization_data[0].authorization_token).split(':')
				end
			end
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
odania_ops-0.0.14 lib/odania_ops/helper/aws.rb
odania_ops-0.0.13 lib/odania_ops/helper/aws.rb