Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ jobs:
--batch-mode \
--no-transfer-progress

showcase-native:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
with:
version: '22.3.2'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: mvn -version
- run: native-image --version
- name: Install sdk-platform-java
run: mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
- name: Install showcase server
run: |
sudo mkdir -p /usr/src/showcase
sudo chown -R ${USER} /usr/src/
curl --location https://github.com/googleapis/gapic-showcase/releases/download/v${SHOWCASE_VERSION}/gapic-showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz --output /usr/src/showcase/showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz
cd /usr/src/showcase/
tar -xf showcase-*
./gapic-showcase run &
cd -
- name: Build native image
working-directory: showcase
run: mvn test -Pnative,-showcase -ntp -B

showcase-clirr:
if: ${{ github.base_ref != '' }} # Only execute on pull_request trigger event
runs-on: ubuntu-22.04
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@
import com.google.auth.Credentials;
import com.google.auth.oauth2.GdchCredentials;
import com.google.auth.oauth2.GdchCredentialsTestUtil;
import com.google.common.truth.Truth;
import com.google.showcase.v1beta1.EchoClient;
import com.google.showcase.v1beta1.EchoSettings;
import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory;
import com.google.showcase.v1beta1.stub.EchoStub;
import com.google.showcase.v1beta1.it.util.TestClientInitializer;
import com.google.showcase.v1beta1.stub.EchoStubSettings;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -53,10 +56,11 @@
*/
public class ITGdch {

private static final String TEST_GDCH_CREDENTIAL_FILE = "/test_gdch_credential.json";
private static final String CA_CERT_RESOURCE_PATH = "/fake_cert.pem";
private static final String CA_CERT_FILENAME = "fake_cert.pem";
private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME;
private static final String CA_CERT_JSON_KEY = "ca_cert_path";
private static final String TEMP_CREDENTIAL_JSON_FILENAME = "temp_gdch_credential.json";
private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json";
private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME;
private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2";
private static final String SID_NAME = "service-identity-name";

Expand All @@ -67,7 +71,6 @@ public class ITGdch {
private EchoStubSettings stubSettings;
private Credentials initialCredentials;
private ClientContext context;
private EchoStub stub;
private InterceptingMockTokenServerTransportFactory transportFactory;
private String projectId;
private URI tokenUri;
Expand All @@ -76,37 +79,44 @@ public class ITGdch {
public void setup() throws IOException, URISyntaxException {
transportFactory = new InterceptingMockTokenServerTransportFactory();
prepareCredentials();
tempFolder.create();
settings =
EchoSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials))
.build();
}

@After
public void tearDown() {
public void tearDown() throws InterruptedException {
if (client != null) {
client.close();
client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
}
}

private void prepareCredentials() throws IOException, URISyntaxException {
// compute absolute path of the CA certificate
Path caCertPath = Paths.get(getClass().getResource(CA_CERT_RESOURCE_PATH).toURI());
private void prepareCredentials() throws IOException {
// Copy file so it can be referenced by Path even in native-image builds
File caCertFile = tempFolder.newFile(CA_CERT_FILENAME);
try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) {
Truth.assertThat(inputStream).isNotNull();
Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
Truth.assertWithMessage(caCertFile.toPath() + " should exist")
.that(caCertFile.exists())
.isTrue();

// open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate
// obtained from above)
JsonFactory factory = new GsonFactory();
GenericJson converted =
factory.fromInputStream(
getClass().getResourceAsStream(TEST_GDCH_CREDENTIAL_FILE), GenericJson.class);
getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class);

// modify and save to a temporary folder
converted.set(CA_CERT_JSON_KEY, caCertPath.toAbsolutePath().toString());
converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString());
projectId = converted.get("project").toString();
tokenUri = URI.create(converted.get("token_uri").toString());

File tempGdchCredentialFile = tempFolder.newFile(TEMP_CREDENTIAL_JSON_FILENAME);
File tempGdchCredentialFile = tempFolder.newFile(GDCH_CREDENTIAL_FILENAME);
try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) {
String preparedJson = converted.toPrettyString();
fileWriter.write(preparedJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"resources":[{"pattern": ".*.json"}]
"resources": [
{ "pattern": ".*.json" },
{ "pattern": ".*.pem" }
]
}