示例#1
0
func main() {
	clientID, secret, parentorgGlobalID, suborgGlobalID, host := parseArguments()

	//Step 0: Authenticate
	authenticatedClient := itsyouonline.NewItsyouonline()
	authenticatedClient.BaseURI = host + "/api"
	authenticatedUsername, authenticatedGlobalID, _, err := authenticatedClient.LoginWithClientCredentials(clientID, secret)

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	if authenticatedUsername != "" {
		fmt.Printf("Authenticated with user %s\n", authenticatedUsername)
	}
	if authenticatedGlobalID != "" {
		fmt.Printf("Authenticated with organization %s\n", authenticatedGlobalID)
	}

	//Step 1: Create the suborganization
	suborg := itsyouonline.Organization{Globalid: suborgGlobalID}

	fmt.Printf("Creating suborganization %s in parent %s\n", suborgGlobalID, parentorgGlobalID)
	_, _, err = authenticatedClient.Organizations.CreateNewSubOrganization(parentorgGlobalID, suborg, nil, nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	//Step2: Access the suborganization
	fmt.Printf("Getting the suborganization information\n")
	suborg, _, err = authenticatedClient.Organizations.GetOrganization(suborgGlobalID, nil, nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	fmt.Println(suborg)

	//Step 3: Delete the entry from step 1
	fmt.Printf("Deleting organization %s\n", suborgGlobalID)
	_, err = authenticatedClient.Organizations.DeleteOrganization(suborgGlobalID, nil, nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
示例#2
0
文件: main.go 项目: Jumpscale/go-raml
func main() {
	flag.Parse()
	if *appID == "" || *appSecret == "" {
		log.Fatalf("please specify itsyou.online application ID & API Key")
	}

	// create itsyou.online client
	ioc := itsyouonline.NewItsyouonline()

	// get oauth2 token
	_, err := ioc.LoginWithClientCredentials(*appID, *appSecret)
	if err != nil {
		log.Fatalf("failed to get itsyou.online token:%v\n", err)
	}

	// create itsyou.online JWT token
	jwtToken, err := ioc.CreateJWTToken([]string{"user:memberof:goraml"}, []string{"external1"})
	if err != nil {
		log.Fatalf("failed to create itsyou.online JWT token:%v", err)
	}

	// create goramldir client
	gr := Newgoramldir()

	// set goramldir authorization header to use JWT token
	gr.AuthHeader = "token " + jwtToken

	// calling GET /users/john
	user, resp, err := gr.UsersUsernameGet("john", nil, nil)
	if err != nil {
		log.Fatalf("failed to GET /users:%v, resp code = %v", err, resp.StatusCode)
	}

	if resp.StatusCode != 200 {
		log.Fatalf("GET /users failed. http status code = %v", resp.StatusCode)
	}

	log.Printf("user = %v\n", user)

}
示例#3
0
func main() {
	clientID, secret, host := parseArguments()

	//Step 1: Create an itsyou.online client, log in with client credentials and create a registry entry
	authenticatedClient := itsyouonline.NewItsyouonline()
	authenticatedClient.BaseURI = host + "/api"
	username, globalid, _, err := authenticatedClient.LoginWithClientCredentials(clientID, secret)

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	entry := itsyouonline.RegistryEntry{Key: "testscriptkey", Value: "testscriptvalue"}

	if username != "" {
		fmt.Printf("Creating/updating a registry entry for user: %s\n", username)
		authenticatedClient.AddUserRegistryEntry(username, entry, nil, nil)
	}
	if globalid != "" {
		fmt.Printf("Creating/updating a registry entry for organization: %s\n", globalid)
		authenticatedClient.AddOrganizationRegistryEntry(globalid, entry, nil, nil)
	}

	//Step 2: List the registry entries

	var entries []itsyouonline.RegistryEntry
	if username != "" {
		entries, _, _ = authenticatedClient.ListUserRegistry(username, nil, nil)
	}
	if globalid != "" {
		entries, _, _ = authenticatedClient.ListOrganizationRegistry(globalid, nil, nil)
	}

	for _, e := range entries {
		fmt.Printf("Key: %s - Value: %s\n", e.Key, e.Value)
	}

	//Step 3: Get the registry entry using an anonymous client
	anonymousClient := itsyouonline.NewItsyouonline()
	anonymousClient.BaseURI = host + "/api"

	var requestedEntry itsyouonline.RegistryEntry
	fmt.Println("Getting the registry entry using an unauthenticated client")
	if username != "" {
		requestedEntry, _, err = anonymousClient.GetUserRegistryEntry("testscriptkey", username, nil, nil)
	}
	if globalid != "" {
		requestedEntry, _, err = anonymousClient.GetOrganizationRegistryEntry("testscriptkey", username, nil, nil)
	}

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	fmt.Printf("Key: %s - Value: %s\n", requestedEntry.Key, requestedEntry.Value)

	//Step 4: Delete the entry from step 1
	if username != "" {
		fmt.Printf("Deleting a registry entry for user: %s\n", username)
		authenticatedClient.DeleteUserRegistryEntry("testscriptkey", username, nil, nil)
	}
	if globalid != "" {
		fmt.Printf("Deleting a registry entry for organization: %s\n", globalid)
		authenticatedClient.DeleteOrganizationRegistryEntry("testscriptkey", globalid, nil, nil)
	}
}