本文整理汇总了Java中com.google.api.services.iam.v1.Iam类的典型用法代码示例。如果您正苦于以下问题:Java Iam类的具体用法?Java Iam怎么用?Java Iam使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Iam类属于com.google.api.services.iam.v1包,在下文中一共展示了Iam类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServiceAccountsApiStub
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
/**
* Get the API stub for accessing the IAM Service Accounts API.
* @return ServiceAccounts api stub for accessing the IAM Service Accounts API.
* @throws IOException Thrown if there's an IO error initializing the api connection.
* @throws GeneralSecurityException Thrown if there's a security error
* initializing the connection.
*/
public static ServiceAccounts getServiceAccountsApiStub() throws IOException, GeneralSecurityException {
if (serviceAccountsApiStub == null) {
HttpTransport transport;
GoogleCredential credential;
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
transport = GoogleNetHttpTransport.newTrustedTransport();
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = IamScopes.all();
credential = credential.createScoped(scopes);
}
serviceAccountsApiStub = new Iam.Builder(transport, jsonFactory, credential)
.build()
.projects()
.serviceAccounts();
}
return serviceAccountsApiStub;
}
示例2: createServiceAccountKeyManager
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
private static ServiceAccountKeyManager createServiceAccountKeyManager() {
try {
final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final GoogleCredential credential = GoogleCredential
.getApplicationDefault(httpTransport, jsonFactory)
.createScoped(IamScopes.all());
final Iam iam = new Iam.Builder(
httpTransport, jsonFactory, credential)
.setApplicationName(SERVICE_NAME)
.build();
return new ServiceAccountKeyManager(iam);
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
}
示例3: setUp
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
keyFile = tempFolder.getRoot().toPath().resolve("key.json");
Iam iam = mock(Iam.class);
Projects projects = mock(Projects.class);
ServiceAccounts serviceAccounts = mock(ServiceAccounts.class);
when(apiFactory.newIamApi(any(Credential.class))).thenReturn(iam);
when(iam.projects()).thenReturn(projects);
when(projects.serviceAccounts()).thenReturn(serviceAccounts);
when(serviceAccounts.keys()).thenReturn(keys);
when(keys.create(
eq("projects/my-project/serviceAccounts/[email protected]"),
any(CreateServiceAccountKeyRequest.class))).thenReturn(create);
ServiceAccountKey serviceAccountKey = new ServiceAccountKey();
byte[] keyContent = "key data in JSON format".getBytes(StandardCharsets.UTF_8);
serviceAccountKey.setPrivateKeyData(Base64.encodeBase64String(keyContent));
when(create.execute()).thenReturn(serviceAccountKey);
}
示例4: setUpServiceKeyCreation
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
private static void setUpServiceKeyCreation(
IGoogleApiFactory mockApiFactory, boolean throwException) throws IOException {
Iam iam = Mockito.mock(Iam.class);
Projects projects = Mockito.mock(Projects.class);
ServiceAccounts serviceAccounts = Mockito.mock(ServiceAccounts.class);
Keys keys = Mockito.mock(Keys.class);
Create create = Mockito.mock(Create.class);
ServiceAccountKey serviceAccountKey = new ServiceAccountKey();
byte[] keyContent = "key data in JSON format".getBytes();
serviceAccountKey.setPrivateKeyData(Base64.encodeBase64String(keyContent));
when(mockApiFactory.newIamApi(any(Credential.class))).thenReturn(iam);
when(iam.projects()).thenReturn(projects);
when(projects.serviceAccounts()).thenReturn(serviceAccounts);
when(serviceAccounts.keys()).thenReturn(keys);
when(keys.create(anyString(), Matchers.any(CreateServiceAccountKeyRequest.class)))
.thenReturn(create);
if (throwException) {
when(create.execute()).thenThrow(new IOException("log from unit test"));
} else {
when(create.execute()).thenReturn(serviceAccountKey);
}
}
示例5: createAppEngineDefaultServiceAccountKey
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
/**
* Creates and saves a service account key the App Engine default service account.
*
* @param credential credential to use to create a service account key
* @param projectId GCP project ID for {@code serviceAccountId}
* @param destination path of a key file to be saved
*/
public static void createAppEngineDefaultServiceAccountKey(IGoogleApiFactory apiFactory,
Credential credential, String projectId, Path destination)
throws FileAlreadyExistsException, IOException {
Preconditions.checkNotNull(credential, "credential not given");
Preconditions.checkState(!projectId.isEmpty(), "project ID empty");
Preconditions.checkArgument(destination.isAbsolute(), "destination not absolute");
if (!Files.exists(destination.getParent())) {
Files.createDirectories(destination.getParent());
}
Iam iam = apiFactory.newIamApi(credential);
Keys keys = iam.projects().serviceAccounts().keys();
String projectEmail = projectId;
// The appengine service account for google.com:gcloud-for-eclipse-testing
// would be [email protected]m.
if (projectId.contains(":")) {
String[] parts = projectId.split(":");
projectEmail = parts[1] + "." + parts[0];
}
String serviceAccountId = projectEmail + "@appspot.gserviceaccount.com";
String keyId = "projects/" + projectId + "/serviceAccounts/" + serviceAccountId;
CreateServiceAccountKeyRequest createRequest = new CreateServiceAccountKeyRequest();
ServiceAccountKey key = keys.create(keyId, createRequest).execute();
byte[] jsonKey = Base64.decodeBase64(key.getPrivateKeyData());
Files.write(destination, jsonKey);
}
示例6: newIamApi
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
@Override
public Iam newIamApi(Credential credential) {
Preconditions.checkNotNull(transportCache, "transportCache is null");
HttpTransport transport = transportCache.getUnchecked(GoogleApi.IAM_API);
Preconditions.checkNotNull(transport, "transport is null");
Preconditions.checkNotNull(jsonFactory, "jsonFactory is null");
Iam iam = new Iam.Builder(transport, jsonFactory, credential)
.setApplicationName(CloudToolsInfo.USER_AGENT).build();
return iam;
}
示例7: ServiceAccountKeyManager
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
public ServiceAccountKeyManager(Iam iam) {
this.iam = iam;
}
示例8: testNewIamApi
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
@Test
public void testNewIamApi() {
Iam iam = googleApiFactory.newIamApi(mock(Credential.class));
assertEquals("https://iam.googleapis.com/", iam.getBaseUrl());
}
示例9: newIamApi
import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
/**
* @return an Identity and Access Management API client
*/
Iam newIamApi(Credential credential);