Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Config/ Best Practices/ Querying Resource Details, Relationships, and Change Records

Querying Resource Details, Relationships, and Change Records

Updated on 2025-01-22 GMT+08:00

Overview

This example shows how to use the Java SDK to query resource details, relationships, and change records.

  1. Resource List only displays some resource attributes. The following example shows how to query more details about a resource.
  2. Associated Resources displays relationships between your Huawei Cloud resources.
  3. Resource Timeline records resource changes. A record will be added to the resource timeline when a service reports a resource attribute or relationship change to Config. Config retains resource change records for seven years by default.

Prerequisites

  1. You have obtained the Huawei Cloud SDK and installed the Java SDK.
  2. You have a Huawei Cloud account and an access key ID (AK) and a secret access key. You can view or create an AK/SK pair in My Credentials > Access Keys on the Huawei Cloud console. For details, see Access Keys.
  3. Config SDK supports Java JDK 1.8 or later.

Installing the SDK

You can obtain and install the SDK using Maven. To use Maven, add dependencies to the pom.xml file. For details about SDK versions, see SDK Center.

<dependency>
    <groupId>com.huaweicloud.sdk</groupId>
    <artifactId>huaweicloud-sdk-config</artifactId>
    <version>{sdk-version}</version>
</dependency>

Example Code

public class ShowResourceRelationDemo {
    public static void main(String[] args) {
        // There will be security risks if the AK and SK used for authentication is written into code. Encrypt the AK/SK and store them into the configuration file or environment variables.
        // In this example, the AK and SK are stored in environment variables. Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.
        String ak = System.getenv("HUAWEICLOUD_SDK_AK");
        String sk = System.getenv("HUAWEICLOUD_SDK_SK");
        String regionId = "<region id>";
        HttpConfig config = HttpConfig.getDefaultHttpConfig();
        config.withIgnoreSSLVerification(true);

        ICredential auth = new GlobalCredentials().withAk(ak).withSk(sk);
        ConfigClient client = ConfigClient.newBuilder().withHttpConfig(config).withCredential(auth)
            .withRegion(ConfigRegion.valueOf(regionId)).build();

        try {
            String resourceId = "<resource id>";
            // Querying resource details
            ShowResourceDetailRequest resourceDetailRequest = new ShowResourceDetailRequest()
                .withResourceId(resourceId);
            System.out.println(client.showResourceDetail(resourceDetailRequest));
            // Querying resource relationships
            ShowResourceRelationsRequest resourceRelationsRequest = new ShowResourceRelationsRequest()
                .withResourceId(resourceId)
                .withDirection(ShowResourceRelationsRequest.DirectionEnum.IN);
            System.out.println(client.showResourceRelations(resourceRelationsRequest).toString());
            // Querying resource change records
            ShowResourceHistoryRequest resourceHistoryRequest = new ShowResourceHistoryRequest()
                .withResourceId(resourceId);
            System.out.println(client.showResourceHistory(resourceHistoryRequest).toString());
        } catch (ConnectionException | RequestTimeoutException | ServiceResponseException ex) {
            System.out.println(ex);
        }
    }
}

Response

class ShowResourceDetailResponse {
    id: 81fi****a864
    name: zh****ng
    provider: iam
    type: users
    regionId: global
    projectId: 
    projectName: 
    epId: 0
    epName: default
    checksum: 522u****e689
    created: 2023-09-18T12:56:30.000Z
    updated: 2023-09-18T12:56:30.000Z
    provisioningState: Succeeded
    state: Normal
    tags: {}
    properties: {pwd_status=false, pwd_strength=high, group_list=[f588****54c5], role_list=[], last_login_time=2023-09-18T12:57:45Z, virtual_mfa_device=false, login_protect={enabled=false}, credentials=[], policy_list=[], access_mode=default, is_root_user=false, enabled=true}
}

class ShowResourceRelationsResponse {
    relations: [class ResourceRelation {
        relationType: contains
        fromResourceType: iam.groups
        toResourceType: iam.users
        fromResourceId: f587****54c5
        toResourceId: 81fa****a864
    }]
    pageInfo: class PageInfo {
        currentCount: 1
        nextMarker: null
    }
}

class ShowResourceHistoryResponse {
    items: [class HistoryItem {
        domainId: 39f4****ea39
        resourceId: 81fa****a864
        resourceType: iam.users
        captureTime: 2023-09-21T15:39:27.632Z
        status: ResourceChanged.CREATE
        relations: [class ResourceRelation {
            relationType: isContainedIn
            fromResourceType: iam.users
            toResourceType: iam.groups
            fromResourceId: 81fa****a864
            toResourceId: b04e****8dd2
        }]
        resource: class ResourceEntity {
            id: 81fa****a864
            name: zh****ng
            provider: iam
            type: users
            regionId: global
            projectId: 
            projectName: 
            epId: 0
            epName: default
            checksum: 00ce****f053
            created: 2023-09-18T12:56:30Z
            updated: 2023-09-18T12:56:30Z
            provisioningState: Succeeded
            state: null
            tags: {}
            properties: {pwd_status=false, pwd_strength=high, group_list=[b04e****8dd2], role_list=[], virtual_mfa_device=false, login_protect={enabled=false}, credentials=[], policy_list=[], access_mode=default, enabled=true}
        }
    }]
    pageInfo: class PageInfo {
        currentCount: 1
        nextMarker: null
    }
}

Reference

For more details, see Viewing Resource Changes.

Change History

Release On

Issue

Description

2024-12-25

1.0

This is the first official release.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback