@@ -2,11 +2,11 @@ import { Command } from 'commander';
2
2
import * as acl_perms from '../../commands/solid-perms_acl' ;
3
3
import { setPermission , listPermissions , IPermissionOperation , IPermissionListing } from '../../commands/solid-perms' ;
4
4
import authenticate from '../../authentication/authenticate' ;
5
- import { addEnvOptions , changeUrlPrefixes , getAndNormalizeURL } from '../../utils/shellutils' ;
6
- import { writeErrorString } from '../../utils/util' ;
5
+ import { addEnvOptions , changeUrlPrefixes } from '../../utils/shellutils' ;
6
+ import { discoverAccessMechanism , writeErrorString } from '../../utils/util' ;
7
7
import chalk from 'chalk' ;
8
8
import SolidCommand from './SolidCommand' ;
9
- import list from '../../commands/ solid-list' ;
9
+ import { acp_ess_2 , hasAccessibleAcl , WithAcl } from "@inrupt/ solid-client" ;
10
10
const Table = require ( 'cli-table' ) ;
11
11
12
12
export default class PermsCommand extends SolidCommand {
@@ -32,26 +32,36 @@ export default class PermsCommand extends SolidCommand {
32
32
const authenticationInfo = await authenticate ( programOpts )
33
33
options . fetch = authenticationInfo . fetch
34
34
url = await changeUrlPrefixes ( authenticationInfo , url )
35
- // try WAC
36
- try {
37
- const listings = await acl_perms . listPermissions ( url , options )
38
- if ( listings ?. access . agent || listings ?. access . public ) {
39
- await formatACLPermissionListing ( url , listings , options )
40
- return ;
41
- }
42
- } catch ( e ) {
43
- if ( options . verbose ) writeErrorString ( 'Unable to list permissions for WAC' , e , options )
35
+
36
+
37
+ const { acp, acl } = await discoverAccessMechanism ( url , options . fetch )
38
+ if ( ! acp && ! acl ) {
39
+ if ( options . verbose ) writeErrorString ( `Could not list permissions for ${ url } ` , { message : "Could not find attached WAC or ACP management resource." } , options )
40
+ return ;
44
41
}
45
- // try Universal
46
- try {
47
- const listings = await listPermissions ( url , options )
48
- if ( listings ?. access . agent || listings ?. access . public ) {
49
- await formatPermissionListing ( url , listings , options )
50
- return ;
42
+ if ( acl ) {
43
+ try {
44
+ const listings = await acl_perms . listPermissions ( url , options )
45
+ if ( listings ?. access . agent || listings ?. access . public ) {
46
+ await formatACLPermissionListing ( url , listings , options )
47
+ return ;
48
+ }
49
+ } catch ( e ) {
50
+ if ( options . verbose ) writeErrorString ( 'Unable to list permissions for WAC' , e , options )
51
51
}
52
- } catch ( e ) {
53
- if ( options . verbose ) writeErrorString ( 'Unable to list permissions for ACP' , e , options )
54
52
}
53
+ if ( acp ) {
54
+ try {
55
+ const listings = await listPermissions ( url , options )
56
+ if ( listings ?. access . agent || listings ?. access . public ) {
57
+ await formatPermissionListing ( url , listings , options )
58
+ return ;
59
+ }
60
+ } catch ( e ) {
61
+ if ( options . verbose ) writeErrorString ( 'Unable to list permissions for ACP' , e , options )
62
+ }
63
+ }
64
+
55
65
if ( this . mayExit ) process . exit ( 0 )
56
66
} )
57
67
@@ -66,9 +76,8 @@ export default class PermsCommand extends SolidCommand {
66
76
For the current authenticated user please set id to "u".
67
77
For specific agents, set id to be the agent webid.
68
78
` )
69
- . option ( '--acl' , 'Enables ACL specific operations --default and --group' )
70
- . option ( '--default' , 'Set the defined permissions as default (only in --acl mode)' )
71
- . option ( '--group' , 'Process identifier as a group identifier (only in --acl mode)' )
79
+ . option ( '--default' , 'Set the defined permissions as default (only for pods on a WAC-based solid server)' )
80
+ . option ( '--group' , 'Process identifier as a group identifier (only for pods on a WAC-based solid server)' )
72
81
. option ( '-v, --verbose' , 'Log all operations' ) // Should this be default?
73
82
. action ( async ( url : string , permissions : string [ ] , options : any ) => {
74
83
@@ -109,18 +118,27 @@ export default class PermsCommand extends SolidCommand {
109
118
return ( { type, id, read, write, append, control, default : def } as IPermissionOperation )
110
119
} )
111
120
for ( let permission of parsedPermissions ) {
112
- try {
113
- await acl_perms . changePermissions ( url , [ permission ] , options )
114
- return ;
115
- } catch ( e ) {
116
- if ( options . verbose ) writeErrorString ( `Could not set permissions for ${ permission . id } using WAC` , e , options )
121
+ const { acp, acl } = await discoverAccessMechanism ( url , options . fetch )
122
+ if ( ! acp && ! acl ) {
123
+ if ( options . verbose ) writeErrorString ( `Could not set permissions for ${ permission . id } ` , { message : "Could not find attached WAC or ACP management resource." } , options )
124
+ continue ;
117
125
}
118
- try {
119
- if ( options . group || options . default ) throw new Error ( "Cannot set WAC-specific options such as group and default for non-WAC environments " )
120
- await setPermission ( url , [ permission ] , options )
121
- return ;
122
- } catch ( e ) {
123
- if ( options . verbose ) writeErrorString ( `Could not set permissions for ${ permission . id } using ACP` , e , options )
126
+ if ( acp ) {
127
+ try {
128
+ if ( options . group || options . default ) throw new Error ( "Cannot set WAC-specific options such as group and default for non-WAC environments " )
129
+ await setPermission ( url , [ permission ] , options )
130
+ return ;
131
+ } catch ( e ) {
132
+ if ( options . verbose ) writeErrorString ( `Could not set permissions for ${ permission . id } using ACP` , e , options )
133
+ }
134
+ }
135
+ if ( acl ) {
136
+ try {
137
+ await acl_perms . changePermissions ( url , [ permission ] , options )
138
+ return ;
139
+ } catch ( e ) {
140
+ if ( options . verbose ) writeErrorString ( `Could not set permissions for ${ permission . id } using WAC` , e , options )
141
+ }
124
142
}
125
143
}
126
144
}
0 commit comments