Search in sources :

Example 6 with IamCredentialsClient

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);
    }
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ByteString(com.google.protobuf.ByteString) SignBlobResponse(com.google.cloud.iam.credentials.v1.SignBlobResponse)

Example 7 with IamCredentialsClient

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);
}
Also used : IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) IamCredentialsSettings(com.google.cloud.iam.credentials.v1.IamCredentialsSettings)

Example 8 with IamCredentialsClient

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();
    }
}
Also used : ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) GenerateAccessTokenResponse(com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse) GenerateAccessTokenRequest(com.google.cloud.iam.credentials.v1.GenerateAccessTokenRequest)

Example 9 with IamCredentialsClient

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);
    }
}
Also used : ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName) Duration(com.google.protobuf.Duration) GenerateAccessTokenResponse(com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse)

Example 10 with IamCredentialsClient

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);
}
Also used : HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) CloudResourceManager(com.google.api.services.cloudresourcemanager.CloudResourceManager) GeneralSecurityException(java.security.GeneralSecurityException) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) JsonFactory(com.google.api.client.json.JsonFactory) IOException(java.io.IOException) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) Iam(com.google.api.services.iam.v1.Iam) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) Directory(com.google.api.services.directory.Directory)

Aggregations

IamCredentialsClient (com.google.cloud.iam.credentials.v1.IamCredentialsClient)21 ArrayList (java.util.ArrayList)11 ServiceAccountName (com.google.cloud.iam.credentials.v1.ServiceAccountName)5 SignJwtResponse (com.google.cloud.iam.credentials.v1.SignJwtResponse)5 GenerateIdTokenResponse (com.google.cloud.iam.credentials.v1.GenerateIdTokenResponse)4 SignBlobResponse (com.google.cloud.iam.credentials.v1.SignBlobResponse)4 ByteString (com.google.protobuf.ByteString)4 GenerateAccessTokenResponse (com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse)3 IamCredentialsSettings (com.google.cloud.iam.credentials.v1.IamCredentialsSettings)3 HttpTransport (com.google.api.client.http.HttpTransport)2 GenerateIdTokenRequest (com.google.cloud.iam.credentials.v1.GenerateIdTokenRequest)2 SignBlobRequest (com.google.cloud.iam.credentials.v1.SignBlobRequest)2 SignJwtRequest (com.google.cloud.iam.credentials.v1.SignJwtRequest)2 Duration (com.google.protobuf.Duration)2 IOException (java.io.IOException)2 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1