Skip to content

Commit fdf198f

Browse files
Sita04sitalakshmisgcf-owl-bot[bot]
committed
docs: client sample docs update (#219)
* docs: update comments * docs: update comments * (docs): Adding README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * docs: updated README.md * refactor: replaced POOL_NAME with POOL_ID to align with cloud docs. * docs: lint fix * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md Co-authored-by: sitalakshmis <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent ea7843d commit fdf198f

13 files changed

+159
-86
lines changed

privateca/cloud-client/README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Google Cloud Private Certificate Authority Service
2+
3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-security-private-ca&page=editor&open_in_editor=samples/snippets/cloud-client/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
Google [Cloud Private Certificate Authority Service](https://cloud.google.com/certificate-authority-service) is a highly available, scalable Google Cloud service that enables you to simplify, automate, and customize the deployment, management, and security of private certificate authorities (CA).
7+
8+
These sample Java applications demonstrate how to access the Cloud CA API using the
9+
Google Java API Client Libraries.
10+
11+
## Prerequisites
12+
13+
### Google Cloud Project
14+
15+
Set up a Google Cloud project with billing enabled.
16+
17+
### Enable the API
18+
19+
You must [enable the Google Private Certificate Authority Service API](https://console.cloud.google.com/flows/enableapi?apiid=privateca.googleapis.com) for your project in order to use these samples.
20+
21+
### Service account
22+
23+
A service account with private key credentials is required to create signed bearer tokens.
24+
Create a [service account](https://console.cloud.google.com/iam-admin/serviceaccounts/create) and download the credentials file as JSON.
25+
26+
### Set Environment Variables
27+
28+
You must set your project ID and service account credentials in order to run the tests.
29+
30+
```
31+
$ export GOOGLE_CLOUD_PROJECT="<google-project-id-here>"
32+
$ export GOOGLE_APPLICATION_CREDENTIALS="<path-to-service-account-credentials-file>"
33+
```
34+
35+
### Grant Permissions
36+
37+
You must ensure that the [user account or service account](https://cloud.google.com/iam/docs/service-accounts#differences_between_a_service_account_and_a_user_account) you used to authorize your gcloud session has the proper permissions to edit Private CA resources for your project. In the Cloud Console under IAM, add the following roles to the project whose service account you're using to test:
38+
39+
* Cloud CA Service Admin
40+
* Cloud CA Service Certificate Requester
41+
* Cloud CA Service Certificate Manager
42+
* Cloud CA Service Certificate Template User
43+
* Cloud CA Service Workload Certificate Requester
44+
* Cloud CA Service Operation Manager
45+
* Cloud CA Service Auditor
46+
47+
More information can be found in the [Google Private Certificate Authority Service Docs](https://cloud.google.com/certificate-authority-service/docs/reference/permissions-and-roles).
48+
49+
50+
## Build and Run
51+
52+
The following instructions will help you prepare your development environment.
53+
54+
1. Download and install the [Java Development Kit (JDK)](https://www.oracle.com/java/technologies/javase-downloads.html).
55+
Verify that the [JAVA_HOME](https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars001.html) environment variable is set and points to your JDK installation.
56+
57+
58+
2. Download and install [Apache Maven](http://maven.apache.org/download.cgi) by following the [Maven installation guide](http://maven.apache.org/install.html) for your specific operating system.
59+
60+
61+
3. Clone the java-security-private-ca repository.
62+
```
63+
git clone https://github.com/googleapis/java-security-private-ca.git
64+
```
65+
66+
4. Navigate to the sample code directory.
67+
68+
```
69+
cd java-security-private-ca/samples/snippets/cloud-client
70+
```
71+
72+
5. Run the **SnippetsIT** test file present under the test folder.
73+
74+
### Crypto frameworks
75+
[Bouncy Castle](https://www.bouncycastle.org/documentation.html) cryptographic framework is used as a part of testing.

privateca/cloud-client/src/main/java/privateca/CreateCaPool.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ public static void main(String[] args)
3434
// TODO(developer): Replace these variables before running the sample.
3535
// location: For a list of locations, see:
3636
// https://cloud.google.com/certificate-authority-service/docs/locations
37-
// caPoolName: Set a unique name for the CA pool.
37+
// pool_Id: Set a unique pool_Id for the CA pool.
3838
String project = "your-project-id";
3939
String location = "ca-location";
40-
String caPoolName = "ca-pool-name";
41-
createCaPool(project, location, caPoolName);
40+
String pool_Id = "ca-pool-id";
41+
createCaPool(project, location, pool_Id);
4242
}
4343

4444
// Create a Certificate Authority Pool. All certificates created under this CA pool will
4545
// follow the same issuance policy, IAM policies,etc.,
46-
public static void createCaPool(String project, String location, String caPoolName)
46+
public static void createCaPool(String project, String location, String pool_Id)
4747
throws InterruptedException, ExecutionException, IOException {
4848
// Initialize client that will be used to send requests. This client only needs to be created
4949
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -59,7 +59,7 @@ Set the Tier (see: https://cloud.google.com/certificate-authority-service/docs/t
5959
CreateCaPoolRequest caPoolRequest =
6060
CreateCaPoolRequest.newBuilder()
6161
.setParent(LocationName.of(project, location).toString())
62-
.setCaPoolId(caPoolName)
62+
.setCaPoolId(pool_Id)
6363
.setCaPool(CaPool.newBuilder().setTier(Tier.ENTERPRISE).build())
6464
.build();
6565

@@ -73,7 +73,7 @@ Set the Tier (see: https://cloud.google.com/certificate-authority-service/docs/t
7373
return;
7474
}
7575

76-
System.out.println("CA pool created successfully: " + caPoolName);
76+
System.out.println("CA pool created successfully: " + pool_Id);
7777
}
7878
}
7979
}

privateca/cloud-client/src/main/java/privateca/CreateCertificate.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ public static void main(String[] args)
4747
// publicKeyBytes: Public key used in signing the certificates.
4848
// location: For a list of locations, see:
4949
// https://cloud.google.com/certificate-authority-service/docs/locations
50-
// caPoolName: Set a unique name for the CA pool.
50+
// pool_Id: Set a unique id for the CA pool.
5151
// certificateAuthorityName: The name of the certificate authority which issues the certificate.
5252
// certificateName: Set a unique name for the certificate.
5353
String project = "your-project-id";
5454
ByteString publicKeyBytes = ByteString.copyFrom(new byte[] {});
5555
String location = "ca-location";
56-
String caPoolName = "ca-pool-name";
56+
String pool_Id = "ca-pool_Id";
5757
String certificateAuthorityName = "certificate-authority-name";
5858
String certificateName = "certificate-name";
5959

6060
createCertificate(
61-
project, location, caPoolName, certificateAuthorityName, certificateName, publicKeyBytes);
61+
project, location, pool_Id, certificateAuthorityName, certificateName, publicKeyBytes);
6262
}
6363

6464
// Create a Certificate which is issued by the Certificate Authority present in the CA Pool.
@@ -67,7 +67,7 @@ public static void main(String[] args)
6767
public static void createCertificate(
6868
String project,
6969
String location,
70-
String caPoolName,
70+
String pool_Id,
7171
String certificateAuthorityName,
7272
String certificateName,
7373
ByteString publicKeyBytes)
@@ -133,7 +133,7 @@ public static void createCertificate(
133133
// Create the Certificate Request.
134134
CreateCertificateRequest certificateRequest =
135135
CreateCertificateRequest.newBuilder()
136-
.setParent(CaPoolName.of(project, location, caPoolName).toString())
136+
.setParent(CaPoolName.of(project, location, pool_Id).toString())
137137
.setCertificateId(certificateName)
138138
.setCertificate(certificate)
139139
.setIssuingCertificateAuthorityId(certificateAuthorityName)

privateca/cloud-client/src/main/java/privateca/CreateCertificateAuthority.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,18 @@ public static void main(String[] args)
4343
// TODO(developer): Replace these variables before running the sample.
4444
// location: For a list of locations, see:
4545
// https://cloud.google.com/certificate-authority-service/docs/locations
46-
// caPoolName: Set it to the CA Pool under which the CA should be created.
46+
// pool_Id: Set it to the CA Pool under which the CA should be created.
4747
// certificateAuthorityName: Unique name for the CA.
4848
String project = "your-project-id";
4949
String location = "ca-location";
50-
String caPoolName = "ca-pool-name";
50+
String pool_Id = "ca-pool-id";
5151
String certificateAuthorityName = "certificate-authority-name";
52-
createCertificateAuthority(project, location, caPoolName, certificateAuthorityName);
52+
createCertificateAuthority(project, location, pool_Id, certificateAuthorityName);
5353
}
5454

55-
// Create Certificate Authority which is the root CA in the given CA Pool. This CA will be
56-
// responsible for signing certificates within this pool.
55+
// Create Certificate Authority which is the root CA in the given CA Pool.
5756
public static void createCertificateAuthority(
58-
String project, String location, String caPoolName, String certificateAuthorityName)
57+
String project, String location, String pool_Id, String certificateAuthorityName)
5958
throws InterruptedException, ExecutionException, IOException {
6059
// Initialize client that will be used to send requests. This client only needs to be created
6160
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -68,7 +67,7 @@ public static void createCertificateAuthority(
6867
String orgName = "org-name";
6968
int caDuration = 100000; // Validity of this CA in seconds.
7069

71-
// Set the types of Algorithm used to create a cloud KMS key.
70+
// Set the type of Algorithm.
7271
KeyVersionSpec keyVersionSpec =
7372
KeyVersionSpec.newBuilder().setAlgorithm(SignHashAlgorithm.RSA_PKCS1_4096_SHA256).build();
7473

@@ -108,7 +107,7 @@ public static void createCertificateAuthority(
108107
// Create the CertificateAuthorityRequest.
109108
CreateCertificateAuthorityRequest certificateAuthorityRequest =
110109
CreateCertificateAuthorityRequest.newBuilder()
111-
.setParent(CaPoolName.of(project, location, caPoolName).toString())
110+
.setParent(CaPoolName.of(project, location, pool_Id).toString())
112111
.setCertificateAuthorityId(certificateAuthorityName)
113112
.setCertificateAuthority(certificateAuthority)
114113
.build();

privateca/cloud-client/src/main/java/privateca/DeleteCaPool.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ public static void main(String[] args)
3333
// TODO(developer): Replace these variables before running the sample.
3434
// location: For a list of locations, see:
3535
// https://cloud.google.com/certificate-authority-service/docs/locations
36-
// caPoolName: The name of the CA pool to be deleted.
36+
// pool_Id: The id of the CA pool to be deleted.
3737
String project = "your-project-id";
3838
String location = "ca-location";
39-
String caPoolName = "ca-pool-name";
40-
deleteCaPool(project, location, caPoolName);
39+
String pool_Id = "ca-pool-id";
40+
deleteCaPool(project, location, pool_Id);
4141
}
4242

43-
// Delete the CA pool as mentioned by the caPoolName.
43+
// Delete the CA pool as mentioned by the pool_Id.
4444
// Before deleting the pool, all CAs in the pool MUST BE deleted.
45-
public static void deleteCaPool(String project, String location, String caPoolName)
45+
public static void deleteCaPool(String project, String location, String pool_Id)
4646
throws InterruptedException, ExecutionException, IOException {
4747
// Initialize client that will be used to send requests. This client only needs to be created
4848
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -51,12 +51,12 @@ public static void deleteCaPool(String project, String location, String caPoolNa
5151
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient =
5252
CertificateAuthorityServiceClient.create()) {
5353

54-
// Set the project, location and caPoolName to delete.
54+
// Set the project, location and pool_Id to delete.
5555
CaPoolName caPool =
5656
CaPoolName.newBuilder()
5757
.setProject(project)
5858
.setLocation(location)
59-
.setCaPool(caPoolName)
59+
.setCaPool(pool_Id)
6060
.build();
6161

6262
// Create the Delete request.
@@ -73,7 +73,7 @@ public static void deleteCaPool(String project, String location, String caPoolNa
7373
return;
7474
}
7575

76-
System.out.println("Deleted CA Pool: " + caPoolName);
76+
System.out.println("Deleted CA Pool: " + pool_Id);
7777
}
7878
}
7979
}

privateca/cloud-client/src/main/java/privateca/DeleteCertificateAuthority.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public static void main(String[] args)
3333
// TODO(developer): Replace these variables before running the sample.
3434
// location: For a list of locations, see:
3535
// https://cloud.google.com/certificate-authority-service/docs/locations
36-
// caPoolName: The name of the CA pool under which the CA is present.
36+
// pool_Id: The id of the CA pool under which the CA is present.
3737
// certificateAuthorityName: The name of the CA to be deleted.
3838
String project = "your-project-id";
3939
String location = "ca-location";
40-
String caPoolName = "ca-pool-name";
40+
String pool_Id = "ca-pool-id";
4141
String certificateAuthorityName = "certificate-authority-name";
42-
deleteCertificateAuthority(project, location, caPoolName, certificateAuthorityName);
42+
deleteCertificateAuthority(project, location, pool_Id, certificateAuthorityName);
4343
}
4444

4545
// Delete the Certificate Authority from the specified CA pool.
4646
// Before deletion, the CA must be disabled and must not contain any active certificates.
4747
public static void deleteCertificateAuthority(
48-
String project, String location, String caPoolName, String certificateAuthorityName)
48+
String project, String location, String pool_Id, String certificateAuthorityName)
4949
throws IOException, ExecutionException, InterruptedException {
5050
// Initialize client that will be used to send requests. This client only needs to be created
5151
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -58,7 +58,7 @@ public static void deleteCertificateAuthority(
5858
CertificateAuthorityName.newBuilder()
5959
.setProject(project)
6060
.setLocation(location)
61-
.setCaPool(caPoolName)
61+
.setCaPool(pool_Id)
6262
.setCertificateAuthority(certificateAuthorityName)
6363
.build();
6464

privateca/cloud-client/src/main/java/privateca/DisableCertificateAuthority.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ public static void main(String[] args)
3333
// TODO(developer): Replace these variables before running the sample.
3434
// location: For a list of locations, see:
3535
// https://cloud.google.com/certificate-authority-service/docs/locations
36-
// caPoolName: The name of the CA pool under which the CA is present.
36+
// pool_Id: The id of the CA pool under which the CA is present.
3737
// certificateAuthorityName: The name of the CA to be disabled.
3838
String project = "your-project-id";
3939
String location = "ca-location";
40-
String caPoolName = "ca-pool-name";
40+
String pool_Id = "ca-pool-id";
4141
String certificateAuthorityName = "certificate-authority-name";
42-
disableCertificateAuthority(project, location, caPoolName, certificateAuthorityName);
42+
disableCertificateAuthority(project, location, pool_Id, certificateAuthorityName);
4343
}
4444

4545
// Disable a Certificate Authority which is present in the given CA pool.
4646
public static void disableCertificateAuthority(
47-
String project, String location, String caPoolName, String certificateAuthorityName)
47+
String project, String location, String pool_Id, String certificateAuthorityName)
4848
throws IOException, ExecutionException, InterruptedException {
4949
// Initialize client that will be used to send requests. This client only needs to be created
5050
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -58,7 +58,7 @@ public static void disableCertificateAuthority(
5858
CertificateAuthorityName.newBuilder()
5959
.setProject(project)
6060
.setLocation(location)
61-
.setCaPool(caPoolName)
61+
.setCaPool(pool_Id)
6262
.setCertificateAuthority(certificateAuthorityName)
6363
.build();
6464

privateca/cloud-client/src/main/java/privateca/EnableCertificateAuthority.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public static void main(String[] args)
3333
// TODO(developer): Replace these variables before running the sample.
3434
// location: For a list of locations, see:
3535
// https://cloud.google.com/certificate-authority-service/docs/locations
36-
// caPoolName: The name of the CA pool under which the CA is present.
36+
// pool_Id: The id of the CA pool under which the CA is present.
3737
// certificateAuthorityName: The name of the CA to be enabled.
3838
String project = "your-project-id";
3939
String location = "ca-location";
40-
String caPoolName = "ca-pool-name";
40+
String pool_Id = "ca-pool-id";
4141
String certificateAuthorityName = "certificate-authority-name";
42-
enableCertificateAuthority(project, location, caPoolName, certificateAuthorityName);
42+
enableCertificateAuthority(project, location, pool_Id, certificateAuthorityName);
4343
}
4444

4545
// Enable the Certificate Authority present in the given ca pool.
4646
// CA cannot be enabled if it has been already deleted.
4747
public static void enableCertificateAuthority(
48-
String project, String location, String caPoolName, String certificateAuthorityName)
48+
String project, String location, String pool_Id, String certificateAuthorityName)
4949
throws IOException, ExecutionException, InterruptedException {
5050
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient =
5151
CertificateAuthorityServiceClient.create()) {
@@ -54,7 +54,7 @@ public static void enableCertificateAuthority(
5454
CertificateAuthorityName.newBuilder()
5555
.setProject(project)
5656
.setLocation(location)
57-
.setCaPool(caPoolName)
57+
.setCaPool(pool_Id)
5858
.setCertificateAuthority(certificateAuthorityName)
5959
.build();
6060

privateca/cloud-client/src/main/java/privateca/ListCaPools.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public static void listCaPools(String project, String location) throws IOExcepti
5454
certificateAuthorityServiceClient.listCaPools(locationName).iterateAll()) {
5555
caPoolName = caPool.getName();
5656
// caPoolName represents the full resource name of the
57-
// format 'projects/{project-id}/locations/{location}/ca-pools/{ca-pool-name}'.
58-
// Hence stripping it down to just pool name.
57+
// format 'projects/{project-id}/locations/{location}/ca-pools/{ca-pool-id}'.
58+
// Hence stripping it down to just CA pool id.
5959
System.out.println(
6060
caPoolName.substring(caPoolName.lastIndexOf("/") + 1) + " " + caPool.isInitialized());
6161
}

privateca/cloud-client/src/main/java/privateca/ListCertificateAuthorities.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public static void main(String[] args) throws IOException {
2828
// TODO(developer): Replace these variables before running the sample.
2929
// location: For a list of locations, see:
3030
// https://cloud.google.com/certificate-authority-service/docs/locations
31-
// caPoolName: The name of the CA pool under which the CAs to be listed are present.
31+
// pool_Id: The id of the CA pool under which the CAs to be listed are present.
3232
String project = "your-project-id";
3333
String location = "ca-location";
34-
String caPoolName = "ca-pool-name";
35-
listCertificateAuthority(project, location, caPoolName);
34+
String pool_Id = "ca-pool-id";
35+
listCertificateAuthority(project, location, pool_Id);
3636
}
3737

3838
// List all Certificate authorities present in the given CA Pool.
39-
public static void listCertificateAuthority(String project, String location, String caPoolName)
39+
public static void listCertificateAuthority(String project, String location, String pool_Id)
4040
throws IOException {
4141
// Initialize client that will be used to send requests. This client only needs to be created
4242
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -50,7 +50,7 @@ public static void listCertificateAuthority(String project, String location, Str
5050
CaPoolName.newBuilder()
5151
.setProject(project)
5252
.setLocation(location)
53-
.setCaPool(caPoolName)
53+
.setCaPool(pool_Id)
5454
.build();
5555

5656
// List the CA name and its corresponding state.

0 commit comments

Comments
 (0)