require "rake" require "fileutils" require "dtc_rake/config" require "dtc_rake/product" require "dtc_rake/ui" require "uu/os/security/session" require "uu/os/artifact" require "uu/os/sheet" require "uu/os/rest/binary_value" include DtcRake::UI def uesuri(art_code) config = DtcRake::Config.instance error("Territory code is not set. Set it in DtcRake.configure (attribute appbox_territory_code) in your Rakefile.") if config.appbox_territory_code.nil? UU::OS::UESURI.create( territory_code: config.appbox_territory_code, artifact_code: art_code ) end def create_appbox(attrs) config = DtcRake::Config.instance product = DtcRake::Product.instance credentials = attrs[:credentials] version = attrs.fetch(:version, product.version) icon = attrs.fetch(:icon, %q(ues:#{system}:#{ues_v5.core_v1.codetable_v1.base_v1.CodeTable_Icons}:#{ART_364})) error("Specify appbox location code - set it in DtcRake.configure block (attribute appbox_location_code) in your Rakefile") unless config.appbox_location_code error("Specify appbox meta artifact code - set it in DtcRake.configure block (attribute appbox_meta_artifact_code) in your Rakefile") unless config.appbox_meta_artifact_code location = uesuri(config.appbox_location_code) meta_artifact = uesuri(config.appbox_meta_artifact_code) error("Specify login credentials") unless credentials UU::OS::Security::Session.login(credentials) config = DtcRake::Config.instance art_name = "#{product.app_descriptor[:data][:name]} #{version}" art_code = "#{product.app_descriptor[:data][:code]}_#{version}" announce "Creating appbox #{art_code} in territory #{config.appbox_territory_code}" appbox_uri = UU::OS::Artifact.create(location, name: art_name, code: art_code, metaArtifactUri: meta_artifact, iconUri: icon ) appbox_uarchive = config.appbox_uarchive unless appbox_uarchive.nil? begin sheet_uri = UU::OS::Sheet.get_sheet_list(appbox_uri, query: "main = true").first.uri File.open(appbox_uarchive, "rb") do |f| data = UU::OS::REST::BinaryValue.new(f) data.content_type = UU::OS::Sheet::MimeType::UARCHIVE UU::OS::Sheet.check_in(sheet_uri, :content => data) end rescue StandardError => e warning "WARNING: Failed to fill in appbox content, skipping (cause: #{e.message})" end end appbox_uri end desc <<-DESC.gsub(/^ {2}/, '') Creates new appbox artifact; requires path to password file. Vendor, app name and version are read from uuApp deployment descriptor. Optionally, version can be overriden. Examples: rake appbox DTC_RAKE_PASSWD=12-345-6 ("~/.uu/12-345-6" will be used) (version from client gem will be used) rake appbox DTC_RAKE_PASSWD=/path/to/12-345-6 (password file from the specified path will be used) rake appbox DTC_RAKE_PASSWD=12-345-6 VERSION=1.2.3 (the specified version will be used) DESC task :appbox do error("Specify password file in env variable DTC_RAKE_PASSWD, e.g. rake appbox DTC_RAKE_PASSWD=12-345-6") unless ENV["DTC_RAKE_PASSWD"] art_uri = create_appbox( credentials: ENV["DTC_RAKE_PASSWD"], version: ENV["VERSION"] || DtcRake::Product.instance.version ) success "Appbox #{art_uri} created" end