require 'helix_versioning_engine/change_service' module GitFusion # # namespace for functions supporting git-fusion api # module Util include HelixVersioningEngine # Messages back to client REPO_INITIALISED = 'Repository already initialised' PATCH_PARAMS_DONT_EXIST = 'Chosen repo configuration' \ 'p4gf_file does not have all of the specified parameters' KEY_ALREADY_EXISTS = 'Key under this name already uploaded, ' \ 'choose a different name' USER_NOT_MATCHING = 'User is authenticated, ' \ 'but not authorised to view the requested data.' DF_MATCH = %r{\/\/(?<depot>.*)\/users\/(?<user>.*)\/keys\/(?<key_name>.*)$} def temp_client require_p4_with_temp_client [env['p4'], env['hws_settings']] end def all_keys p4, hws_settings = temp_client file_list = p4.run_files('-e', "//#{hws_settings.GIT_FUSION_DEPOT}/users/*/...") file_list.map do |file| data = file['depotFile'].match(DF_MATCH) { 'key_name' => GitFusionStrings.decode(data['key_name']), 'user' => data['user'], 'key' => print_result(file['depotFile'], p4: p4) } end end def keys_for_user(user) keys = all_keys.select { |key| key['user'] == user } keys end def check_if_key_exists(key) keys = all_keys keys.any? { |h| h['key'] == key } end def check_if_key_name_exists(key, user) keys = all_keys keys.any? { |h| h['key_name'] == key && h['user'] == user } end def get_by_key(key, value) val = all_keys.select { |record| record['key'] == key } val.first.nil? ? '' : val.first[value] end def self.error?(p4) !p4.errors.empty? end def to_message(message) { MessageCode: 0, MessageSeverity: 3, MessageText: message } end def error_and_clean_up(error) halt 400, to_message(error).to_json end def print_result(file_location, p4: nil) p4 = temp_client.first unless p4 file_result = p4.run_print(file_location) content = ''.b file_result.drop(1).each do |result| content << result if result end content end def decode_from_uri(*args) args.map do |a| HWSStrings.component_decode(a, '%', GitFusionStrings::URI_RESERVED_CHARACTERS) end end def encode_to_gf_format(*args) args.map do |a| GitFusionStrings.encode(a) end end def submit_file(p4, file_path, file_content, description) files = [ ChangeService::File.new(depot_file: file_path, action: 'upload', content: file_content) ] change_service = ChangeService.new(p4: p4, client_root: env['p4_root'], client_name: p4.client) change_service.submit(files: files, description: description) end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 16014 | Doug Scheirer | Merge down from main | ||
//guest/perforce_software/helix-web-services/main/source/helix_web_services/lib/git_fusion/util.rb | |||||
#1 | 15969 | tjuricek |
Add support for repo creation/update and deletion, same for SSH keys. Add util module for supporting methods, modify temp client to dissapear. (Modified submit of review 15549 by @ptomiak) |