Esempio n. 1
0
//Show requests account details from Kumoru and marshals the data into the Account type.
func (a *Account) Show() (*Account, *http.Response, []error) {
	k := kumoru.New()

	k.Get(fmt.Sprintf("%v/v1/accounts/%v", k.EndPoint.Authorization, a.Email))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if len(errs) > 0 {
		return a, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
		return a, resp, errs
	}

	err := json.Unmarshal([]byte(body), &a)

	if err != nil {
		errs = append(errs, err)
		return a, resp, errs
	}

	return a, resp, nil
}
Esempio n. 2
0
//Show is a method on an Application which retrieves a particular Application from Kumoru.
func (a *Application) Show() (*Application, *http.Response, []error) {
	k := kumoru.New()

	k.Get(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if len(errs) > 0 {
		return a, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	err := json.Unmarshal([]byte(body), &a)

	if err != nil {
		errs = append(errs, fmt.Errorf("%s", err))
		return a, resp, errs
	}

	return a, resp, nil
}
Esempio n. 3
0
//List retreives all secrets a role has access to
func List() ([]*Secret, *http.Response, []error) {
	apps := []*Secret{}
	k := kumoru.New()

	k.Get(fmt.Sprintf("%s/v1/secrets/", k.EndPoint.Authorization))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if len(errs) > 0 {
		return nil, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	err := json.Unmarshal([]byte(body), &apps)

	if err != nil {
		errs = append(errs, fmt.Errorf("%s", err))
	}

	return apps, resp, nil
}
Esempio n. 4
0
//CreateAcct requests a particular account be made in Kumoru.
//It returns the updated Account.
func (a *Account) CreateAcct(password string) (*Account, *http.Response, []error) {
	k := kumoru.New()

	k.Put(fmt.Sprintf("%s/v1/accounts/%s", k.EndPoint.Authorization, a.Email))
	k.Send(fmt.Sprintf("given_name=%s&surname=%s&password=%s", a.GivenName, a.Surname, password))

	resp, body, errs := k.End()

	if len(errs) > 0 {
		return a, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	err := json.Unmarshal([]byte(body), &a)

	if err != nil {
		errs = append(errs, err)
		return a, resp, errs
	}

	return a, resp, nil
}
Esempio n. 5
0
//Create is a method on an Application which requests that the application be drafted in Kumoru.
func (a *Application) Create() (*Application, *http.Response, []error) {
	var errs []error
	k := kumoru.New()

	k.Post(fmt.Sprintf("%s/v1/applications/", k.EndPoint.Application))
	k.TargetType = "json"
	s, err := json.Marshal(*a)

	if err != nil {
		errs = append(errs, fmt.Errorf("%s", err))
		return a, nil, errs
	}

	k.RawString = string(s)
	k.SignRequest(true)

	resp, body, errs := k.End()

	if len(errs) > 0 {
		return a, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	err = json.Unmarshal([]byte(body), &a)

	if err != nil {
		errs = append(errs, err)
		return a, resp, errs
	}

	return a, resp, nil
}
Esempio n. 6
0
// List retrieves a list of Applications a role has access to.
func List() (*http.Response, string, []error) {
	k := kumoru.New()

	k.Get(fmt.Sprintf("%s/v1/applications/", k.EndPoint.Application))
	k.SignRequest(true)
	return k.End()
}
Esempio n. 7
0
// Patch is a method on an application which will modify an Application.
func (a *Application) Patch(certificates, name, image, metaData string, envVars, rules, ports, sslPorts []string) (*http.Response, string, []error) {
	k := kumoru.New()

	k.Patch(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
	k.Send(genParameters(certificates, name, image, metaData, envVars, rules, ports, sslPorts))
	k.SignRequest(true)
	return k.End()
}
Esempio n. 8
0
//ResetPassword requests the password be reset for a given Account.
func (a *Account) ResetPassword() (*Account, *http.Response, []error) {
	k := kumoru.New()

	k.Get(fmt.Sprintf("%v/v1/accounts/%v/password/resets/", k.EndPoint.Authorization, a.Email))
	resp, _, errs := k.End()

	return a, resp, errs
}
Esempio n. 9
0
//GetTokens generates a new token(uuid), stores this token in Kumoru and retrieves the private half of the token.
func GetTokens(username, password string) (string, *http.Response, string, []error) {
	k := kumoru.New()

	token := uuid.New()

	k.Put(fmt.Sprintf("%v/v1/tokens/%v", k.EndPoint.Authorization, token))
	k.SetBasicAuth(username, password)
	resp, body, errs := k.End()

	return token, resp, body, errs
}
Esempio n. 10
0
//Find is a method which will search for Locations based on inputs
func (l *Location) Find() (string, []error) {
	k := kumoru.New()

	k.Get(l.buildFindPath(k.EndPoint.Location))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if resp.StatusCode != 200 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	return string(body), errs
}
Esempio n. 11
0
//Delete will request that a particular Location be removed
func (l *Location) Delete() []error {
	k := kumoru.New()

	k.Delete(fmt.Sprintf("%s/v1/locations/%s/%s", k.EndPoint.Location, l.Provider, l.Region))
	k.SignRequest(true)

	resp, _, errs := k.End()

	if resp.StatusCode != 204 {
		errs = append(errs, fmt.Errorf("s", resp.Status))
	}

	return errs
}
Esempio n. 12
0
//Create is a method which will request a Location be created
func (l *Location) Create() (string, []error) {
	k := kumoru.New()

	k.Put(fmt.Sprintf("%s/v1/locations/%s/%s", k.EndPoint.Location, l.Provider, l.Region))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if resp.StatusCode != 201 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	return string(body), errs
}
Esempio n. 13
0
// Patch is a method on an application which will modify an existing Application.
func (a *Application) Patch(patchedApplication *Application) (*Application, *http.Response, []error) {
	o, err := json.Marshal(a)
	if err != nil {
		return nil, nil, []error{err}
	}

	p, err := json.Marshal(patchedApplication)
	if err != nil {
		return nil, nil, []error{err}
	}

	patch, err := jsonpatch.CreatePatch([]byte(o), []byte(p))
	if err != nil {
		fmt.Printf("Error creating JSON patch:%v", err)
		return nil, nil, []error{err}
	}

	patchBytes, err := json.Marshal(patch)
	if err != nil {
		return nil, nil, []error{err}
	}
	k := kumoru.New()

	k.Logger.Debugf("Patch string: %s", patchBytes)

	k.Patch(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
	k.TargetType = "json-patch+json"
	k.RawString = string(string(patchBytes))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if len(errs) > 0 {
		return a, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	pApp := Application{}
	err = json.Unmarshal([]byte(body), &pApp)

	if err != nil {
		errs = append(errs, err)
		return a, resp, errs
	}

	return &pApp, resp, nil
}
Esempio n. 14
0
//Delete is a method on a Location that will remove Kumoru resources from the provider region
func (l *Location) Delete(uuid string) (*Location, *http.Response, []error) {
	k := kumoru.New()

	k.Delete(fmt.Sprintf("%v/v1/pools/%s", k.EndPoint.Pool, uuid))
	k.SignRequest(true)

	resp, _, errs := k.End()

	if errs != nil {
		return l, resp, errs
	}

	return l, resp, nil
}
Esempio n. 15
0
//Delete is a method on an Application which request an Application be deleted in Kumoru.
func (a *Application) Delete() (*Application, *http.Response, []error) {
	k := kumoru.New()

	k.Delete(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
	k.SignRequest(true)

	resp, _, errs := k.End()

	if len(errs) > 0 {
		return a, resp, errs
	}

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	return a, resp, nil
}
Esempio n. 16
0
// Show is a method will call the appropriate URI and return a specific deployment
func (d *Deployment) Show(applicationUuid, deploymentUuid string) (*Deployment, *http.Response, []error) {
	deployment := Deployment{}
	k := kumoru.New()

	k.Get(fmt.Sprintf("%s/v1/applications/%s/deployments/%s", k.EndPoint.Application, applicationUuid, deploymentUuid))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if errs != nil {
		return &deployment, resp, errs
	}

	err := json.Unmarshal([]byte(body), &deployment)

	if err != nil {
		errs = append(errs, err)
		return &deployment, resp, errs
	}

	return &deployment, resp, errs
}
Esempio n. 17
0
// Show is a Secret method will call the appropriate URI and return a specific secret
func (s *Secret) Show(secretUuid *string) (*Secret, *http.Response, []error) {
	secret := Secret{}
	k := kumoru.New()

	k.Get(fmt.Sprintf("%s/v1/secrets/%s", k.EndPoint.Authorization, *secretUuid))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if errs != nil {
		return &secret, resp, errs
	}

	err := json.Unmarshal([]byte(body), &secret)

	if err != nil {
		errs = append(errs, err)
		return &secret, resp, errs
	}

	return &secret, resp, errs
}
Esempio n. 18
0
// Create is a Secret method that will create a secret with the specified value
func (s *Secret) Create() (*Secret, *http.Response, []error) {
	k := kumoru.New()

	k.Post(fmt.Sprintf("%v/v1/secrets/", k.EndPoint.Authorization))
	k.Send(genParameters(s.Value, s.Labels))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if errs != nil {
		return s, resp, errs
	}

	err := json.Unmarshal([]byte(body), &s)

	if err != nil {
		errs = append(errs, err)
		return s, resp, errs
	}

	return s, resp, nil
}
Esempio n. 19
0
//Show is a method on a Location that will show all the details of a particular Location
func (l *Location) Show() (*Location, *http.Response, []error) {
	k := kumoru.New()

	k.Get(fmt.Sprintf("%v/v1/pools/%s", k.EndPoint.Pool, l.Uuid))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
		return l, resp, errs
	}

	err := json.Unmarshal([]byte(body), l)

	if err != nil {
		errs = append(errs, err)
		return l, resp, errs
	}

	return l, resp, errs

}
Esempio n. 20
0
//List is a method on a Location that will list all Locations an user has access to
func (l *Location) List() (*[]Location, *http.Response, []error) {
	locations := []Location{}
	k := kumoru.New()

	k.Get(fmt.Sprintf("%v/v1/pools/", k.EndPoint.Pool))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
		return &locations, resp, errs
	}

	err := json.Unmarshal([]byte(body), &locations)

	if err != nil {
		errs = append(errs, err)
		return &locations, resp, errs
	}

	return &locations, resp, nil
}
Esempio n. 21
0
// Create is a method on a Location that will create Kumoru resources in the provider region
func (l *Location) Create() (*Location, *http.Response, []error) {
	k := kumoru.New()

	k.Post(fmt.Sprintf("%v/v1/pools/", k.EndPoint.Pool))
	k.Send(fmt.Sprintf("location=%s", url.QueryEscape(l.Identifier)))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if resp.StatusCode >= 400 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
		return l, resp, errs
	}

	err := json.Unmarshal([]byte(body), &l)

	if err != nil {
		errs = append(errs, err)
		return l, resp, errs
	}

	return l, resp, nil
}
Esempio n. 22
0
// Find resources that are accesible to the requester
func Find(rType, action, UUID string, wrappedRequest *http.Request) (*http.Response, string, []error) {
	params := "select_by="
	params += fmt.Sprintf("type=%s,", rType)
	params += fmt.Sprintf("action=%s", action)
	if UUID != "" {
		params += fmt.Sprintf(",uuid=%s,", UUID)
	}

	fmt.Println("Params: ", params)

	k := kumoru.New()
	k.Get(fmt.Sprintf("%s/v1/resources/", k.EndPoint.Authorization))
	k.Query(params)
	if wrappedRequest != nil {
		k.ProxyRequest(wrappedRequest)
		if wrappedRequest.Header.Get("X-Kumoru-Context") != "" {
			k.SetHeader("X-Kumoru-Context", wrappedRequest.Header.Get("X-Kumoru-Context"))
		}
	}
	k.SignRequest(true)

	return k.End()
}