void Update() { // Call Update() on AccessTokenGetter and on WwwRequestInProgress to trigger execution of pending tasks // if there are any. AccessTokenGetter.Update(); WwwRequestInProgress.Update(); }
/// <summary> /// Sends an HTTP request to GCP to verify whether or not configured bucket name exist. Invokes action /// postResponseAction on the WWW instance holding the request when a response to the request is received. /// </summary> /// <param name="postResponseAction">An action to be invoked on the WWW instance holding the HTTP request /// when the response is available.</param> private static void CheckBucketExistence(Action <WWW> postResponseAction) { // see https://cloud.google.com/storage/docs/getting-bucket-information on getting bucket information. var bucketInfoUrl = string.Format("https://www.googleapis.com/storage/v1/b/{0}", QuickDeployWindow.Config.CloudStorageBucketName); var request = HttpRequestHelper.SendHttpGetRequest(bucketInfoUrl, null, GetDictionaryWithAuthorizationHeader()); WwwRequestInProgress.TrackProgress(request, "Checking whether bucket exists.", postResponseAction); }
/// <summary> /// Sends a request to GCP to change visibility of specified file to public, and invokes the result handler /// action on the HTTP response. /// </summary> /// <param name="onMakeBundlePublicResponseAction">An action to be invoked on the WWW instance holding the HTTP /// request once the response to the request to make the bundle public is available.</param> private static void MakeBundlePublic(Action <WWW> onMakeBundlePublicResponseAction) { // see https://cloud.google.com/storage/docs/access-control/making-data-public on making data public. var makePublicEndpoint = string.Format("https://www.googleapis.com/storage/v1/b/{0}/o/{1}/acl", QuickDeployWindow.Config.CloudStorageBucketName, QuickDeployWindow.Config.CloudStorageObjectName); var requestJsonContents = JsonUtility.ToJson(new PublicAccessRequest()); var makeBundlePublicWww = SendAuthenticatedPostRequest(makePublicEndpoint, Encoding.UTF8.GetBytes(requestJsonContents), "application/json"); WwwRequestInProgress.TrackProgress(makeBundlePublicWww, "Making remote file public", onMakeBundlePublicResponseAction); }
/// <summary> /// Sends an HTTP request to GCP to upload the file according to quick deploy configurations, and /// invokes the handler action on the response. /// </summary> /// <param name="postResponseAction">An action to be invoked on the www instance holding the http request /// once the response to the request to upload the bundle is available</param> private static void UploadBundleFile(Action <WWW> postResponseAction) { // See https://cloud.google.com/storage/docs/uploading-objects var uploadEndpoint = string.Format("https://www.googleapis.com/upload/storage/v1/b/{0}/o?uploadType=media&name={1}", QuickDeployWindow.Config.CloudStorageBucketName, QuickDeployWindow.Config.CloudStorageObjectName); var assetBundleFileBytes = File.ReadAllBytes(QuickDeployWindow.Config.AssetBundleFileName); var request = SendAuthenticatedPostRequest(uploadEndpoint, assetBundleFileBytes, "application/octet-stream"); WwwRequestInProgress.TrackProgress(request, "Uploading file to Google Cloud Storage", postResponseAction); }
/// <summary> /// Sends an HTTP request to OAuth2 token uri to retrieve, process and store needed tokens. /// </summary> /// <param name="grantDictionary">A dictionary containing OAuth2 grant type and grant values to be used when /// requesting access token. The dictionary will be mutated by adding more credentials values needed to /// send the token request.</param> /// <param name="postTokenAction"></param> private static void RequestToken(Dictionary <string, string> grantDictionary, Action postTokenAction) { var credentials = OAuth2Credentials.GetCredentials(); grantDictionary.Add("client_id", credentials.client_id); grantDictionary.Add("client_secret", credentials.client_secret); WwwRequestInProgress.TrackProgress( HttpRequestHelper.SendHttpPostRequest(credentials.token_uri, grantDictionary, null), "Requesting access token", completeTokenRequest => { HandleTokenResponse(completeTokenRequest); postTokenAction(); }); }
/// <summary> /// Sends an HTTP request to GCP to create a bucket with the configured name, and invokes the response /// handler on the HTTP response. /// </summary> /// <param name="onCreateBucketResponseAction">An action to be invoked on the www instance holding the HTTP request /// once the response to the request to create bucket is available.</param> private static void CreateBucket(Action <WWW> onCreateBucketResponseAction) { var credentials = OAuth2Credentials.GetCredentials(); // see https://cloud.google.com/storage/docs/creating-buckets on creating buckets. var createBucketEndPoint = string.Format("https://www.googleapis.com/storage/v1/b?project={0}", credentials.project_id); var createBucketRequest = new CreateBucketRequest { name = QuickDeployWindow.Config.CloudStorageBucketName }; var jsonBytes = Encoding.UTF8.GetBytes(JsonUtility.ToJson(createBucketRequest)); var createBucketWww = SendAuthenticatedPostRequest(createBucketEndPoint, jsonBytes, "application/json"); WwwRequestInProgress.TrackProgress( createBucketWww, string.Format("Creating bucket with name \"{0}\"", createBucketRequest.name), onCreateBucketResponseAction); }