Skip to content
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

Merged
merged 10 commits into from Feb 20, 2017
Merged

CLI registration #530

merged 10 commits into from Feb 20, 2017

Conversation

nono
Copy link
Member

@nono nono commented Feb 17, 2017

No description provided.

@nono nono requested a review from sebn February 17, 2017 14:27
@@ -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.')
Copy link
Contributor

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?

Copy link
Member Author

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) {
Copy link
Contributor

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
Copy link
Contributor

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')
Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Member Author

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).

Copy link
Contributor

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)

Copy link
Contributor

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()?

Copy link
Member Author

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
Copy link
Contributor

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?

url: 'none'
}
this.config.save()
this.config.setCozyUrl('http://cozy.local:8080/')
Copy link
Contributor

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/'

process.argv = []
let name = this.config.getDefaultDeviceName()
name.should.equal('tester')
conf.getCozyUrl().should.equal('http://cozy.local:8080/')
Copy link
Contributor

@sebn sebn Feb 17, 2017

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()) {
Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Contributor

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) {
  ...
}

Copy link
Member Author

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",
Copy link
Contributor

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?

Copy link
Member Author

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-io
Copy link

codecov-io commented Feb 17, 2017

Codecov Report

Merging #530 into master will decrease coverage by -0.03%.
The diff coverage is 51.16%.

@@            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
Impacted Files Coverage Δ
src/app.js 7.54% <ø> (-13.51%)
src/remote/cozy.js 100% <100%> (ø)
src/remote/index.js 68.96% <100%> (-2.01%)
src/local/index.js 93.61% <100%> (ø)
src/remote/registration.js 45.83% <45.83%> (ø)
src/config.js 91.89% <90.62%> (+5.22%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0afbf22...89242cd. Read the comment docs.

})
return cozy.authorize().then(
(res) => res,
(err) => { throw err }
Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Contributor

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)

@sebn
Copy link
Contributor

sebn commented Feb 17, 2017

Looks good to me overall.

The only thing really bothering me is the Config class exposing oauth-related save / load / delete methods:

  • I assume no cozy-desktop code will ever use them
  • save() / load() can be used to change / read whatever property of the class
  • they are not of the same abstraction level (hence the name conflict with persist())

@nono
Copy link
Member Author

nono commented Feb 20, 2017

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.

@sebn
Copy link
Contributor

sebn commented Feb 20, 2017

But I'd prefer to keep that for later

👌

@nono nono mentioned this pull request Feb 20, 2017
@sebn sebn merged commit e5dbfc1 into cozy-labs:master Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants