aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-alm-client/src/main/java/org/sonar/alm/client/ApplicationHttpClient.java
blob: a5b1e5577be97e6ba5d8d2ab3eab0c49e66fec4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * SonarQube
 * Copyright (C) 2009-2025 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.alm.client;

import java.io.IOException;
import java.util.Optional;
import org.sonar.auth.github.security.AccessToken;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;

@ServerSide
@ComputeEngineSide
public interface ApplicationHttpClient {
  /**
   * Content of the response is populated if response's HTTP code is {@link java.net.HttpURLConnection#HTTP_OK OK}.
   */
  GetResponse get(String appUrl, AccessToken token, String endPoint) throws IOException;

  /**
   * Content of the response is populated if response's HTTP code is {@link java.net.HttpURLConnection#HTTP_OK OK}.
   * No log if there is an issue during the call.
   */
  GetResponse getSilent(String appUrl, AccessToken token, String endPoint) throws IOException;

  /**
   * Content of the response is populated if response's HTTP code is {@link java.net.HttpURLConnection#HTTP_OK OK} or
   * {@link java.net.HttpURLConnection#HTTP_CREATED CREATED}.
   */
  Response post(String appUrl, AccessToken token, String endPoint) throws IOException;

  /**
   * Content of the response is populated if response's HTTP code is {@link java.net.HttpURLConnection#HTTP_OK OK} or
   * {@link java.net.HttpURLConnection#HTTP_CREATED CREATED}.
   *
   * Content type will be application/json; charset=utf-8
   */
  Response post(String appUrl, AccessToken token, String endPoint, String json) throws IOException;

  /**
   * Content of the response is populated if response's HTTP code is {@link java.net.HttpURLConnection#HTTP_OK OK}.
   *
   * Content type will be application/json; charset=utf-8
   */
  Response patch(String appUrl, AccessToken token, String endPoint, String json) throws IOException;

  /**
   * Content of the response is populated if response's HTTP code is {@link java.net.HttpURLConnection#HTTP_OK OK}.
   *
   * Content type will be application/json; charset=utf-8
   *
   */
  Response delete(String appUrl, AccessToken token, String endPoint) throws IOException;

  record RateLimit(int remaining, int limit, long reset) {
  }
  interface Response {

    /**
     * @return the HTTP code of the response.
     */
    int getCode();

    /**
     * @return the content of the response if the response had an HTTP code for which we expect a content for the current
     *         HTTP method (see {@link #get(String, AccessToken, String)} and {@link #post(String, AccessToken, String)}).
     */
    Optional<String> getContent();

    RateLimit getRateLimit();
  }

  interface GetResponse extends Response {
    Optional<String> getNextEndPoint();
  }

}