新增:gitlink、gitea、gitcode的token校验以及请求超时时间的更改
This commit is contained in:
		
							parent
							
								
									cbdbc4b25e
								
							
						
					
					
						commit
						973e18812c
					
				| 
						 | 
					@ -36,16 +36,66 @@ class Projects::VerifyAuthTokenService < ApplicationService
 | 
				
			||||||
            gitlab_verify
 | 
					            gitlab_verify
 | 
				
			||||||
        when "gitee.com"
 | 
					        when "gitee.com"
 | 
				
			||||||
            gitee_verify
 | 
					            gitee_verify
 | 
				
			||||||
 | 
					        when "gitlink.org.cn"
 | 
				
			||||||
 | 
					            gitlink_verify
 | 
				
			||||||
 | 
					        when "gitea.com"
 | 
				
			||||||
 | 
					            gitea_verify
 | 
				
			||||||
 | 
					        when "gitcode.com"
 | 
				
			||||||
 | 
					            gitcode_verify
 | 
				
			||||||
 | 
					        else 
 | 
				
			||||||
 | 
					            @success = nil
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def gitcode_verify 
 | 
				
			||||||
 | 
					        url = "/api/v5/user"
 | 
				
			||||||
 | 
					        api_url = "https://api.gitcode.com"
 | 
				
			||||||
 | 
					        client = Faraday.new(url: api_url)
 | 
				
			||||||
 | 
					        client.options["open_timeout"] = 100
 | 
				
			||||||
 | 
					        client.options["timeout"] = 100
 | 
				
			||||||
 | 
					        client.options["write_timeout"] = 100
 | 
				
			||||||
 | 
					        req_params={
 | 
				
			||||||
 | 
					            access_token: @token
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        response = client.public_send("get", url, req_params)
 | 
				
			||||||
 | 
					        @success = true if response.status == 200 
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def gitea_verify 
 | 
				
			||||||
 | 
					        url = "/api/v1/user"
 | 
				
			||||||
 | 
					        api_url = "https://gitea.com"
 | 
				
			||||||
 | 
					        client = Faraday.new(url: api_url)
 | 
				
			||||||
 | 
					        client.options["open_timeout"] = 100
 | 
				
			||||||
 | 
					        client.options["timeout"] = 100
 | 
				
			||||||
 | 
					        client.options["write_timeout"] = 100
 | 
				
			||||||
 | 
					        req_params={
 | 
				
			||||||
 | 
					            token: @token
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        response = client.public_send("get", url, req_params)
 | 
				
			||||||
 | 
					        @success = true if response.status == 200 
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def gitlink_verify
 | 
				
			||||||
 | 
					        url = "/api/v1/user"
 | 
				
			||||||
 | 
					        api_url = "https://cdn05042023.gitlink.org.cn"
 | 
				
			||||||
 | 
					        client = Faraday.new(url: api_url)
 | 
				
			||||||
 | 
					        client.options["open_timeout"] = 100
 | 
				
			||||||
 | 
					        client.options["timeout"] = 100
 | 
				
			||||||
 | 
					        client.options["write_timeout"] = 100
 | 
				
			||||||
 | 
					        req_params={
 | 
				
			||||||
 | 
					            token: @token
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        response = client.public_send("get", url, req_params)
 | 
				
			||||||
 | 
					        @success = true if response.status == 200 
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def gitee_verify
 | 
					    def gitee_verify
 | 
				
			||||||
        url = "/api/v5/repos/#{@owner}/#{@repo}"
 | 
					        url = "/api/v5/repos/#{@owner}/#{@repo}"
 | 
				
			||||||
        api_url=  "https://gitee.com"
 | 
					        api_url=  "https://gitee.com"
 | 
				
			||||||
        client = Faraday.new(url: api_url)
 | 
					        client = Faraday.new(url: api_url)
 | 
				
			||||||
        client.options["open_timeout"] = 1
 | 
					        client.options["open_timeout"] = 100
 | 
				
			||||||
        client.options["timeout"] = 1
 | 
					        client.options["timeout"] = 100
 | 
				
			||||||
        client.options["write_timeout"] = 1
 | 
					        client.options["write_timeout"] = 100
 | 
				
			||||||
        req_params={
 | 
					        req_params={
 | 
				
			||||||
            access_token: @token,
 | 
					            access_token: @token,
 | 
				
			||||||
            owner: @owner,
 | 
					            owner: @owner,
 | 
				
			||||||
| 
						 | 
					@ -59,9 +109,9 @@ class Projects::VerifyAuthTokenService < ApplicationService
 | 
				
			||||||
        url = "/octocat"
 | 
					        url = "/octocat"
 | 
				
			||||||
        api_url=  "https://api.github.com"
 | 
					        api_url=  "https://api.github.com"
 | 
				
			||||||
        client = Faraday.new(url: api_url)
 | 
					        client = Faraday.new(url: api_url)
 | 
				
			||||||
        client.options["open_timeout"] = 1
 | 
					        client.options["open_timeout"] = 100
 | 
				
			||||||
        client.options["timeout"] = 1
 | 
					        client.options["timeout"] = 100
 | 
				
			||||||
        client.options["write_timeout"] = 1
 | 
					        client.options["write_timeout"] = 100
 | 
				
			||||||
        client.headers["Authorization"] = "Bearer #{@token}"
 | 
					        client.headers["Authorization"] = "Bearer #{@token}"
 | 
				
			||||||
        response = client.public_send("get", url)
 | 
					        response = client.public_send("get", url)
 | 
				
			||||||
        @success = true if response.status == 200 
 | 
					        @success = true if response.status == 200 
 | 
				
			||||||
| 
						 | 
					@ -71,9 +121,9 @@ class Projects::VerifyAuthTokenService < ApplicationService
 | 
				
			||||||
        url = "/api/v4/projects"
 | 
					        url = "/api/v4/projects"
 | 
				
			||||||
        api_url=  "https://gitlab.com"
 | 
					        api_url=  "https://gitlab.com"
 | 
				
			||||||
        client = Faraday.new(url: api_url)
 | 
					        client = Faraday.new(url: api_url)
 | 
				
			||||||
        client.options["open_timeout"] = 1
 | 
					        client.options["open_timeout"] = 100
 | 
				
			||||||
        client.options["timeout"] = 1
 | 
					        client.options["timeout"] = 100
 | 
				
			||||||
        client.options["write_timeout"] = 1
 | 
					        client.options["write_timeout"] = 100
 | 
				
			||||||
        req_params={
 | 
					        req_params={
 | 
				
			||||||
            private_token: @token
 | 
					            private_token: @token
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue