Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN Access Check - Account manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
edugain
eduGAIN Access Check - Account manager
Commits
893001bf
Commit
893001bf
authored
7 years ago
by
Guillaume ROUSSE
Browse files
Options
Downloads
Patches
Plain Diff
use multipart response to download accounts in CSV format
parent
f85b05b1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/AccountManager/WebRequest.pm
+89
-3
89 additions, 3 deletions
lib/AccountManager/WebRequest.pm
with
89 additions
and
3 deletions
lib/AccountManager/WebRequest.pm
+
89
−
3
View file @
893001bf
...
...
@@ -10,6 +10,10 @@ use Template;
use
Log::Any::
Adapter
;
use
List::
MoreUtils
qw(uniq)
;
use
HTTP::
AcceptLanguage
;
use
HTTP::
Message
;
use
HTTP::
Response
;
use
IO::
String
;
use
Text::
CSV
;
use
AccountManager::
Account
;
use
AccountManager::Account::
Manager
;
...
...
@@ -127,7 +131,6 @@ sub run {
sub
respond
{
my
(
$self
,
$data
)
=
@_
;
$data
->
{
app
}
=
{
name
=>
$self
->
{
configuration
}
->
{
app
}
->
{
name
},
url
=>
$self
->
{
configuration
}
->
{
app
}
->
{
url
},
...
...
@@ -154,8 +157,9 @@ sub respond {
binmode
(
STDOUT
,
"
:utf8
");
print
$self
->
{
cgi
}
->
header
(
-
nph
=>
1
,
-
type
=>
'
text/html
',
-
charset
=>
''
-
charset
=>
'
utf8
'
);
unless
(
$tt2
->
process
(
$template
,
$data
,
\
*STDOUT
))
{
...
...
@@ -499,13 +503,95 @@ sub req_create_accounts {
$self
->
{
in
}
->
{
token
}
);
$self
->
respond
({
binmode
(
STDOUT
,
"
:utf8
");
my
$response
=
HTTP::
Response
->
new
(
200
,
'
OK
',
[
'
Content-Type
'
=>
'
multipart/x-mixed-replace
'
]
);
$response
->
protocol
('
HTTP/1.1
');
$response
->
date
(
time
);
$response
->
server
(
$ENV
{
SERVER_SOFTWARE
});
# HTML page
my
$data
=
{
app
=>
{
name
=>
$self
->
{
configuration
}
->
{
app
}
->
{
name
},
url
=>
$self
->
{
configuration
}
->
{
app
}
->
{
url
},
support_email
=>
$self
->
{
configuration
}
->
{
app
}
->
{
support_email
},
version
=>
$self
->
{
configuration
}
->
{
app
}
->
{
version
},
},
accounts
=>
\
@accounts
,
accounts_validity_period
=>
$self
->
{
configuration
}
->
{
service
}
->
{
account_validity_period
},
idp_displayname
=>
$self
->
{
configuration
}
->
{
idp
}
->
{
displayname
},
entityid
=>
$self
->
{
in
}
->
{
entityid
},
action
=>
'
create_accounts
'
};
my
$lang
=
HTTP::
AcceptLanguage
->
new
(
$ENV
{
HTTP_ACCEPT_LANGUAGE
})
->
match
(
qw/en fr/
)
||
'
en
';
my
$tt2
=
Template
->
new
({
INCLUDE_PATH
=>
$self
->
{
configuration
}
->
{
_
}
->
{
templates_dir
}
.
"
/web/
$lang
"
});
my
$page_content
;
$tt2
->
process
('
index.tt2.html
',
$data
,
\
$page_content
);
my
$page_response
=
HTTP::
Message
->
new
(
[
'
Content-Type
'
=>
'
text/html; charset=utf-8
',
'
Content-Disposition
'
=>
'
inline
'
],
$page_content
);
$response
->
add_part
(
$page_response
);
# CSV file
my
$csv
=
Text::
CSV
->
new
({
binary
=>
1
,
eol
=>
"
\r\n
",
quote_space
=>
0
});
my
$file_content
;
my
$file_content_io
=
IO::
String
->
new
(
$file_content
);
$csv
->
print
(
$file_content_io
,
[
qw/
username
password
profile
cn
displayName
givenName
mail
eduPersonAffiliation
eduPersonScopedAffiliation
eduPersonPrincipalName
schacHomeOrganization
schacHomeOrganizationType
/
]);
foreach
my
$account
(
@accounts
)
{
$csv
->
print
(
$file_content_io
,
[
$account
->
internal_uid
(),
$account
->
password
(),
$account
->
profile
(),
$account
->
cn
(),
$account
->
displayName
(),
$account
->
givenName
(),
$account
->
mail
(),
$account
->
eduPersonAffiliation
(),
$account
->
eduPersonScopedAffiliation
(),
$account
->
eduPersonPrincipalName
(),
$account
->
schacHomeOrganization
(),
$account
->
schacHomeOrganizationType
(),
]);
}
my
$file_response
=
HTTP::
Message
->
new
(
[
'
Content-Type
'
=>
'
text/csv; charset=utf-8
',
'
Content-Disposition
'
=>
'
attachment; filename="accounts.csv"
'
],
$file_content
);
$response
->
add_part
(
$file_response
);
print
$response
->
as_string
();
}
## Return the homepage of the service
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment