수요일, 5월 29, 2024
HomeLanguageSonarQube Web API 프로젝트 (components) 공개/비공개 설정 - java

SonarQube Web API 프로젝트 (components) 공개/비공개 설정 – java

타 Front End Site에서 SunarQube 화면을 구현할 경우
프로젝트(components) 목록중 공개/비공개 설정을 할경우 SonarQube 로그인과정을 거치게 되며
로그인후 프로젝트(components) 를 public/private 상태로 변경이 가능합니다.

아래는 java로 구현한 간단한 예제입니다.

		CloseableHttpClient httpClient = HttpClients.createDefault();
		String result = "false";
		
		try {
			String projectId = "java_project";
			String visibility = "private";
			String projectUrl = "http://localhost/sonarqube/api/projects/update_visibility";
			String projectParam = "project="+ projectId + "&visibility=" + visibility;
			
			HttpPost httpPost = new HttpPost( projectUrl + "?" + projectParam );
			httpPost.setEntity(new StringEntity("login post"));
		    UsernamePasswordCredentials creds = new UsernamePasswordCredentials("sonarqubeId", "sonarqubePassword");
		    httpPost.addHeader(new BasicScheme().authenticate(creds, httpPost, null));
		    
			HttpResponse response = httpClient.execute(httpPost);
			
			int httpStatus = response.getStatusLine().getStatusCode();
			if (httpStatus >= 200 && httpStatus < 300) {
				result = "true";
			} else {
				throw new ClientProtocolException("Unexpected response status: " + httpStatus);
			}
		} catch (Exception e) {
			logger.error("Error : " + e);
		} finally {
			try {
				httpClient.close();
			} catch (Exception e) {
				logger.error("Error while closing the HTTP client: " + e);
			}
		}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Time limit exceeded. Please complete the captcha once again.

Most Popular