当前位置: 首页>>代码示例>>Java>>正文


Java Iam类代码示例

本文整理汇总了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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:policyscanner,代码行数:26,代码来源:GCPServiceAccount.java

示例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);
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:17,代码来源:StyxScheduler.java

示例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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:23,代码来源:ServiceAccountUtilTest.java

示例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);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:26,代码来源:GcpLocalRunTabTest.java

示例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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:38,代码来源:ServiceAccountUtil.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:12,代码来源:GoogleApiFactory.java

示例7: ServiceAccountKeyManager

import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
public ServiceAccountKeyManager(Iam iam) {
  this.iam = iam;
}
 
开发者ID:spotify,项目名称:styx,代码行数:4,代码来源:ServiceAccountKeyManager.java

示例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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:6,代码来源:GoogleApiFactoryTest.java

示例9: newIamApi

import com.google.api.services.iam.v1.Iam; //导入依赖的package包/类
/**
 * @return an Identity and Access Management API client
 */
Iam newIamApi(Credential credential);
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:5,代码来源:IGoogleApiFactory.java


注:本文中的com.google.api.services.iam.v1.Iam类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。