Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDrive: Fix fieldNotWritable, Add SupportSharedDrive, Add service_account method #512

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

DoyunShin
Copy link

No description provided.

&drive.File
Size => fieldNotWritable error
SupportsAllDrives(true) => all action
IncludeItemsFromAllDrives(true) => List
server/storage/gdrive.go Outdated Show resolved Hide resolved
Check localConfigPath == "" on NEWGDriveStorage()
@DoyunShin
Copy link
Author

DoyunShin commented Oct 26, 2022

Didnt expected gDriveRootConfigFile requires localConfigPath on commit cd9c56e
reverted with 73ac766

@aspacca
Copy link
Collaborator

aspacca commented Oct 26, 2022

how do you select a shared drive as target?
currently we write the root of transfer.sh in the main folder, and save the id
https://github.com/dutchcoders/transfer.sh/blob/main/server/storage/gdrive.go#L87-L96

is giving the service account access to a specific shared folder that you end up using a folder? (total guess)

return nil, err
var httpClient *http.Client

if strings.Contains(string(b), `"type": "service_account"`) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have a separate cli param for service account file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param like --gdrive-type=service / oauth2?
or we can actually check in json.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oauth2
{ "installed": { "client_id": "clientid", "project_id": "projectname", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_secret": "clientsecret" } }

Service Account
{ "type": "service_account", "project_id": "projectname", "private_key_id": "keyid", "private_key": "-----BEGIN PRIVATE KEY-----\nKEYSECRET\n-----END PRIVATE KEY-----\n", "client_email": "transfersh@projectname.iam.gserviceaccount.com", "client_id": "clientid", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/transfersh%40projectname.iam.gserviceaccount.com" }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param like --gdrive-type=service / oauth2?
or we can actually check in json.

param like gdrive-client-json-filepath: gdrive-service-account-json-filepath

only one of the two can be set

in the factory you can translate this to a single param with the path and a new param for the type (service account/oauth2): it is up to you

server/storage/gdrive.go Outdated Show resolved Hide resolved
server/storage/gdrive.go Outdated Show resolved Hide resolved
@DoyunShin
Copy link
Author

DoyunShin commented Oct 26, 2022

is giving the service account access to a specific shared folder that you end up using a folder? (total guess)

image
Yep. By giving a permission to service account(name@projectname.iam.gserviceaccount.com), the service account can access to shared folder

how do you select a shared drive as target?

i think we can get folder id from basedir
(and if basedir is "root" then get root folder)

@DoyunShin
Copy link
Author

be00bb8
Changed to Using basedir as rootID.

if basedir == "root", then user's drive root folder is used to store files.

@DoyunShin
Copy link
Author

#512 (comment)

About this,
#512 (comment)
This is the credentials of service account and oauth2.

There is no problem even if we receive the auth-type with cli or automatically identify it with credentials.json.
Which choice do we go?

Or, it seems that there will be no problem even if it is made to work both when auth-type is entered or not.

return nil, err
var httpClient *http.Client

if strings.Contains(string(b), `"type": "service_account"`) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param like --gdrive-type=service / oauth2?
or we can actually check in json.

param like gdrive-client-json-filepath: gdrive-service-account-json-filepath

only one of the two can be set

in the factory you can translate this to a single param with the path and a new param for the type (service account/oauth2): it is up to you

err = ioutil.WriteFile(rootFileConfig, []byte(s.rootID), os.FileMode(0600))
if err != nil {
return err
func (s *GDrive) checkRoot() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change.

basedir is the name of the folder to be created in the gdrive, rootID is the id of the folder once created and that we save. the two carry two different information.

if we replce rootID value with basedir value:

  1. we don't create the folder
  2. current installations have to change the value that they pass to basedir, to use instead rootID

I guess you meant this change to be the way to select a shared drive, is it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

I changed basedir to insert folder id, to select rootID.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot accept a breaking change, sorry
you have to find another way to provide the sharedfolder to use and the basedir as it was

server/storage/gdrive.go Show resolved Hide resolved
server/storage/gdrive.go Show resolved Hide resolved
@DoyunShin
Copy link
Author

in the factory you can translate this to a single param with the path and a new param for the type (service account/oauth2): it is up to you

Added gdrive-auth-type
oauth2|service_account

@@ -169,6 +169,12 @@ var globalFlags = []cli.Flag{
Value: "",
EnvVar: "GDRIVE_CLIENT_JSON_FILEPATH",
},
cli.StringFlag{
Name: "gdrive-auth-type",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way you pass gdrive-client-json-filepath when it's a gdrive-service-account-filepath indeed

also it's a breaking change, I cannot accept it, sorry :(

you can add gdrive-service-account-filepath, check that only this or gdrive-client-json-filepath is set (and at least one of them), and set the authType value to pass to the factory: https://github.com/dutchcoders/transfer.sh/pull/512/files#diff-8e494a434a8037b6c0b888e25b2baae7618fe65e792d4a155dadd096e9350667R488

please, remember to change the name of the param in the factory to something generic, like gdriveCredentialsFilepath

Copy link
Collaborator

@aspacca aspacca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please. see my latest comments :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants