mirror of
https://github.com/documize/community.git
synced 2025-08-07 22:45:24 +02:00
github and paper trail secrets
This commit is contained in:
parent
7b2cdce328
commit
fb7d940a67
4 changed files with 35 additions and 15 deletions
|
@ -86,9 +86,9 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
self.send('auth');
|
||||
});
|
||||
} else {
|
||||
if (config.userId !== self.session.user.id) {
|
||||
if (config.userId !== self.get("session.session.authenticated.user.id")) {
|
||||
console.log("github auth wrong user ID, switching");
|
||||
self.set('config.userId', self.session.user.id);
|
||||
self.set('config.userId', self.get("session.session.authenticated.user.id"));
|
||||
}
|
||||
self.get('sectionService').fetch(page, "checkAuth", self.get('config'))
|
||||
.then(function () {
|
||||
|
@ -361,7 +361,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
|
||||
authStage2() {
|
||||
let self = this;
|
||||
self.set('config.userId', this.session.user.id);
|
||||
self.set('config.userId', self.get("session.session.authenticated.user.id"));
|
||||
self.set('authenticated', true);
|
||||
self.set('busy', true);
|
||||
let page = this.get('page');
|
||||
|
|
|
@ -65,12 +65,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
},
|
||||
|
||||
auth() {
|
||||
console.log(this.get('config'));
|
||||
// missing data?
|
||||
this.set('config.APIToken', this.get('config.APIToken').trim());
|
||||
|
||||
if (is.empty(this.get('config.APIToken'))) {
|
||||
$("#papertrail-apitoken").addClass("error").focus();
|
||||
console.log("auth token empty");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
self.set('authenticated', true);
|
||||
self.set('items', response);
|
||||
self.set('config.APIToken', '********'); // reset the api token once it has been sent to the host
|
||||
console.log("auth token OK");
|
||||
|
||||
self.get('sectionService').fetch(page, "options", config)
|
||||
.then(function (response) {
|
||||
|
@ -97,15 +98,18 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
Ember.set(config, 'group', group);
|
||||
}
|
||||
}, function (reason) { //jshint ignore: line
|
||||
self.set('authenticated', false);
|
||||
self.set('waiting', false);
|
||||
self.set('config.APIToken', ''); // clear the api token
|
||||
self.displayError(reason);
|
||||
console.log("get options call failed");
|
||||
});
|
||||
}, function (reason) { //jshint ignore: line
|
||||
self.set('authenticated', false);
|
||||
self.set('waiting', false);
|
||||
self.set('config.APIToken', ''); // clear the api token
|
||||
self.displayError(reason);
|
||||
$("#papertrail-apitoken").addClass("error").focus();
|
||||
console.log("auth token invalid");
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -2,25 +2,27 @@
|
|||
|
||||
<div class="pull-left width-45">
|
||||
<div class="input-form">
|
||||
<form {{action 'auth' on="submit"}}>
|
||||
<form {{ action 'auth' on="submit" }} >
|
||||
<div class="heading">
|
||||
<div class="title">Papertrail Authentication
|
||||
{{#if authenticated}}
|
||||
Complete
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="tip">Provide your Papertrail API token</div>
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>API Key</label>
|
||||
<div class="tip">API Token (from your profile)</div>
|
||||
{{focus-input id="papertrail-apitoken" type="password" value=config.APIToken readonly=isReadonly}}
|
||||
{{focus-input id="papertrail-apitoken" type="password" value=config.APIToken }}
|
||||
</div>
|
||||
<div class="regular-button button-blue" {{ action 'auth' }} >
|
||||
{{#if authenticated}}
|
||||
Re-Authenticate
|
||||
{{else}}
|
||||
Authenticate
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if authenticated}}
|
||||
<div class="regular-button button-blue" {{ action 'auth' }}>Re-Authenticate</div>
|
||||
{{else}}
|
||||
<div class="regular-button button-blue" {{ action 'auth' }}>Authenticate</div>
|
||||
{{/if}}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -14,6 +14,7 @@ package papertrail
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
|
@ -160,7 +161,14 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
|
|||
func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
|
||||
result, err := fetchEvents(config)
|
||||
|
||||
if result == nil {
|
||||
err = errors.New("nil result of papertrail query")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.IfErr(ctx.SaveSecrets(`{"APIToken":""}`)) // invalid token, so reset it
|
||||
|
||||
if err.Error() == "forbidden" {
|
||||
provider.WriteForbidden(w)
|
||||
} else {
|
||||
|
@ -256,11 +264,17 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
|
|||
filter = fmt.Sprintf("%s%sgroup_id=%d", filter, prefix, config.Group.ID)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", "https://papertrailapp.com/api/v1/events/search.json?"+filter, nil)
|
||||
var req *http.Request
|
||||
req, err = http.NewRequest("GET", "https://papertrailapp.com/api/v1/events/search.json?"+filter, nil)
|
||||
if err != nil {
|
||||
log.Error("new request", err)
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Papertrail-Token", config.APIToken)
|
||||
|
||||
client := &http.Client{}
|
||||
res, err := client.Do(req)
|
||||
var res *http.Response
|
||||
res, err = client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
log.Error("message", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue