@@ -2,11 +2,11 @@ import { Command } from 'commander';
22import * as acl_perms from '../../commands/solid-perms_acl' ;
33import { setPermission , listPermissions , IPermissionOperation , IPermissionListing } from '../../commands/solid-perms' ;
44import 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' ;
77import chalk from 'chalk' ;
88import SolidCommand from './SolidCommand' ;
9- import list from '../../commands/ solid-list' ;
9+ import { acp_ess_2 , hasAccessibleAcl , WithAcl } from "@inrupt/ solid-client" ;
1010const Table = require ( 'cli-table' ) ;
1111
1212export default class PermsCommand extends SolidCommand {
@@ -32,26 +32,36 @@ export default class PermsCommand extends SolidCommand {
3232 const authenticationInfo = await authenticate ( programOpts )
3333 options . fetch = authenticationInfo . fetch
3434 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 ;
4441 }
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 )
5151 }
52- } catch ( e ) {
53- if ( options . verbose ) writeErrorString ( 'Unable to list permissions for ACP' , e , options )
5452 }
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+
5565 if ( this . mayExit ) process . exit ( 0 )
5666 } )
5767
@@ -66,9 +76,8 @@ export default class PermsCommand extends SolidCommand {
6676 For the current authenticated user please set id to "u".
6777 For specific agents, set id to be the agent webid.
6878 ` )
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)' )
7281 . option ( '-v, --verbose' , 'Log all operations' ) // Should this be default?
7382 . action ( async ( url : string , permissions : string [ ] , options : any ) => {
7483
@@ -109,18 +118,27 @@ export default class PermsCommand extends SolidCommand {
109118 return ( { type, id, read, write, append, control, default : def } as IPermissionOperation )
110119 } )
111120 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 ;
117125 }
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+ }
124142 }
125143 }
126144 }
0 commit comments