Commit ae69e025 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Update on CLI; bugfix in CreateGroupCall; added workaround for invited registration trigger

parent 32687700
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -62,3 +62,5 @@ nbactions.xml
/gms/node/

nb-configuration.xml
dependency-reduced-pom.xml
+2 −6
Original line number Diff line number Diff line
#base_url=http://localhost:8081/gms
#client_id=test
#client_secret=test
base_url=https://sso.ia2.inaf.it/gms
client_id=sso-admin
client_secret=cXjbauYe8g
base_url=http://localhost:8082/gms/ws/jwt
token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjM0ZmU4MDcwMDVhNTcxMTYifQ.eyJpc3MiOiJzc28uaWEyLmluYWYuaXQiLCJzdWIiOiIyMzg2IiwiaWF0IjoxNTg3NjU5NzYxLCJleHAiOjE1ODc3NDYxNjEsImF1ZCI6ImdtcyJ9.KcXRAciG3ApqlE8MFM8VYW9WAX3hEZb7Vk8jB9uJtWsOMU48ha_Ybb4k_f0nrD2jhOxwaNn2QMxWZuflwCf1N-KiCj5Ff9f8xKOrrXZrl-w1H3_dwtMlIS8t2b0-w0WwRJ7UIhrwVBzmCcWinD3qJhFPzyO2pi-A4aXV57RpJ68VXfALQXeHK0sslrf-RgAU3xWYOgjGTUoGB5BQYC9huA_bZ0eV1HFcancs9pDdoTusqZs8OkPFCJbo7-L5eibsuykqnLHztYdCcP2Vtvtwb0pww-ofWZblIHzoMI8i-ipnfLJETG8Dpc7FrhjCYLw3AEGZg4U1wYTeqG3HRbPXSQ
+21 −21
Original line number Diff line number Diff line
@@ -2,12 +2,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>it.inaf.ia2</groupId>
    <artifactId>gms-cli</artifactId>
    <version>0.0.1-SNAPSHOT</version>
@@ -15,34 +9,40 @@
    <description>GMS Command Line Client</description>

    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>12</maven.compiler.source>
        <maven.compiler.target>12</maven.compiler.target>
        <java.version>12</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>gms-client-lib</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>it.inaf.ia2.gms.cli.CLI</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
+27 −42
Original line number Diff line number Diff line
package it.inaf.ia2.gms.cli;

import it.inaf.ia2.gms.client.GmsClient;
import it.inaf.ia2.gms.client.model.Permission;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class CLI implements CommandLineRunner {
public class CLI {

    private final GmsClient client;

    public CLI() throws IOException {
    public static void main(String[] args) throws Exception {
        new CLI().run(args);
    }

    private CLI() throws IOException {

        File config = new File("gms.properties");
        if (!config.exists()) {
@@ -35,22 +35,15 @@ public class CLI implements CommandLineRunner {
            System.exit(1);
        }

        String clientId = (String) properties.get("client_id");
        if (clientId == null) {
            System.err.println("Missing client_id in gms.properties");
            System.exit(1);
        }

        String clientSecret = (String) properties.get("client_secret");
        if (clientSecret == null) {
            System.err.println("Missing client_secret in gms.properties");
        String token = (String) properties.get("token");
        if (token == null) {
            System.err.println("Missing token in gms.properties");
            System.exit(1);
        }

        client = new GmsClient(baseUrl, clientId, clientSecret);
        client = new GmsClient(baseUrl).setAccessToken(token);
    }

    @Override
    public void run(String... args) throws Exception {
        if (args.length < 2) {
            displayUsage();
@@ -58,39 +51,43 @@ public class CLI implements CommandLineRunner {

        switch (args[0]) {
            case "create-group":
                client.addGroup(getNames(args, 1));
                boolean leaf = false;
                if (args.length > 1) {
                    leaf = Boolean.parseBoolean(args[2]);
                }
                client.createGroup(args[1], leaf);
                System.out.println("Group created");
                break;
            case "delete-group":
                client.removeGroup(getNames(args, 1));
                client.deleteGroup(args[1]);
                System.out.println("Group deleted");
                break;
            case "add-member":
                if (args.length < 3) {
                    displayUsage();
                }
                client.addMember(getNames(args, 1, args.length - 2), args[args.length - 1]);
                client.addMember(args[1], args[2]);
                System.out.println("Member added");
                break;
            case "remove-member":
                if (args.length < 3) {
                    displayUsage();
                }
                client.removeMember(getNames(args, 1, args.length - 2), args[args.length - 1]);
                client.removeMember(args[1], args[2]);
                System.out.println("Member removed");
                break;
            case "add-permission":
                if (args.length < 4) {
                    displayUsage();
                }
                client.addPermission(getNames(args, 1, args.length - 3), args[args.length - 2], args[args.length - 1]);
                client.addPermission(args[1], args[2], Permission.valueOf(args[3]));
                System.out.println("Permission added");
                break;
            case "delete-permission":
                if (args.length < 4) {
                    displayUsage();
                }
                client.removePermission(getNames(args, 1, args.length - 2), args[args.length - 1]);
                client.removePermission(args[1], args[2]);
                System.out.println("Permission removed");
                break;
            default:
@@ -101,24 +98,12 @@ public class CLI implements CommandLineRunner {

    private void displayUsage() {
        System.out.println("java -jar gms-client.jar\n"
                + "    create-group <name1 name2 name3>\n"
                + "    delete-group <name1 name2 name3>\n"
                + "    add-member <name1 name2 name3> <user_id>\n"
                + "    remove-member <name1 name2 name3> <user_id>\n"
                + "    add-permission <name1 name2 name3> <user_id> <permission>\n"
                + "    delete-permission <name1 name2 name3> <user_id>");
                + "    create-group <name1.name2.name3> <leaf>\n"
                + "    delete-group <name1.name2.name3>\n"
                + "    add-member <name1.name2.name3> <user_id>\n"
                + "    remove-member <name1.name2.name3> <user_id>\n"
                + "    add-permission <name1.name2.name3> <user_id> <permission>\n"
                + "    delete-permission <name1.name2.name3> <user_id>");
        System.exit(0);
    }

    private List<String> getNames(String[] args, int startIndex) {
        return getNames(args, startIndex, args.length - 1);
    }

    private List<String> getNames(String[] args, int startIndex, int endIndex) {
        List<String> names = new ArrayList<>();
        for (int i = startIndex; i <= endIndex; i++) {
            names.add(args[i]);
        }
        return names;
    }
}
+0 −13
Original line number Diff line number Diff line
package it.inaf.ia2.gms.cli;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class GmsCliApplication {

	public static void main(String[] args) {
		SpringApplication.run(GmsCliApplication.class, args);
	}

}
Loading