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
CLI registration #530
CLI registration #530
Conversation
@@ -79,18 +78,17 @@ program | |||
program | |||
.command('sync') | |||
.description('Synchronize the local filesystem and the remote cozy') | |||
.option('-k, --insecure', 'Turn off HTTPS certificate verification.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not something self-hosted users will want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, but it is a priority for the short term, and the code we had for that will no longer work
src/bin/repl.js
Outdated
@@ -12,7 +12,7 @@ The following objects are available: | |||
app The cozy-desktop app | |||
config Your active cozy-desktop configuration`) | |||
|
|||
if ((config.deviceName != null) && (config.url != null) && (config.path != null)) { | |||
if (config.url) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.config.isValid()
?
src/config.js
Outdated
} else { | ||
return false | ||
saveMode (mode) { | ||
let old = this.config.mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
src/config.js
Outdated
if (old === mode) { | ||
return true | ||
} else if (old) { | ||
throw new Error('Incompatible mode') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error(`Once you set mode to "${old}", you cannot switch to "${mode}"`)
src/config.js
Outdated
|
||
save (key, value) { | ||
this.config.credentials[key] = value | ||
return Promise.resolve(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have some kind Config#oauthStorage()
return the expected interface? (not sure how you expect to use it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is to persist what cozy-client-js puts in this storage in the config file (it is the client informations and the OAuth tokens).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and move save
/ load
/ ...
to the new object)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this the reason for the persist()
method not to be named save()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :-p
src/config.js
Outdated
} | ||
|
||
export default Config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export default class Config
directly?
test/unit/config.js
Outdated
url: 'none' | ||
} | ||
this.config.save() | ||
this.config.setCozyUrl('http://cozy.local:8080/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const url = 'http://cozy.local:8080/'
test/unit/config.js
Outdated
process.argv = [] | ||
let name = this.config.getDefaultDeviceName() | ||
name.should.equal('tester') | ||
conf.getCozyUrl().should.equal('http://cozy.local:8080/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started using the following pattern in new code:
should(conf.getCozyUrl()).equal(...)
Pros:
- no monkey-patching involved...
- ... which makes it more Flow-friendly
- assertion error in case
getCozyUrl()
returns undefined, instead of undefined-has-no-should-property
Please let me now in case you disagree, so I stop using it everywhere.
src/bin/cli.js
Outdated
if (err) { return process.exit(1) } | ||
}) | ||
} else { | ||
if (!app.config.hasClient()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.config.isValid()
src/bin/repl.js
Outdated
@@ -3,7 +3,7 @@ import { start } from 'repl' | |||
import App from '../app' | |||
|
|||
const app = new App(process.env.COZY_DESKTOP_DIR) | |||
const config = app.config.getDevice() | |||
const config = app.config.config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to remove the multi-config support? (just out of curiosity)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, there were no multi-config support. I had tried it, but it was too error-prone and even if the config file can have several "devices", only the first one was really used.
src/config.js
Outdated
} | ||
// Get the path on the local file system of the synchronized folder | ||
getSyncPath () { | ||
return this.config.path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether es getters/setters are supported... Would it make sense to use them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean:
get syncPath() {
...
}
set syncPath(path) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
@@ -2,7 +2,7 @@ | |||
"name": "cozy-desktop", | |||
"version": "0.16.0", | |||
"description": "File Synchronization Client for Cozy Cloud", | |||
"homepage": "https://github.com/cozy-labs/cozy-desktop", | |||
"homepage": "https://docs.cozy.io/en/mobile/desktop.html", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just disable the cozy-desktop github pages if they are not supposed to be the main entry point for users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to keep documentation for users on cozy.io, and on github for people who want to contribute to our projects
Codecov Report
@@ Coverage Diff @@
## master #530 +/- ##
==========================================
- Coverage 71.22% 71.19% -0.03%
==========================================
Files 18 19 +1
Lines 1449 1399 -50
==========================================
- Hits 1032 996 -36
+ Misses 417 403 -14
Continue to review full report at Codecov.
|
src/remote/registration.js
Outdated
}) | ||
return cozy.authorize().then( | ||
(res) => res, | ||
(err) => { throw err } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just .catch(err => { throw err })
?
Also, since process()
is not async and it returns the promise, is the catch
block even needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I've added them to console.log this step. Then I removed the console.log, but the then()
can also be removed.
@@ -14,25 +15,37 @@ const cozyStackDouble = new CozyStackDouble() | |||
describe('RemoteCozy', function () { | |||
before(() => cozyStackDouble.start()) | |||
beforeEach(deleteAll) | |||
before('instanciate config', configHelpers.createConfig) | |||
before('register OAuth client', configHelpers.registerClient) | |||
after('clean config directory', configHelpers.cleanConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't mocha use the function name as a description anyway? (assuming it is named)
Looks good to me overall. The only thing really bothering me is the
|
For the config class that also exports the storage interface, I'm OK with you that it should be refactored. But I'd prefer to keep that for later. I'd like to explore token refresh and device revocation before. |
👌 |
b00b5e5
to
89242cd
Compare
No description provided.