Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
2639fd9f
Commit
2639fd9f
authored
Mar 18, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small test
parent
b9f9e3df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
Drive.php
src/opnsense/mvc/app/library/Google/API/Drive.php
+19
-6
No files found.
src/opnsense/mvc/app/library/Google/API/Drive.php
View file @
2639fd9f
...
@@ -44,6 +44,11 @@ class Drive
...
@@ -44,6 +44,11 @@ class Drive
*/
*/
private
$client
=
null
;
private
$client
=
null
;
/**
* @var null|Google_Auth_AssertionCredentials credential object
*/
private
$cred
=
null
;
public
function
__construct
()
public
function
__construct
()
{
{
// hook in Google's autoloader
// hook in Google's autoloader
...
@@ -60,17 +65,13 @@ class Drive
...
@@ -60,17 +65,13 @@ class Drive
$this
->
client
=
new
\Google_Client
();
$this
->
client
=
new
\Google_Client
();
$key
=
base64_decode
(
$privateKeyB64
);
$key
=
base64_decode
(
$privateKeyB64
);
$cred
=
new
\Google_Auth_AssertionCredentials
(
$
this
->
cred
=
new
\Google_Auth_AssertionCredentials
(
$client_id
,
$client_id
,
array
(
'https://www.googleapis.com/auth/drive'
),
array
(
'https://www.googleapis.com/auth/drive'
),
$key
$key
);
);
$this
->
client
->
setAssertionCredentials
(
$cred
);
$this
->
client
->
setAssertionCredentials
(
$
this
->
cred
);
$this
->
client
->
setApplicationName
(
"OPNsense"
);
$this
->
client
->
setApplicationName
(
"OPNsense"
);
$this
->
client
->
setAssertionCredentials
(
$cred
);
if
(
$this
->
client
->
getAuth
()
->
isAccessTokenExpired
())
{
$this
->
client
->
getAuth
()
->
refreshTokenWithAssertion
(
$cred
);
}
$this
->
service
=
new
\Google_Service_Drive
(
$this
->
client
);
$this
->
service
=
new
\Google_Service_Drive
(
$this
->
client
);
}
}
...
@@ -87,6 +88,9 @@ class Drive
...
@@ -87,6 +88,9 @@ class Drive
if
(
$filename
!=
null
)
{
if
(
$filename
!=
null
)
{
$query
.=
" and title in '"
.
$filename
.
"'"
;
$query
.=
" and title in '"
.
$filename
.
"'"
;
}
}
if
(
$this
->
client
->
getAuth
()
->
isAccessTokenExpired
())
{
$this
->
client
->
getAuth
()
->
refreshTokenWithAssertion
(
$this
->
cred
);
}
return
$this
->
service
->
files
->
listFiles
(
array
(
'q'
=>
$query
));
return
$this
->
service
->
files
->
listFiles
(
array
(
'q'
=>
$query
));
}
}
...
@@ -97,6 +101,9 @@ class Drive
...
@@ -97,6 +101,9 @@ class Drive
*/
*/
public
function
download
(
$fileHandle
)
public
function
download
(
$fileHandle
)
{
{
if
(
$this
->
client
->
getAuth
()
->
isAccessTokenExpired
())
{
$this
->
client
->
getAuth
()
->
refreshTokenWithAssertion
(
$this
->
cred
);
}
$sUrl
=
$fileHandle
->
getDownloadUrl
();
$sUrl
=
$fileHandle
->
getDownloadUrl
();
$request
=
new
\Google_Http_Request
(
$sUrl
,
'GET'
,
null
,
null
);
$request
=
new
\Google_Http_Request
(
$sUrl
,
'GET'
,
null
,
null
);
$httpRequest
=
$this
->
client
->
getAuth
()
->
authenticatedRequest
(
$request
);
$httpRequest
=
$this
->
client
->
getAuth
()
->
authenticatedRequest
(
$request
);
...
@@ -120,6 +127,9 @@ class Drive
...
@@ -120,6 +127,9 @@ class Drive
public
function
upload
(
$directoryId
,
$filename
,
$content
,
$mimetype
=
'text/plain'
)
public
function
upload
(
$directoryId
,
$filename
,
$content
,
$mimetype
=
'text/plain'
)
{
{
if
(
$this
->
client
->
getAuth
()
->
isAccessTokenExpired
())
{
$this
->
client
->
getAuth
()
->
refreshTokenWithAssertion
(
$this
->
cred
);
}
$parent
=
new
\Google_Service_Drive_ParentReference
();
$parent
=
new
\Google_Service_Drive_ParentReference
();
$parent
->
setId
(
$directoryId
);
$parent
->
setId
(
$directoryId
);
...
@@ -144,6 +154,9 @@ class Drive
...
@@ -144,6 +154,9 @@ class Drive
*/
*/
public
function
delete
(
$fileHandle
)
public
function
delete
(
$fileHandle
)
{
{
if
(
$this
->
client
->
getAuth
()
->
isAccessTokenExpired
())
{
$this
->
client
->
getAuth
()
->
refreshTokenWithAssertion
(
$this
->
cred
);
}
$this
->
service
->
files
->
delete
(
$fileHandle
[
'id'
]);
$this
->
service
->
files
->
delete
(
$fileHandle
[
'id'
]);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment