Exemplo n.º 1
0
func AddInstance(instanceName string, flags *AddInstanceFlags) error {
	data := AddInstanceRequestContent{
		Name:        instanceName,
		Url:         flags.ArtifactoryInstanceDetails.Url,
		User:        flags.ArtifactoryInstanceDetails.User,
		Password:    flags.ArtifactoryInstanceDetails.Password,
		Description: flags.Description,
		Location:    flags.Location}
	requestContent, err := json.Marshal(data)
	if err != nil {
		return cliutils.CheckError(errors.New("Failed to execute request. " + cliutils.GetDocumentationMessage()))
	}
	missionControlUrl := flags.MissionControlDetails.Url + "api/v1/instances"
	httpClientDetails := utils.GetMissionControlHttpClientDetails(flags.MissionControlDetails)
	resp, body, err := ioutils.SendPost(missionControlUrl, requestContent, httpClientDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode == 201 || resp.StatusCode == 204 {
		fmt.Println("Mission Control response: " + resp.Status)
	} else {
		return cliutils.CheckError(errors.New(resp.Status + ". " + utils.ReadMissionControlHttpMessage(body)))
	}
	return nil
}
Exemplo n.º 2
0
func Remove(instanceName string, flags *RemoveFlags) error {
	missionControlUrl := flags.MissionControlDetails.Url + "api/v1/instances/" + instanceName
	httpClientDetails := utils.GetMissionControlHttpClientDetails(flags.MissionControlDetails)
	resp, body, err := ioutils.SendDelete(missionControlUrl, nil, httpClientDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 204 {
		return cliutils.CheckError(errors.New(resp.Status + ". " + utils.ReadMissionControlHttpMessage(body)))
	}
	fmt.Println("Mission Control response: " + resp.Status)
	return nil
}
Exemplo n.º 3
0
func AttachLic(instanceName string, flags *AttachLicFlags) error {
	prepareLicenseFile(flags.LicensePath, flags.Override)
	postContent := utils.LicenseRequestContent{
		Name:   instanceName,
		NodeID: flags.NodeId,
		Deploy: flags.Deploy}
	requestContent, err := json.Marshal(postContent)
	if err != nil {
		return cliutils.CheckError(errors.New("Failed to marshal json. " + cliutils.GetDocumentationMessage()))
	}
	missionControlUrl := flags.MissionControlDetails.Url + "api/v1/buckets/" + flags.BucketId + "/licenses"
	httpClientDetails := utils.GetMissionControlHttpClientDetails(flags.MissionControlDetails)
	resp, body, err := ioutils.SendPost(missionControlUrl, requestContent, httpClientDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		if flags.LicensePath != "" {
			os.Remove(flags.LicensePath)
		}
		return cliutils.CheckError(errors.New(resp.Status + ". " + utils.ReadMissionControlHttpMessage(body)))
	}
	fmt.Println("Mission Control response: " + resp.Status)
	if flags.LicensePath == "" {
		var m Message
		m, err = extractJsonValue(body)
		if err != nil {
			return err
		}
		requestContent, err = json.Marshal(m)
		err = cliutils.CheckError(err)
		if err != nil {
			return err
		}
		fmt.Println(string(requestContent))
	} else {
		var licenseKey []byte
		licenseKey, err = getLicenseFromJson(body)
		if err != nil {
			return err
		}
		err = saveLicense(flags.LicensePath, licenseKey)
	}
	return nil
}
Exemplo n.º 4
0
func DetachLic(instanceName string, flags *DetachLicFlags) error {
	bucketId := flags.BucketId
	postContent := utils.LicenseRequestContent{
		Name:   instanceName,
		NodeID: flags.NodeId}
	requestContent, err := json.Marshal(postContent)
	if err != nil {
		return cliutils.CheckError(errors.New("Failed to marshal json. " + cliutils.GetDocumentationMessage()))
	}
	missionControlUrl := flags.MissionControlDetails.Url + "api/v1/buckets/" + bucketId + "/licenses"
	httpClientDetails := utils.GetMissionControlHttpClientDetails(flags.MissionControlDetails)
	resp, body, err := ioutils.SendDelete(missionControlUrl, requestContent, httpClientDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New(resp.Status + ". " + utils.ReadMissionControlHttpMessage(body)))
	}
	fmt.Println("Mission Control response: " + resp.Status)
	return nil
}