如何在运行时通过http:put方法通过身份验证?

问题描述

我正在使用计划任务运行以下xqy代码,在此xqy代码中,我在put调用中手动传递了带有method =“ digest” username = admin password = admin的身份验证节点的值, 有什么办法可以让我在运行时使用
通过它吗? 1.用户名和密码的加密令牌
2.在运行时获取服务器的用户名和密码,并将其传递给http-put函数以通过8000端口访问其余服务扩展(/ v1 / resources / example)。

xquery version "1.0-ml";
    
    declare namespace hst = 'http://marklogic.com/xdmp/status/host';   
    declare namespace c = 'http://example.com/abc';  
    declare variable $Collection := 'collection';
    
    let $query :=    
         cts:and-query((   
            cts:collection-query($Collection),cts:element-range-query(xs:QName('c:element'),'<=',fn:current-dateTime())  
        ))
          
    let $uris := cts:uris('',(),$query)   
    let $total-uri := count($uris)  
    return   
        if ($total-uri) then  
        let $PORT := '8000'   
        let $database := xdmp:database()  
        let $host-list := xdmp:hosts()    
        let $hosts :=     
                for $hosts-online in $host-list      
                where xdmp:host-status($hosts-online)/hst:hosts/hst:host[.//hst:online/fn:string() = 'true']    
                return $hosts-online                        
        let $cluster-size := fn:count($hosts)     
        return
            for $host at $index in $hosts       
            let $page-size := fn:ceiling($total-uri div $cluster-size)       
            let $start-index := ($index - 1) * $page-size + 1       
            let $end-index :=       
                if ($cluster-size eq $index)  then      
                    $total-uri       
                else         
                    ($index - 1) * $page-size +$page-size        
            let $urisforHost := string-join($uris[$start-index to $end-index],',')        
    
            let $url  := fn:concat('http://',xdmp:host-name($host),':',$PORT,'/v1/resources/example?rs:uris=',$urisforHost,'&amp;rs:db=',$database)
            return
                xdmp:spawn-function(function()
                    {xdmp:http-put($url,<options xmlns="xdmp:http">
                           <authentication method="digest">
                             <username>admin</username>
                             <password>admin</password>
                           </authentication>
                     </options>
                    )
                    }
                )
    

解决方法

这可以通过creating a credential的安全证书来实现

然后您在HTTP请求中引用凭证ID,例如

const withMutationCacheUpdate = args => Wrapped => {
  return function(props) {
    const [updateData] = useMutation(UPDATE_DATA,{
      update(cache,{ data: { newData } }) {
        // Read relevant data from cache with cache.readQuery,// then update using cache.writeQuery,cache.writeFragment 
       // or cache.modify as appropriate with returned payload and possibly args
      },})
    return <Wrapped {...props} updateData={updateData} />
  }
}

const config = {...}
const YourComponent = props => { ... }
const YourWrappedComponent = withMutationCacheUpdate(config)(YourComponent)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...