Skip to content

Commit

Permalink
feat: add argument to provide keyfile content directly for all actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bskim45 committed Sep 16, 2024
1 parent df67ae7 commit 20c6421
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 125 deletions.
20 changes: 20 additions & 0 deletions CHAGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# CHANGELOG


## v0.10.0 (2024-09-16)

### Changelog

#### Breaking Changes

The default value of `drive_keyfile` (`drive_key.json`) is removed.
Now, **you must specify the key file path manually** via
the `drive_keyfile` argument or the `GDRIVE_KEY_FILE` environment variable.
This change applies to all actions.

#### Other Changes
- Added the argument `drive_key_json` (env: `GDRIVE_KEY_JSON`) to all actions,
allowing you to provide the JSON key file content directly.

- You can also specify the path to the JSON key file using
the `GOOGLE_APPLICATION_CREDENTIALS` environment variable,
commonly used in other SDKs and libraries.

## v0.9.0 (2022-12-03)

### Changelog
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-google_drive)
[![Gem Version](https://badge.fury.io/rb/fastlane-plugin-google_drive.svg)](https://badge.fury.io/rb/fastlane-plugin-google_drive)
[![Build Status](https://app.travis-ci.com/bskim45/fastlane-plugin-google_drive.svg?branch=main)](https://app.travis-ci.com/bskim45/fastlane-plugin-google_drive)
![Build Status](https://github.com/bskim45/fastlane-plugin-google_drive/actions/workflows/rubygems.yml/badge.svg)
[![Test Coverage](https://api.codeclimate.com/v1/badges/681ab1f5c19ca029dff4/test_coverage)](https://codeclimate.com/github/bskim45/fastlane-plugin-google_drive/test_coverage)

## Getting Started
Expand All @@ -15,14 +15,15 @@ fastlane add_plugin google_drive

## About google_drive

> Please refer to [this guide](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md) to create an Google Drive credential.
> Please refer to [this guide](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md) to create a Google Drive credential.
Upload files to Google Drive folder.
> Aliases for this action - `google_drive_upload` and `upload_google_drive` are both removed in `v0.6.0`.

```ruby
upload_to_google_drive(
drive_keyfile: 'drive_key.json',
# or you can provide the content of JSON keyfile directly as an argument
# drive_key_json: __KEYFILE_CONTENT__,
service_account: true,
folder_id: 'folder_id',
upload_files: ['file_to_upload', 'another_file_to_upload']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ module SharedValues
GDRIVE_CREATED_FOLDER_ID = :GDRIVE_CREATED_FOLDER_ID
GDRIVE_CREATED_FOLDER_URL = :GDRIVE_CREATED_FOLDER_URL
end

class CreateGoogleDriveFolderAction < Action
def self.run(params)
UI.message("Using credential file: #{params[:drive_keyfile]}")
unless params[:drive_keyfile].nil?
UI.message("Using credential file: #{params[:drive_keyfile]}")
end

session = Helper::GoogleDriveHelper.setup(
keyfile: params[:drive_keyfile],
key_json: params[:drive_key_json],
service_account: params[:service_account]
)

Expand Down Expand Up @@ -47,36 +51,62 @@ def self.details

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :drive_keyfile,
env_name: 'GDRIVE_KEY_FILE',
description: 'Json config file',
type: String,
default_value: 'drive_key.json',
verify_block: proc do |value|
UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
end),
FastlaneCore::ConfigItem.new(key: :service_account,
env_name: 'GDRIVE_SERVICE_ACCOUNT',
description: 'Credential is service account',
optional: true,
is_string: false,
default_value: false),
FastlaneCore::ConfigItem.new(key: :folder_id,
env_name: "GDRIVE_UPLOAD_FOLDER_ID",
description: "Upload target folder id",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No target folder_id given, pass using `folder_id: 'some_id'`") unless value and !value.empty?
end),
FastlaneCore::ConfigItem.new(key: :folder_title,
env_name: "GDRIVE_FOLDER_NAME",
description: "Folder title of new one",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No folder title given") if value.nil? || value.empty?
end)
FastlaneCore::ConfigItem.new(
key: :drive_keyfile,
env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
description: 'Path to the JSON keyfile',
conflicting_options: [:drive_key_json],
type: String,
optional: true,
verify_block: proc do |value|
UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
end
),
FastlaneCore::ConfigItem.new(
key: :drive_key_json,
env_name: 'GDRIVE_KEY_JSON',
description: 'Credential key in stringified JSON format',
optional: true,
conflicting_options: [:drive_keyfile],
type: String,
sensitive: true,
verify_block: proc do |value|
begin
JSON.parse(value)
rescue JSON::ParserError
UI.user_error!("Provided credential key is not a valid JSON")
end
end
),
FastlaneCore::ConfigItem.new(
key: :service_account,
env_name: 'GDRIVE_SERVICE_ACCOUNT',
description: 'true if the credential is for a service account, false otherwise',
optional: true,
is_string: false,
default_value: false
),
FastlaneCore::ConfigItem.new(
key: :folder_id,
env_name: "GDRIVE_UPLOAD_FOLDER_ID",
description: "Upload target folder id",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No target `folder_id` was provided. Pass it using `folder_id: 'some_id'`") unless value and !value.empty?
end
),
FastlaneCore::ConfigItem.new(
key: :folder_title,
env_name: "GDRIVE_FOLDER_NAME",
description: "Folder title of new one",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No folder title given") if value.nil? || value.empty?
end
)
]
end

Expand All @@ -92,7 +122,7 @@ def self.return_value
end

def self.authors
['Kohki Miki (@giginet)']
['Bumsoo Kim (@bskim45)', 'Kohki Miki (@giginet)']
end

def self.is_supported?(platform)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ module SharedValues

class FindGoogleDriveFileByIdAction < Action
def self.run(params)
UI.message("Using credential file: #{params[:drive_keyfile]}")
unless params[:drive_keyfile].nil?
UI.message("Using credential file: #{params[:drive_keyfile]}")
end

session = Helper::GoogleDriveHelper.setup(
keyfile: params[:drive_keyfile],
key_json: params[:drive_key_json],
service_account: params[:service_account]
)

Expand Down Expand Up @@ -53,18 +56,36 @@ def self.available_options
[
FastlaneCore::ConfigItem.new(
key: :drive_keyfile,
env_name: 'GDRIVE_KEY_FILE',
description: 'The path to the json keyfile',
env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
description: 'Path to the JSON keyfile',
conflicting_options: [:drive_key_json],
type: String,
default_value: 'drive_key.json',
optional: true,
verify_block: proc do |value|
UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
end
),
FastlaneCore::ConfigItem.new(
key: :drive_key_json,
env_name: 'GDRIVE_KEY_JSON',
description: 'Credential key in stringified JSON format',
optional: true,
conflicting_options: [:drive_keyfile],
type: String,
sensitive: true,
verify_block: proc do |value|
begin
JSON.parse(value)
rescue JSON::ParserError
UI.user_error!("Provided credential key is not a valid JSON")
end
end
),
FastlaneCore::ConfigItem.new(
key: :service_account,
env_name: 'GDRIVE_SERVICE_ACCOUNT',
description: 'Whether the credential file is for the google service account',
description: 'true if the credential is for a service account, false otherwise',
optional: true,
is_string: false,
default_value: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ module SharedValues

class FindGoogleDriveFileByTitleAction < Action
def self.run(params)
UI.message("Using credential file: #{params[:drive_keyfile]}")
unless params[:drive_keyfile].nil?
UI.message("Using credential file: #{params[:drive_keyfile]}")
end

session = Helper::GoogleDriveHelper.setup(
keyfile: params[:drive_keyfile],
key_json: params[:drive_key_json],
service_account: params[:service_account]
)

Expand Down Expand Up @@ -57,18 +60,36 @@ def self.available_options
[
FastlaneCore::ConfigItem.new(
key: :drive_keyfile,
env_name: 'GDRIVE_KEY_FILE',
description: 'The path to the json keyfile',
env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
description: 'Path to the JSON keyfile',
conflicting_options: [:drive_key_json],
type: String,
default_value: 'drive_key.json',
optional: true,
verify_block: proc do |value|
UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
end
),
FastlaneCore::ConfigItem.new(
key: :drive_key_json,
env_name: 'GDRIVE_KEY_JSON',
description: 'Credential key in stringified JSON format',
optional: true,
conflicting_options: [:drive_keyfile],
type: String,
sensitive: true,
verify_block: proc do |value|
begin
JSON.parse(value)
rescue JSON::ParserError
UI.user_error!("Provided credential key is not a valid JSON")
end
end
),
FastlaneCore::ConfigItem.new(
key: :service_account,
env_name: 'GDRIVE_SERVICE_ACCOUNT',
description: 'Whether the credential file is for the google service account',
description: 'true if the credential is for a service account, false otherwise',
optional: true,
is_string: false,
default_value: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ module SharedValues
GDRIVE_UPDATED_FILE_NAME = :GDRIVE_UPDATED_FILE_NAME
GDRIVE_UPDATED_FILE_URL = :GDRIVE_UPDATED_FILE_URL
end

class UpdateGoogleDriveFileAction < Action
def self.run(params)
UI.message("Using credential file: #{params[:drive_keyfile]}")
unless params[:drive_keyfile].nil?
UI.message("Using credential file: #{params[:drive_keyfile]}")
end

session = Helper::GoogleDriveHelper.setup(
keyfile: params[:drive_keyfile],
key_json: params[:drive_key_json],
service_account: params[:service_account]
)

Expand Down Expand Up @@ -46,37 +50,63 @@ def self.details

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :drive_keyfile,
env_name: 'GDRIVE_KEY_FILE',
description: 'Json config file',
type: String,
default_value: 'drive_key.json',
verify_block: proc do |value|
UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
end),
FastlaneCore::ConfigItem.new(key: :service_account,
env_name: 'GDRIVE_SERVICE_ACCOUNT',
description: 'Credential is service account',
optional: true,
is_string: false,
default_value: false),
FastlaneCore::ConfigItem.new(key: :file_id,
env_name: "GDRIVE_UPDATE_FILE_ID",
description: "Target file id to update the content",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No target file id given, pass using `file_id: 'some_id'`") unless value and !value.empty?
end),
FastlaneCore::ConfigItem.new(key: :upload_file,
env_name: "GDRIVE_UPLOAD_FILE",
description: "Path to a file to be uploaded",
optional: false,
is_string: false,
verify_block: proc do |value|
UI.user_error!("No upload file is given, pass using `upload_file: 'some/path/a.txt'`") unless value and !value.empty?
UI.user_error!("Couldn't find upload file at path '#{value}'") unless File.exist?(value)
end)
FastlaneCore::ConfigItem.new(
key: :drive_keyfile,
env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
description: 'Path to the JSON keyfile',
conflicting_options: [:drive_key_json],
type: String,
optional: true,
verify_block: proc do |value|
UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
end
),
FastlaneCore::ConfigItem.new(
key: :drive_key_json,
env_name: 'GDRIVE_KEY_JSON',
description: 'Credential key in stringified JSON format',
optional: true,
conflicting_options: [:drive_keyfile],
type: String,
sensitive: true,
verify_block: proc do |value|
begin
JSON.parse(value)
rescue JSON::ParserError
UI.user_error!("Provided credential key is not a valid JSON")
end
end
),
FastlaneCore::ConfigItem.new(
key: :service_account,
env_name: 'GDRIVE_SERVICE_ACCOUNT',
description: 'true if the credential is for a service account, false otherwise',
optional: true,
is_string: false,
default_value: false
),
FastlaneCore::ConfigItem.new(
key: :file_id,
env_name: "GDRIVE_UPDATE_FILE_ID",
description: "Target file id to update the content",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No target `file_id` is provided. Pass it using `file_id: 'some_id'`") unless value and !value.empty?
end
),
FastlaneCore::ConfigItem.new(
key: :upload_file,
env_name: "GDRIVE_UPLOAD_FILE",
description: "Path to a file to be uploaded",
optional: false,
is_string: false,
verify_block: proc do |value|
UI.user_error!("No upload file is given, pass using `upload_file: 'some/path/a.txt'`") unless value and !value.empty?
UI.user_error!("Couldn't find upload file at path '#{value}'") unless File.exist?(value)
end
)
]
end

Expand Down
Loading

0 comments on commit 20c6421

Please sign in to comment.