Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
knowledge-platform
Commits
c64941e4
Commit
c64941e4
authored
2 years ago
by
shishir suman
Browse files
Options
Download
Patches
Plain Diff
changes for gcloud signURL
parent
760d7baf
release-5.1.0-content
Gcloud_copy
Gcloud_fix
Remove_unwantedCode_Gcloud_fix
bulk-upload-comptenecy-mapping
bulk-upload-excelsheet
bulk-upload-test_excel
bulk_upload
master
poc_bulk_upload
rahul_bulk_upload_postgres
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
platform-modules/mimetype-manager/pom.xml
+6
-0
platform-modules/mimetype-manager/pom.xml
platform-modules/mimetype-manager/src/main/scala/org/sunbird/cloudstore/StorageService.scala
+19
-3
...rc/main/scala/org/sunbird/cloudstore/StorageService.scala
with
25 additions
and
3 deletions
+25
-3
platform-modules/mimetype-manager/pom.xml
+
6
−
0
View file @
c64941e4
...
@@ -15,6 +15,12 @@
...
@@ -15,6 +15,12 @@
</properties>
</properties>
<dependencies>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-storage -->
<dependency>
<groupId>
com.google.cloud
</groupId>
<artifactId>
google-cloud-storage
</artifactId>
<version>
2.16.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.sunbird
</groupId>
<groupId>
org.sunbird
</groupId>
<artifactId>
platform-common
</artifactId>
<artifactId>
platform-common
</artifactId>
...
...
This diff is collapsed.
Click to expand it.
platform-modules/mimetype-manager/src/main/scala/org/sunbird/cloudstore/StorageService.scala
+
19
−
3
View file @
c64941e4
package
org.sunbird.cloudstore
package
org.sunbird.cloudstore
import
com.google.auth.oauth2.ServiceAccountCredentials
import
com.google.cloud.storage.
{
BlobId
,
BlobInfo
,
Storage
,
StorageOptions
}
import
org.apache.commons.lang3.StringUtils
import
org.apache.commons.lang3.StringUtils
import
org.apache.tika.Tika
import
org.apache.tika.Tika
import
org.sunbird.cloud.storage.BaseStorageService
import
org.sunbird.cloud.storage.BaseStorageService
import
org.sunbird.cloud.storage.factory.
{
StorageConfig
,
StorageServiceFactory
}
import
org.sunbird.cloud.storage.factory.
{
StorageConfig
,
StorageServiceFactory
}
import
org.sunbird.common.
{
Platform
,
Slug
}
import
org.sunbird.common.exception.ServerException
import
org.sunbird.common.exception.ServerException
import
org.sunbird.common.
{
Platform
,
Slug
}
import
java.io.File
import
java.io.File
import
scala.concurrent.
{
ExecutionContext
,
Future
}
import
java.util.concurrent.TimeUnit
import
scala.concurrent.
{
ExecutionContext
,
Future
};
class
StorageService
{
class
StorageService
{
...
@@ -86,11 +90,23 @@ class StorageService {
...
@@ -86,11 +90,23 @@ class StorageService {
def
getSignedURL
(
key
:
String
,
ttl
:
Option
[
Int
],
permission
:
Option
[
String
])
:
String
=
{
def
getSignedURL
(
key
:
String
,
ttl
:
Option
[
Int
],
permission
:
Option
[
String
])
:
String
=
{
storageType
match
{
storageType
match
{
case
"gcloud"
=>
getService
.
getPutSignedURL
(
getContainerName
,
key
,
ttl
,
permission
,
Option
.
apply
(
getMimeType
(
key
)))
case
"gcloud"
=>
getGCPSignedURL
(
"113740098487205958998"
,
Platform
.
config
.
getString
(
"gcloud_client_key"
),
Platform
.
config
.
getString
(
"gcloud_private_secret"
),
"6aef3a75efe29225e6347244de3e8f1ddd8437df"
,
"upsmf-368011"
,
key
)
case
_
=>
getService
.
getSignedURL
(
getContainerName
,
key
,
ttl
,
permission
)
case
_
=>
getService
.
getSignedURL
(
getContainerName
,
key
,
ttl
,
permission
)
}
}
}
}
def
getGCPSignedURL
(
clientId
:
String
,
clientEmail
:
String
,
privateKeyPkcs8
:
String
,
privateKeyIds
:
String
,
projectId
:
String
,
objectName
:
String
)
:
String
=
{
val
credentials
=
ServiceAccountCredentials
.
fromPkcs8
(
clientId
,
clientEmail
,
privateKeyPkcs8
,
privateKeyIds
,
new
java
.
util
.
ArrayList
[
String
]())
val
storage
=
StorageOptions
.
newBuilder
.
setProjectId
(
projectId
).
setCredentials
(
credentials
).
build
.
getService
val
blobInfo
=
BlobInfo
.
newBuilder
(
BlobId
.
of
(
getContainerName
,
objectName
)).
build
val
url
=
storage
.
signUrl
(
blobInfo
,
15
,
TimeUnit
.
MINUTES
,
Storage
.
SignUrlOption
.
withV4Signature
)
println
(
"url:"
,
url
)
url
.
toString
;
}
def
getUri
(
key
:
String
)
:
String
=
{
def
getUri
(
key
:
String
)
:
String
=
{
try
{
try
{
getService
.
getUri
(
getContainerName
,
key
,
Option
.
apply
(
false
))
getService
.
getUri
(
getContainerName
,
key
,
Option
.
apply
(
false
))
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets