mirror of
https://github.com/documize/community.git
synced 2025-08-09 07:25:23 +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');
|
self.send('auth');
|
||||||
});
|
});
|
||||||
} else {
|
} 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");
|
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'))
|
self.get('sectionService').fetch(page, "checkAuth", self.get('config'))
|
||||||
.then(function () {
|
.then(function () {
|
||||||
|
@ -361,7 +361,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
|
|
||||||
authStage2() {
|
authStage2() {
|
||||||
let self = this;
|
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('authenticated', true);
|
||||||
self.set('busy', true);
|
self.set('busy', true);
|
||||||
let page = this.get('page');
|
let page = this.get('page');
|
||||||
|
|
|
@ -65,12 +65,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
},
|
},
|
||||||
|
|
||||||
auth() {
|
auth() {
|
||||||
console.log(this.get('config'));
|
|
||||||
// missing data?
|
// missing data?
|
||||||
this.set('config.APIToken', this.get('config.APIToken').trim());
|
this.set('config.APIToken', this.get('config.APIToken').trim());
|
||||||
|
|
||||||
if (is.empty(this.get('config.APIToken'))) {
|
if (is.empty(this.get('config.APIToken'))) {
|
||||||
$("#papertrail-apitoken").addClass("error").focus();
|
$("#papertrail-apitoken").addClass("error").focus();
|
||||||
|
console.log("auth token empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
self.set('authenticated', true);
|
self.set('authenticated', true);
|
||||||
self.set('items', response);
|
self.set('items', response);
|
||||||
self.set('config.APIToken', '********'); // reset the api token once it has been sent to the host
|
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)
|
self.get('sectionService').fetch(page, "options", config)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
@ -97,15 +98,18 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
Ember.set(config, 'group', group);
|
Ember.set(config, 'group', group);
|
||||||
}
|
}
|
||||||
}, function (reason) { //jshint ignore: line
|
}, function (reason) { //jshint ignore: line
|
||||||
|
self.set('authenticated', false);
|
||||||
self.set('waiting', false);
|
self.set('waiting', false);
|
||||||
|
self.set('config.APIToken', ''); // clear the api token
|
||||||
self.displayError(reason);
|
self.displayError(reason);
|
||||||
|
console.log("get options call failed");
|
||||||
});
|
});
|
||||||
}, function (reason) { //jshint ignore: line
|
}, function (reason) { //jshint ignore: line
|
||||||
self.set('authenticated', false);
|
self.set('authenticated', false);
|
||||||
self.set('waiting', false);
|
self.set('waiting', false);
|
||||||
self.set('config.APIToken', ''); // clear the api token
|
self.set('config.APIToken', ''); // clear the api token
|
||||||
self.displayError(reason);
|
self.displayError(reason);
|
||||||
$("#papertrail-apitoken").addClass("error").focus();
|
console.log("auth token invalid");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<div class="pull-left width-45">
|
<div class="pull-left width-45">
|
||||||
<div class="input-form">
|
<div class="input-form">
|
||||||
<form {{action 'auth' on="submit"}}>
|
<form {{ action 'auth' on="submit" }} >
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
<div class="title">Papertrail Authentication
|
<div class="title">Papertrail Authentication
|
||||||
{{#if authenticated}}
|
{{#if authenticated}}
|
||||||
|
@ -14,13 +14,15 @@
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>API Key</label>
|
<label>API Key</label>
|
||||||
<div class="tip">API Token (from your profile)</div>
|
<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>
|
</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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -14,6 +14,7 @@ package papertrail
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"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) {
|
func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
|
||||||
result, err := fetchEvents(config)
|
result, err := fetchEvents(config)
|
||||||
|
|
||||||
|
if result == nil {
|
||||||
|
err = errors.New("nil result of papertrail query")
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
log.IfErr(ctx.SaveSecrets(`{"APIToken":""}`)) // invalid token, so reset it
|
||||||
|
|
||||||
if err.Error() == "forbidden" {
|
if err.Error() == "forbidden" {
|
||||||
provider.WriteForbidden(w)
|
provider.WriteForbidden(w)
|
||||||
} else {
|
} 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)
|
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)
|
req.Header.Set("X-Papertrail-Token", config.APIToken)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
res, err := client.Do(req)
|
var res *http.Response
|
||||||
|
res, err = client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("message", err)
|
log.Error("message", err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue