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

[Flutter] API Keyなどの秘匿情報の管理 #32

Merged
merged 8 commits into from
Feb 14, 2023
Merged
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
.classpath
.project
.settings/
.vscode/
.vscode/*
!.vscode/settings.json
!.vscode/launch.json
!.vscode/extensions.json
Comment on lines +24 to +26
Copy link
Owner Author

Choose a reason for hiding this comment

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

チーム内で開発環境を統一するために必要なjsonファイルのみgit管理対象にする


# Flutter repo-specific
/bin/cache/
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"Dart-Code.flutter", // Flutter support and debugger for Visual Studio Code.
"Dart-Code.dart-code", // Dart
"robert-brunhage.flutter-riverpod-snippets", // riverpod
// "alexisvt.flutter-snippets", // flutter widget snippets
]
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

https://de-milestones.com/vscode-how-to-setup-recommended-tools/
拡張機能を統一させるための設定ファイル

56 changes: 56 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
// launch.json作成時のテンプレート - START
// "configurations": [
// {
// "name": "flutter_github_search",
// "request": "launch",
// "type": "dart"
// },
// {
// "name": "flutter_github_search (profile mode)",
// "request": "launch",
// "type": "dart",
// "flutterMode": "profile"
// },
// {
// "name": "flutter_github_search (release mode)",
// "request": "launch",
// "type": "dart",
// "flutterMode": "release"
// }
// ]
// launch.json作成時のテンプレート - END
"configurations": [
{
"name": "Debug dev",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"args": [
"--dart-define-from-file=dart_define/development.json"
]
},
{
"name": "Debug stg",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"args": [
"--dart-define-from-file=dart_define/staging.json"
]
},
{
"name": "Debug prod",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"args": [
"--dart-define-from-file=dart_define/production.json"
]
}
]
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

vscode上で、「実行とデバッグ」をクリックして実行する場合に指定できるビルドタイプの設定ファイル

49 changes: 49 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
// Flutterプロジェクトのバージョン管理のため、fvmを指定 -START
// https://fvm.app/docs/getting_started/configuration#option-1---automatic-switching-recommended
"dart.flutterSdkPath": ".fvm/flutter_sdk",
// Remove .fvm files from search
"search.exclude": {
"**/.fvm": true
},
// Remove from file watching
"files.watcherExclude": {
"**/.fvm": true
},
// Flutterプロジェクトのバージョン管理のため、fvmを指定 -END
"[dart]": {
// Automatically format code on save and during typing of certain characters
// (like `;` and `}`).
"editor.formatOnSave": true,
"editor.formatOnType": true,
// Draw a guide line at 80 characters, where Dart's formatting will wrap code.
"editor.rulers": [
80
],
// Disables built-in highlighting of words that match your selection. Without
// this, all instances of the selected text will be highlighted, interfering
// with Dart's ability to highlight only exact references to the selected variable.
"editor.selectionHighlight": false,
// By default, VS Code prevents code completion from popping open when in
// "snippet mode" (editing placeholders in inserted code). Setting this option
// to `false` stops that and allows completion to open as normal, as if you
// weren't in a snippet placeholder.
"editor.suggest.snippetsPreventQuickSuggestions": false,
// By default, VS Code will pre-select the most recently used item from code
// completion. This is usually not the most relevant item.
//
// "first" will always select top item
// "recentlyUsedByPrefix" will filter the recently used items based on the
// text immediately preceding where completion was invoked.
"editor.suggestSelection": "first",
// Allows pressing <TAB> to complete snippets such as `for` even when the
// completion list is not visible.
"editor.tabCompletion": "onlySnippets",
// By default, VS Code will populate code completion with words found in the
// current file when a language service does not provide its own completions.
// This results in code completion suggesting words when editing comments and
// strings. This setting will prevent that.
"editor.wordBasedSuggestions": false,
},
"dart.openDevTools": "flutter",
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

Editorの設定やflutter fvmの設定周りの共有用の設定ファイル

5 changes: 5 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ android {
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// applicationIdSuffix に {環境}.json で定義した flutterApplicationIdSuffix を指定
// 注意点は、gradleの変数名(applicationIdSuffix)と {環境}.json で定義した変数名が同じだと設定が反映されないので注意!
applicationIdSuffix flutterApplicationIdSuffix
// string/app_nameを作成し、{環境}.json で定義した flutterAppName を指定
resValue "string", "app_name", flutterAppName
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.leoleo.githubsearch.flutter_github_search">
<application
android:label="flutter_github_search"
android:label="@string/app_name"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
7 changes: 7 additions & 0 deletions dart_define/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"flavor": "development",
"flutterAppName": "(Dev)GithubSearch",
"flutterApplicationIdSuffix": ".development",
"githubAccessToken": "",
Copy link
Owner Author

Choose a reason for hiding this comment

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

秘匿情報はここの設定値をローカル環境にて各自書き換える。

"githubApiDomain": "api.github.com"
}
7 changes: 7 additions & 0 deletions dart_define/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"flavor": "production",
"flutterAppName": "GithubSearch",
"flutterApplicationIdSuffix": "",
"githubAccessToken": "",
"githubApiDomain": "api.github.com"
}
7 changes: 7 additions & 0 deletions dart_define/staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"flavor": "staging",
"flutterAppName": "(Stg)GithubSearch",
"flutterApplicationIdSuffix": ".staging",
"githubAccessToken": "",
"githubApiDomain": "api.github.com"
}
25 changes: 21 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
680683C1AB9F9B48F6AA247B /* Pods-Runner.release.xcconfig */,
9F15CC6C18E3D13D30559DD0 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -139,6 +138,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
2765D7B135C7DC9A08ABBBCC /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -197,6 +197,23 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
2765D7B135C7DC9A08ABBBCC /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
Expand Down Expand Up @@ -347,7 +364,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.leoleo.githubsearch.flutterGithubSearch;
PRODUCT_BUNDLE_IDENTIFIER = "com.leoleo.githubsearch.flutterGithubSearch${flutterApplicationIdSuffix}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -476,7 +493,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.leoleo.githubsearch.flutterGithubSearch;
PRODUCT_BUNDLE_IDENTIFIER = "com.leoleo.githubsearch.flutterGithubSearch${flutterApplicationIdSuffix}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -499,7 +516,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.leoleo.githubsearch.flutterGithubSearch;
PRODUCT_BUNDLE_IDENTIFIER = "com.leoleo.githubsearch.flutterGithubSearch${flutterApplicationIdSuffix}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 3 additions & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutter_github_search</string>
<string>$(flutterAppName)</string>
<key>CFBundleDisplayName</key>
<string>$(flutterAppName)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down
2 changes: 1 addition & 1 deletion lib/data/api/github/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final Provider githubApiProvider = Provider<GithubApi>((_) {
});

class GithubApi {
static const _authority = 'api.github.com';
static const _authority = String.fromEnvironment('githubApiDomain');
Copy link
Owner Author

Choose a reason for hiding this comment

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

static const perPage = 20;
final client = GithubApiHttpClient();
Future<SearchRepositoriesResponse> searchRepositories(
Expand Down
5 changes: 3 additions & 2 deletions lib/data/api/github/github_api_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import 'package:flutter_github_search/data/api/http_handler.dart';
import 'package:flutter_github_search/domain/exception/api_exceptions.dart';

class GithubApiHttpClient extends http.BaseClient {
// static const String _accessToken = "INPUT HERE TOKEN";
static const String _accessToken =
String.fromEnvironment('githubAccessToken');
Copy link
Owner Author

Choose a reason for hiding this comment

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

final Map<String, String> _headers = <String, String>{
'Accept': 'application/vnd.github.v3+json',
// 'Authorization': 'Bearer $_accessToken',
'Authorization': 'Bearer $_accessToken',
'X-GitHub-Api-Version': '2022-11-28',
};
final http.Client _client = http.Client();
Expand Down
47 changes: 47 additions & 0 deletions lib/ui/environment_variable/environment_variable_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Flutter imports:
import 'package:flutter/material.dart';

class EnvironmentVariableScreen extends StatelessWidget {
const EnvironmentVariableScreen({super.key});
@override
Widget build(BuildContext context) {
const flavor = String.fromEnvironment('flavor');
const appName = String.fromEnvironment('flutterAppName');
const applicationIdSuffix =
String.fromEnvironment('flutterApplicationIdSuffix');
const githubAccessToken = String.fromEnvironment('githubAccessToken');
const githubApiDomain = String.fromEnvironment('githubApiDomain');
return Scaffold(
appBar: AppBar(
title: const Text('Env Variable'),
),
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: const [
ListTile(
leading: Text('flavor'),
title: Text(flavor),
),
ListTile(
leading: Text('appName'),
title: Text(appName),
),
ListTile(
leading: Text('applicationIdSuffix'),
title: Text(applicationIdSuffix),
),
ListTile(
leading: Text('githubAccessToken'),
title: Text(githubAccessToken),
),
ListTile(
leading: Text('githubApiDomain'),
title: Text(githubApiDomain),
),
],
),
)),
);
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

環境変数確認用画面

22 changes: 22 additions & 0 deletions lib/ui/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import 'package:flutter/material.dart';

// Project imports:
import 'package:flutter_github_search/ui/package_info/package_info_screen.dart';
import 'package:flutter_github_search/ui/search/pagination/search_paging_screen.dart';
import 'package:flutter_github_search/ui/search/search_screen.dart';
import '../environment_variable/environment_variable_screen.dart';

class HomeScreen extends StatelessWidget {
const HomeScreen({super.key, required this.title});
Expand All @@ -25,6 +27,26 @@ class HomeScreen extends StatelessWidget {
child: Text(
'Paging compatible / non-compatible versions are available.'),
),
ListTile(
leading: const Icon(Icons.computer),
title: const Text("Environment Variable"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) =>
const EnvironmentVariableScreen()));
}),
ListTile(
leading: const Icon(Icons.info),
title: const Text("Package Info"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) =>
const PackageInfoScreen()));
}),
ListTile(
leading: const Icon(Icons.flutter_dash_outlined),
title: const Text("Paging compatible"),
Expand Down
Loading