This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Utilities.java
69 lines (62 loc) · 2.76 KB
/
Utilities.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
* Copyright 2019 Huawei Technologies Co.,Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
package com.huawei.openstack.sample.bss.v1;
import com.huawei.openstack4j.api.OSClient;
import com.huawei.openstack4j.api.exceptions.ClientResponseException;
import com.huawei.openstack4j.api.exceptions.ServerResponseException;
import com.huawei.openstack4j.model.common.Identifier;
import com.huawei.openstack4j.openstack.OSFactory;
import com.huawei.openstack4j.openstack.bss.v1.domain.utilities.SendVerificationCodeReq;
import com.huawei.openstack4j.openstack.bss.v1.domain.utilities.SendVerificationCodeRsp;
public class Utilities
{
private static OSClient.OSClientV3 getOsClientV3(String username, String password, String userDomainId) {
String authUrl = "https://iam.xxx.com/v3";
OSFactory.enableHttpLoggingFilter(true);
// create connection
return OSFactory.builderV3()
.endpoint(authUrl)
.credentials(username, password, Identifier.byId(userDomainId))
.scopeToDomain(Identifier.byId(userDomainId))
.authenticate();
}
private static SendVerificationCodeRsp sendVerificationCode(OSClient.OSClientV3 client, String domainID, SendVerificationCodeReq req)
{
try {
SendVerificationCodeRsp rsp = client.bssV1().utilitiesService().sendVerificationCode(domainID, req);
return rsp;
}
catch (ClientResponseException e1)
{
System.out.println("errorMsg: " + e1.getBody());;
}
catch (ServerResponseException e2)
{
System.out.println("errorMsg: " + e2.getBody());;
}
return null;
}
public static void main(String[] args)
{
// create connection
String domainId = "xxx";
OSClient.OSClientV3 osclient = getOsClientV3("xxx","xxxxx", domainId);
//Sending a Verification Code
SendVerificationCodeReq req =
SendVerificationCodeReq.builder().receiverType(2).mobilePhone("134xxxxxxxx").build();
SendVerificationCodeRsp rsp = sendVerificationCode(osclient, domainId, req);
}
}