Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sita04 committed Jan 17, 2023
1 parent 6d8386f commit 9caff31
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,36 @@ public static void main(String[] args)

// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: Set a unique id for the CA pool.
// poolId: Set a unique id for the CA pool.
// subordinateCaName: The CA to be activated.
// pemCACertificate: The signed certificate, obtained by signing the CSR.
// pemCaCertificate: The signed certificate, obtained by signing the CSR.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
String poolId = "ca-pool-id";
String subordinateCaName = "subordinate-certificate-authority-name";
String pemCACertificate =
String pemCaCertificate =
"-----BEGIN CERTIFICATE-----\n" + "sample-pem-certificate\n" + "-----END CERTIFICATE-----";

// certificateAuthorityName: The name of the certificate authority which signed the CSR.
// If an external CA (CA not present in Google Cloud) was used for signing,
// then use the CA's issuerCertificateChain.
String certificateAuthorityName = "certificate-authority-name";

activateSubordinateCA(
project, location, pool_Id, certificateAuthorityName, subordinateCaName, pemCACertificate);
activateSubordinateCa(
project, location, poolId, certificateAuthorityName, subordinateCaName, pemCaCertificate);
}

// Activate a subordinate CA.
// *Prerequisite*: Get the CSR of the subordinate CA signed by another CA. Pass in the signed
// certificate and (issuer CA's name or the issuer CA's Certificate chain).
// *Post*: After activating the subordinate CA, it should be enabled before issuing certificates.
public static void activateSubordinateCA(
public static void activateSubordinateCa(
String project,
String location,
String pool_Id,
String poolId,
String certificateAuthorityName,
String subordinateCaName,
String pemCACertificate)
String pemCaCertificate)
throws ExecutionException, InterruptedException, IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand All @@ -75,14 +75,14 @@ public static void activateSubordinateCA(
CertificateAuthorityServiceClient.create()) {
// Subordinate CA parent.
String subordinateCaParent =
CertificateAuthorityName.of(project, location, pool_Id, subordinateCaName).toString();
CertificateAuthorityName.of(project, location, poolId, subordinateCaName).toString();

// Construct the "Activate CA Request".
ActivateCertificateAuthorityRequest activateCertificateAuthorityRequest =
ActivateCertificateAuthorityRequest.newBuilder()
.setName(subordinateCaParent)
// The signed certificate.
.setPemCaCertificate(pemCACertificate)
.setPemCaCertificate(pemCaCertificate)
.setSubordinateConfig(
SubordinateConfig.newBuilder()
// Follow one of the below methods:
Expand All @@ -91,7 +91,7 @@ public static void activateSubordinateCA(
// Name.
.setCertificateAuthority(
CertificateAuthorityName.of(
project, location, pool_Id, certificateAuthorityName)
project, location, poolId, certificateAuthorityName)
.toString())

// Method 2: If issuer CA is external to Google Cloud, set the issuer's
Expand Down
12 changes: 6 additions & 6 deletions privateca/snippets/src/main/java/privateca/CreateCaPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public static void main(String[] args)
// TODO(developer): Replace these variables before running the sample.
// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: Set a unique pool_Id for the CA pool.
// poolId: Set a unique poolId for the CA pool.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
createCaPool(project, location, pool_Id);
String poolId = "ca-pool-id";
createCaPool(project, location, poolId);
}

// Create a Certificate Authority Pool. All certificates created under this CA pool will
// follow the same issuance policy, IAM policies,etc.,
public static void createCaPool(String project, String location, String pool_Id)
public static void createCaPool(String project, String location, String poolId)
throws InterruptedException, ExecutionException, IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand All @@ -69,7 +69,7 @@ Set the Tier (see: https://cloud.google.com/certificate-authority-service/docs/t
CreateCaPoolRequest caPoolRequest =
CreateCaPoolRequest.newBuilder()
.setParent(LocationName.of(project, location).toString())
.setCaPoolId(pool_Id)
.setCaPoolId(poolId)
.setCaPool(
CaPool.newBuilder()
.setIssuancePolicy(issuancePolicy)
Expand All @@ -87,7 +87,7 @@ Set the Tier (see: https://cloud.google.com/certificate-authority-service/docs/t
return;
}

System.out.println("CA pool created successfully: " + pool_Id);
System.out.println("CA pool created successfully: " + poolId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ public static void main(String[] args)
// publicKeyBytes: Public key used in signing the certificates.
// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: Set a unique id for the CA pool.
// poolId: Set a unique id for the CA pool.
// certificateAuthorityName: The name of the certificate authority which issues the certificate.
// certificateName: Set a unique name for the certificate.
String project = "your-project-id";
ByteString publicKeyBytes = ByteString.copyFrom(new byte[]{});
String location = "ca-location";
String pool_Id = "ca-pool_Id";
String poolId = "ca-poolId";
String certificateAuthorityName = "certificate-authority-name";
String certificateName = "certificate-name";

createCertificate(
project, location, pool_Id, certificateAuthorityName, certificateName, publicKeyBytes);
project, location, poolId, certificateAuthorityName, certificateName, publicKeyBytes);
}

// Create a Certificate which is issued by the Certificate Authority present in the CA Pool.
Expand All @@ -68,7 +68,7 @@ public static void main(String[] args)
public static void createCertificate(
String project,
String location,
String pool_Id,
String poolId,
String certificateAuthorityName,
String certificateName,
ByteString publicKeyBytes)
Expand Down Expand Up @@ -134,7 +134,7 @@ public static void createCertificate(
// Create the Certificate Request.
CreateCertificateRequest certificateRequest =
CreateCertificateRequest.newBuilder()
.setParent(CaPoolName.of(project, location, pool_Id).toString())
.setParent(CaPoolName.of(project, location, poolId).toString())
.setCertificateId(certificateName)
.setCertificate(certificate)
.setIssuingCertificateAuthorityId(certificateAuthorityName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ public static void main(String[] args)
// TODO(developer): Replace these variables before running the sample.
// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: Set it to the CA Pool under which the CA should be created.
// poolId: Set it to the CA Pool under which the CA should be created.
// certificateAuthorityName: Unique name for the CA.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
String poolId = "ca-pool-id";
String certificateAuthorityName = "certificate-authority-name";
createCertificateAuthority(project, location, pool_Id, certificateAuthorityName);
createCertificateAuthority(project, location, poolId, certificateAuthorityName);
}

// Create Certificate Authority which is the root CA in the given CA Pool.
public static void createCertificateAuthority(
String project, String location, String pool_Id, String certificateAuthorityName)
String project, String location, String poolId, String certificateAuthorityName)
throws InterruptedException, ExecutionException, IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand Down Expand Up @@ -108,7 +108,7 @@ public static void createCertificateAuthority(
// Create the CertificateAuthorityRequest.
CreateCertificateAuthorityRequest certificateAuthorityRequest =
CreateCertificateAuthorityRequest.newBuilder()
.setParent(CaPoolName.of(project, location, pool_Id).toString())
.setParent(CaPoolName.of(project, location, poolId).toString())
.setCertificateAuthorityId(certificateAuthorityName)
.setCertificateAuthority(certificateAuthority)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,41 @@
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class CreateCertificate_CSR {
public class CreateCertificateCsr {

public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
// TODO(developer): Replace these variables before running the sample.

// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: Set a unique id for the CA pool.
// poolId: Set a unique id for the CA pool.
// certificateAuthorityName: The name of the certificate authority to sign the CSR.
// certificateName: Set a unique name for the certificate.
// pemCSR: Set the Certificate Issuing Request in the pem encoded format.
// pemCsr: Set the Certificate Issuing Request in the pem encoded format.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
String poolId = "ca-pool-id";
String certificateAuthorityName = "certificate-authority-name";
String certificateName = "certificate-name";
String pemCSR =
String pemCsr =
"-----BEGIN CERTIFICATE REQUEST-----\n"
+ "sample-pem-csr-format\n"
+ "-----END CERTIFICATE REQUEST-----";

createCertificateWithCSR(
project, location, pool_Id, certificateAuthorityName, certificateName, pemCSR);
createCertificateWithCsr(
project, location, poolId, certificateAuthorityName, certificateName, pemCsr);
}

// Create a Certificate which is issued by the specified Certificate Authority.
// The certificate details and the public key is provided as a CSR (Certificate Signing Request).
public static void createCertificateWithCSR(
public static void createCertificateWithCsr(
String project,
String location,
String pool_Id,
String poolId,
String certificateAuthorityName,
String certificateName,
String pemCSR)
String pemCsr)
throws IOException, ExecutionException, InterruptedException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand All @@ -76,15 +76,15 @@ public static void createCertificateWithCSR(
// The pemCSR contains the public key and the domain details required.
Certificate certificate =
Certificate.newBuilder()
.setPemCsr(pemCSR)
.setPemCsr(pemCsr)
.setLifetime(Duration.newBuilder().setSeconds(certificateLifetime).build())
.build();

// Create the Certificate Request.
// Set the CA which is responsible for creating the certificate with the provided CSR.
CreateCertificateRequest certificateRequest =
CreateCertificateRequest.newBuilder()
.setParent(CaPoolName.of(project, location, pool_Id).toString())
.setParent(CaPoolName.of(project, location, poolId).toString())
.setIssuingCertificateAuthorityId(certificateAuthorityName)
.setCertificateId(certificateName)
.setCertificate(certificate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ public static void main(String[] args)
// TODO(developer): Replace these variables before running the sample.
// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: Set it to the CA Pool under which the CA should be created.
// poolId: Set it to the CA Pool under which the CA should be created.
// subordinateCaName: Unique name for the Subordinate CA.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
String poolId = "ca-pool-id";
String subordinateCaName = "subordinate-certificate-authority-name";

createSubordinateCertificateAuthority(project, location, pool_Id, subordinateCaName);
createSubordinateCertificateAuthority(project, location, poolId, subordinateCaName);
}

public static void createSubordinateCertificateAuthority(
String project, String location, String pool_Id, String subordinateCaName)
String project, String location, String poolId, String subordinateCaName)
throws IOException, ExecutionException, InterruptedException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand Down Expand Up @@ -111,7 +111,7 @@ public static void createSubordinateCertificateAuthority(
// Create the CertificateAuthorityRequest.
CreateCertificateAuthorityRequest subCertificateAuthorityRequest =
CreateCertificateAuthorityRequest.newBuilder()
.setParent(CaPoolName.of(project, location, pool_Id).toString())
.setParent(CaPoolName.of(project, location, poolId).toString())
.setCertificateAuthorityId(subordinateCaName)
.setCertificateAuthority(subCertificateAuthority)
.build();
Expand Down
16 changes: 8 additions & 8 deletions privateca/snippets/src/main/java/privateca/DeleteCaPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public static void main(String[] args)
// TODO(developer): Replace these variables before running the sample.
// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: The id of the CA pool to be deleted.
// poolId: The id of the CA pool to be deleted.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
deleteCaPool(project, location, pool_Id);
String poolId = "ca-pool-id";
deleteCaPool(project, location, poolId);
}

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

// Set the project, location and pool_Id to delete.
// Set the project, location and poolId to delete.
CaPoolName caPool =
CaPoolName.newBuilder()
.setProject(project)
.setLocation(location)
.setCaPool(pool_Id)
.setCaPool(poolId)
.build();

// Create the Delete request.
Expand All @@ -74,7 +74,7 @@ public static void deleteCaPool(String project, String location, String pool_Id)
return;
}

System.out.println("Deleted CA Pool: " + pool_Id);
System.out.println("Deleted CA Pool: " + poolId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public static void main(String[] args)
// TODO(developer): Replace these variables before running the sample.
// location: For a list of locations, see:
// https://cloud.google.com/certificate-authority-service/docs/locations
// pool_Id: The id of the CA pool under which the CA is present.
// poolId: The id of the CA pool under which the CA is present.
// certificateAuthorityName: The name of the CA to be deleted.
String project = "your-project-id";
String location = "ca-location";
String pool_Id = "ca-pool-id";
String poolId = "ca-pool-id";
String certificateAuthorityName = "certificate-authority-name";
deleteCertificateAuthority(project, location, pool_Id, certificateAuthorityName);
deleteCertificateAuthority(project, location, poolId, certificateAuthorityName);
}

// Delete the Certificate Authority from the specified CA pool.
// Before deletion, the CA must be disabled and must not contain any active certificates.
public static void deleteCertificateAuthority(
String project, String location, String pool_Id, String certificateAuthorityName)
String project, String location, String poolId, String certificateAuthorityName)
throws IOException, ExecutionException, InterruptedException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand All @@ -59,7 +59,7 @@ public static void deleteCertificateAuthority(
CertificateAuthorityName.newBuilder()
.setProject(project)
.setLocation(location)
.setCaPool(pool_Id)
.setCaPool(poolId)
.setCertificateAuthority(certificateAuthorityName)
.build();

Expand Down
Loading

0 comments on commit 9caff31

Please sign in to comment.