use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project gapic-generator-java by googleapis.
the class SyncSignBlobStringListstringBytestring method syncSignBlobStringListstringBytestring.
public static void syncSignBlobStringListstringBytestring() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
String name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString();
List<String> delegates = new ArrayList<>();
ByteString payload = ByteString.EMPTY;
SignBlobResponse response = iamCredentialsClient.signBlob(name, delegates, payload);
}
}
use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project gapic-generator-java by googleapis.
the class SyncCreateSetEndpoint method syncCreateSetEndpoint.
public static void syncCreateSetEndpoint() throws Exception {
// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
IamCredentialsSettings iamCredentialsSettings = IamCredentialsSettings.newBuilder().setEndpoint(myEndpoint).build();
IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create(iamCredentialsSettings);
}
use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project gapic-generator-java by googleapis.
the class AsyncGenerateAccessToken method asyncGenerateAccessToken.
public static void asyncGenerateAccessToken() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
GenerateAccessTokenRequest request = GenerateAccessTokenRequest.newBuilder().setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString()).addAllDelegates(new ArrayList<String>()).addAllScope(new ArrayList<String>()).setLifetime(Duration.newBuilder().build()).build();
ApiFuture<GenerateAccessTokenResponse> future = iamCredentialsClient.generateAccessTokenCallable().futureCall(request);
// Do something.
GenerateAccessTokenResponse response = future.get();
}
}
use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project gapic-generator-java by googleapis.
the class SyncGenerateAccessTokenServiceaccountnameListstringListstringDuration method syncGenerateAccessTokenServiceaccountnameListstringListstringDuration.
public static void syncGenerateAccessTokenServiceaccountnameListstringListstringDuration() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
List<String> delegates = new ArrayList<>();
List<String> scope = new ArrayList<>();
Duration lifetime = Duration.newBuilder().build();
GenerateAccessTokenResponse response = iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
}
}
use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project styx by spotify.
the class ServiceAccountUsageAuthorizer method create.
static ServiceAccountUsageAuthorizer create(Closer closer, String serviceAccountUserRole, AuthorizationPolicy authorizationPolicy, GoogleCredentials credentials, String gsuiteUserEmail, String serviceName, String message, List<String> administrators, List<String> blacklist) {
final HttpTransport httpTransport;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final CloudResourceManager crm = new CloudResourceManager.Builder(httpTransport, jsonFactory, new HttpCredentialsAdapter(credentials.createScoped(IamScopes.all()))).setApplicationName(serviceName).build();
final Iam iam = new Iam.Builder(httpTransport, jsonFactory, new HttpCredentialsAdapter(credentials.createScoped(IamScopes.all()))).setApplicationName(serviceName).build();
final IamCredentialsClient iamCredentialsClient;
try {
iamCredentialsClient = IamCredentialsClient.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
closer.register(iamCredentialsClient::close);
final GoogleCredential directoryCredential = new ManagedServiceAccountKeyCredential.Builder(iamCredentialsClient).setServiceAccountId(ServiceAccounts.serviceAccountEmail(credentials)).setServiceAccountUser(gsuiteUserEmail).setServiceAccountScopes(Set.of(ADMIN_DIRECTORY_GROUP_MEMBER_READONLY)).build();
final Directory directory = new Directory.Builder(httpTransport, jsonFactory, directoryCredential).setApplicationName(serviceName).build();
return new Impl(iam, crm, directory, serviceAccountUserRole, authorizationPolicy, Impl.DEFAULT_WAIT_STRATEGY, Impl.DEFAULT_RETRY_STOP_STRATEGY, message, administrators, blacklist);
}
Aggregations