Skip to content

Commit c82ef24

Browse files
committed
initial login changes
1 parent 39c8267 commit c82ef24

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

recipes/perl/api_requests.pl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env perl
2+
use LWP::UserAgent;
3+
4+
my $content_type_v2 = "application/json";
5+
6+
#We will get this token using login api and the token will be used
7+
#in subsequent api requests of policy
8+
my $token;
9+
10+
sub perform_login {
11+
my $base_url;
12+
13+
foreach $item (@_) {
14+
$base_url = $item;
15+
}
16+
17+
my $url = "$base_url/login";
18+
print "\nUsing url: $url\n";
19+
20+
my $req = HTTP::Request->new(POST => $url);
21+
$req->header('content-type' => $content_type_v2);
22+
my $post_data = '{ "domainType": "nt", "domainName": "rmnus", "userName": "akumar1", "password": "FEELDheat9193" }';
23+
$req->content($post_data);
24+
25+
my $ua = LWP::UserAgent->new(
26+
ssl_opts => { verify_hostname => 0, verify_peer => 0},
27+
);
28+
29+
print "\n\n**************************************************************";
30+
print "\n\n Making Post Request to login to get token \n\n";
31+
32+
my $resp = $ua->request($req);
33+
if ($resp->is_success) {
34+
my $message = decode_json($resp->content);
35+
$token = $message->{"token"};
36+
print "Received token: $token\n";
37+
}
38+
else {
39+
print "HTTP POST error code: ", $resp->code, "\n";
40+
print "HTTP POST error message: ", $resp->message, "\n";
41+
}
42+
}
43+
44+
sub customtest {
45+
print "we made it here";
46+
}
47+
1;

recipes/perl/create_policy_with_defaults.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
print "LWP::UserAgent: ".LWP::UserAgent->VERSION,"\n";
66
print "LWP::Protocol::https: ".LWP::Protocol::https->VERSION,"\n";
77
use JSON;
8-
8+
require 'api_requests.pl';
99

1010
#
1111
# The token is the key to the NetBackup AuthN/AuthZ scheme. You must login and get a token
@@ -35,7 +35,8 @@ sub print_disclaimer {
3535

3636
# subroutine to process user input
3737
sub user_input {
38-
38+
customtest();
39+
perform_login("https://localhost:1556/netbackup");
3940
}
4041

4142
print_disclaimer();

0 commit comments

Comments
 (0)