get_ws1_device_attributes

in chef/cookbooks/cpe_workspaceone/libraries/hubcli.rb [21:70]


    def get_ws1_device_attributes
      unless macos?
        Chef::Log.warn('node.ws1_device_attributes called on non-macOS!')
        return {}
      end

      
      return {} unless node.profile_installed?('ProfileDisplayName', 'Device Manager')

      
      return {} unless ws1_hubcli_exists

      
      ws1_use_cache = node['cpe_workspaceone']['use_cache']
      return _get_available_ws1_profiles_list unless ws1_use_cache

      
      ws1_cache_file_path = ::File.join(Chef::Config[:file_cache_path], 'cpe_workspaceone-device_attributes.json')
      ws1_cache_exists = ::File.exist?(ws1_cache_file_path)
      ws1_cache_old = ws1_json_age_over_invalidation?(ws1_cache_file_path)

      
      if ws1_cache_exists && !ws1_cache_old
        parsed_ws1_json = node.parse_json(ws1_cache_file_path)
        
        
        
        if node.greater_than?(node['platform_version'], parsed_ws1_json['os_version'])
          ws1_device_attributes = _get_available_ws1_profiles_list
        else
          return parsed_ws1_json
        end
      
      else
        
        _trigger_sync
        ws1_device_attributes = _get_available_ws1_profiles_list
      end

      
      unless ws1_device_attributes.empty?
        node.write_contents_to_file(ws1_cache_file_path, Chef::JSONCompat.to_json_pretty(ws1_device_attributes))
      end

      ws1_device_attributes
    rescue Exception => e 
      Chef::Log.warn("Failed to get workspace one device attributes with error #{e}")
      {}
    end