Thanks Matt for sharing, so it looks like there's going to be a bit of work 
on my end to create a new plugin then which I'd like to do depending on the 
feasibility vs. need at this stage of our project.  I'll definitely reach 
out for assistance if and when I get this plugin started.

On Sunday, September 28, 2014 8:44:23 AM UTC-7, Matthew Moore wrote:
>
> Hrm, sadly there doesn't seem to be a nice client library for this API 
> like there are for a lot of the cloud APIs...
>
>
>
> Regardless, the various Credential 
> <http://javadoc.google-oauth-java-client.googlecode.com/hg/1.8.0-beta/com/google/api/client/auth/oauth2/Credential.html?is-external=true>
>  
> objects implement HttpRequestInitializer 
> <http://javadoc.google-http-java-client.googlecode.com/hg/1.8.3-beta/com/google/api/client/http/HttpRequestInitializer.html?is-external=true>.
>   
> Translation: they understand how to annotate HttpRequests 
> <http://javadoc.google-http-java-client.googlecode.com/hg/1.8.3-beta/com/google/api/client/http/HttpRequest.html>
>  
> with:
>
> -H "Authorization: Bearer $TOKEN"  \
>
> Here is some sample code 
> <https://github.com/jenkinsci/google-oauth-plugin/blob/master/src/main/java/com/google/jenkins/plugins/util/MetadataReader.java>
>  
> that deals with raw HttpRequests in the oauth2 plugin as a start, although 
> it doesn't use credentials or POST.
>
>
>
>
> I *think* the code you are going to want in a plugin is going to look 
> something like (beware, I have not tested this code in any way):
> HttpRequestFactory requestFactory =
>    new NetHttpTransport().createRequestFactory(*{insert Credential}*);
>
> // Handles loading the file properly with remoting, but proxies thru the 
> master.
> // By comparison, Storage uploads directly from the slave, to decrease 
> load on
> // the master, but the code for that is a bit trickier to get right, and 
> this is
> // a fine starting point.
> InputStreamContent content = new InputStreamContent();
> content.inputStream = filePath.read();
> content.type = "*{fill in mime type}*";
>
> HttpRequest request = requestFactory.buildPostRequest(
>    new GenericUrl("
> https://www.googleapis.com/upload/chromewebstore/v1.1/items";),
>    content);
>
> request.getHeaders().set("x-goog-api-version", 2);
>
> // Where the magic happens
> request.execute();
>
>
> There are also pretty good facilities in place for mocking out 
> HttpRequest, just factor the above code in your plugin such that 
> HttpRequestFactory can be passed in, and you should be able to write decent 
> tests.  For factoring, see how the aforementioned sample code 
> <https://github.com/jenkinsci/google-oauth-plugin/blob/master/src/main/java/com/google/jenkins/plugins/util/MetadataReader.java#L77>
>  
> structures things, and how its tests look 
> <https://github.com/jenkinsci/google-oauth-plugin/blob/master/src/test/java/com/google/jenkins/plugins/util/MetadataReaderTest.java>.
>   
> Also, there is a fair amount of overlap with the storage plugin, if you 
> ignore the fact that it has a nice client library.
>
>
>
> If you do head down the path of writing the plugin, please let me know and 
> I'd be happy to give you pointers and help review the code (or loop in a 
> suitable surrogate).
>
> thanks, and hopefully this is helpful.
> -M
>
>
>
> On Sat, Sep 27, 2014 at 11:27 PM, Calvin <[email protected] 
> <javascript:>> wrote:
>
>> Ok sorry, I'm fairly new to using Google's API and Jenkins and I think I 
>> see where my confusion lies, I was thinking that the Google OAuth Plugin 
>> automatically provides the scopes, however after relooking at 
>> https://wiki.jenkins-ci.org/display/JENKINS/Google+OAuth+Plugin, I 
>> realize that this plugin just provides the Google service account options 
>> that I can associate to Jenkins and then I would need to probably implement 
>> another plugin like the GoogleCloudStorage that exposes the scopes needed 
>> to access the Chrome Web Store APIs.  I want to be able to do something 
>> like the following within Jenkins as a post process to automatically 
>> publish/update a Chrome extension we've developed directly to the Chrome 
>> Store,
>>
>> > curl \-H "Authorization: Bearer $TOKEN"  \-H "x-goog-api-version: 2" \-X 
>> > POST \-T $FILE_NAME \-v \
>> https://www.googleapis.com/upload/chromewebstore/v1.1/items
>>
>>
>> On Saturday, September 27, 2014 9:58:57 PM UTC-7, Matthew Moore wrote:
>>>
>>> I assume you are building a plugin to access this API, using an OAuth2 
>>> credential?  Otherwise, I'll probably need some more context on how you 
>>> plan to wire things up...
>>>
>>>
>>> If you are building such a plugin you should look at how the Google 
>>> Cloud Storage plugin specifies its OAuth2 scope requirement: 
>>> https://github.com/jenkinsci/google-storage-plugin/blob/master/src/main/
>>> java/com/google/jenkins/plugins/storage/GoogleCloudStorageUploader.
>>> java#L51
>>>
>>> Putting an appropriately constructed @RequiresDomain on any describable 
>>> (e.g. Publishers) will make the error you are seeing go away.  As I said 
>>> (more tersely) before, we scan for these annotations to dynamically 
>>> populate the pertinent set of scopes for installed plugins.
>>>
>>>
>>>
>>>
>>> Specifically, you are going to want to define:
>>> public class ChromeWebStoreScopeRequirement extends 
>>> GoogleOAuth2ScopeRequirement {
>>>
>>> which returns the scope you list, similar to StorageScopeRequirement 
>>> <https://github.com/jenkinsci/google-storage-plugin/blob/master/src/main/java/com/google/jenkins/plugins/storage/StorageScopeRequirement.java>,
>>>  
>>> then annotate something like this:
>>> @RequiresDomain(value = ChromeWebStoreScopeRequirement.class)
>>> public class ChromeWebStorePublisher extends Recorder {
>>>
>>>
>>> or maybe I am completely misunderstanding your intent...  Hope that 
>>> helps.
>>> -M
>>>
>>>
>>>
>>> On Fri, Sep 26, 2014 at 9:51 AM, Calvin <[email protected]> wrote:
>>>
>>>> Hi Matt,
>>>>
>>>> I have both the Google OAuth Plugin as well as the OAuth Credential 
>>>> Plugin installed and enabled.  The scope I'm needing specifically from the 
>>>> Google OAuth Plugin is, scope=https://www.googleapis.com/auth/
>>>> chromewebstore to use this API, https://developer.chrome.
>>>> com/webstore/using_webstore_api
>>>>
>>>>
>>>> <https://lh4.googleusercontent.com/-JiykxSQwKIg/VCWZhx-P5UI/AAAAAAAAAeA/tq0xSrvd-mQ/s1600/Screen%2BShot%2B2014-09-26%2Bat%2B9.48.06%2BAM.png>
>>>>
>>>> On Friday, September 26, 2014 9:35:35 AM UTC-7, Matthew Moore wrote:
>>>>>
>>>>> What plugins do you have installed that require OAuth?  This plugin 
>>>>> dynamically determines the set of OAuth scopes that might be required by 
>>>>> installed plugins, to allow you to pick and choose which should be 
>>>>> allowed 
>>>>> for a given credential.
>>>>>
>>>>> Try installing google-storage-plugin, for example, and the storage 
>>>>> scope should show up where you currently have that error message.
>>>>>
>>>>>
>>>>> LMK if you are expecting something to show up, which isn't.
>>>>> -M
>>>>>
>>>>> On Thu, Sep 25, 2014 at 11:04 PM, Calvin <[email protected]> 
>>>>> wrote:
>>>>>
>>>>>> Just installed the Google OAuth Plugin into Jenkins in addition to 
>>>>>> having the OAuth Credential Plugin, and upon configuring a new 
>>>>>> credential 
>>>>>> domain neither plugins load the Google OAuth scopes.  Anybody experience 
>>>>>> this before?
>>>>>>
>>>>>>
>>>>>> <https://lh5.googleusercontent.com/-h5XOtXgqPrM/VCUB1xLwcdI/AAAAAAAAAdw/VgS-687r3c4/s1600/Screen%2BShot%2B2014-09-25%2Bat%2B5.33.34%2BPM.png>
>>>>>>
>>>>>>  -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Jenkins Developers" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected].
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> Matthew Moore
>>>>> DI/Docker (aka Convoy)
>>>>> Developer Infrastructure @ Google
>>>>>  
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Jenkins Developers" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Matthew Moore
>>> DI/Docker (aka Convoy)
>>> Developer Infrastructure @ Google
>>>  
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Jenkins Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Matthew Moore
> DI/Docker (aka Convoy)
> Developer Infrastructure @ Google
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to