in sources/src/main/java/com/google/solutions/jitaccess/apis/clients/PubSubClient.java [58:97]
public String publish(
@NotNull PubSubTopic topic,
@NotNull PubsubMessage message
) throws AccessException, IOException {
var client = createClient();
try {
var request = new PublishRequest();
request.setMessages(List.of(message));
var result = client
.projects()
.topics()
.publish(topic.getFullResourceName(), request)
.execute();
if (result.getMessageIds()
.isEmpty()){
throw new IOException(
String.format("Publishing message to topic %s returned empty response", topic));
}
return result.getMessageIds().get(0);
}
catch (GoogleJsonResponseException e) {
switch (e.getStatusCode()) {
case 401:
throw new NotAuthenticatedException("Not authenticated", e);
case 403:
case 404:
throw new AccessDeniedException(
String.format(
"Pub/Sub topic '%s' cannot be accessed or does not exist: %s",
topic,
e.getMessage()),
e);
default:
throw (GoogleJsonResponseException)e.fillInStackTrace();
}
}
}