Example #1
0
func identify() {
	tokenPayload := struct {
		Fingerprint string
	}{base64.StdEncoding.EncodeToString(client.Fingerprint())}

	log.WithFields(
		log.Fields{"fingerprint": tokenPayload.Fingerprint}).Debug("Identify")

	var identifyResult TokenChallenge
	// Identify - send fingerprint
	resp, err := napping.Post("http://localhost:8080/identify", &tokenPayload,
		&identifyResult, nil)
	if err != nil {
		log.Fatal(err)
	}

	if resp.Status() == http.StatusNotFound {
		log.Fatal("Identify - not registered")
		return
	}

	// Replace the token with the decrypted version
	identifyResult.Decrypt()

	test := make(map[string]string)
	resp, _ = napping.Post("http://localhost:8080/identify/token",
		&identifyResult, test, nil)
	if resp.Status() == 200 {
		log.Debug("Identify/Token - success")
	} else {
		log.Fatal("Identify/Token - failure")
	}
}
Example #2
0
func registerCommit(c *cli.Context, deployKey, commitSha, image string) {
	url := fmt.Sprintf("http://%s/deploy/register", c.GlobalString("api-endpoint"))

	var payload struct {
		DeployKey string          `json:"deploy_key"`
		CommitSha string          `json:"commit_sha"`
		Manifest  ServiceManifest `json:"manifest"`
	}

	payload.DeployKey = deployKey
	payload.CommitSha = commitSha

	data, err := ioutil.ReadFile(c.String("manifest-file"))
	if err != nil {
		log.Panic("mikro-cli: register-commit: cannot read manifest: ", err)
	}
	err = yaml.Unmarshal(data, &payload.Manifest)
	if err != nil {
		log.Panic("mikro-cli: register-commit: cannot decode manifest: ", err)
	}

	payload.Manifest.Image = image
	_, err = napping.Post(url, &payload, nil, nil)
	if err != nil {
		log.Panic("mikro-cli: register-commit: register failed: ", err)
	}
}
Example #3
0
// do is an easy function for performing requests against Mandrill's API.
func do(url string, data interface{}, result interface{}) error {

	url = "https://mandrillapp.com/api/1.0" + url

	resp, err := napping.Post(url, &data, &result, nil)
	if resp.Status() == 200 {
		return nil
	}

	fmt.Println(err)
	return err
}
Example #4
0
func registerToken(tc TokenChallenge) {
	tc.Decrypt()
	resp, _ := napping.Post("http://localhost:8080/register/token", &tc,
		nil, nil)

	if resp.Status() == http.StatusCreated {
		log.Debug("Register - success")
	} else if resp.Status() == http.StatusForbidden {
		log.Fatal("Register - user with the same fingerprint already registered")
	} else {
		log.WithFields(log.Fields{"status": resp.Status()}).Fatal("Register - unknown status")
	}
}
Example #5
0
func register() {
	pkPayload := struct {
		PublicKey string
	}{string(pgp.ToArmor(client.PublicKey(), pgp.PGPPublicKey))}
	var pkResult TokenChallenge
	log.WithFields(log.Fields{"PublicKey": pkPayload.PublicKey}).Debug("Register")

	resp, err := napping.Post("http://localhost:8080/register", &pkPayload,
		&pkResult, nil)
	if err != nil {
		log.Fatal(err)
	}

	if resp.Status() == http.StatusAccepted {
		log.WithFields(log.Fields{"encToken": pkResult.Token}).Debug("Register - challenge received")
	} else {
		log.WithFields(log.Fields{"status": resp.Status()}).Fatal("Register - unknown status")
	}

	registerToken(pkResult)
}
Example #6
0
func cmdPush(c *cli.Context) {
	url := fmt.Sprintf("http://%s/deploy/upload", c.GlobalString("api-endpoint"))

	var payload struct {
		DeployKey string `json:"deploy_key"`
	}

	payload.DeployKey = c.String("deploy-key")

	var response struct {
		AccessKey string `json:"access_key_id"`
		SecretKey string `json:"secret_access_key"`
		Bucket    string `json:"bucket"`
		Region    string `json:"region"`
		Name      string `json:"name"`
	}

	_, err := napping.Post(url, &payload, &response, nil)
	if err != nil {
		log.Panic("mikro-cli: push: upload-request: ", err)
	}

	options := s3.DriverParameters{
		AccessKey: response.AccessKey,
		SecretKey: response.SecretKey,
		Bucket:    response.Bucket,
		Region:    aws.GetRegion(fmt.Sprint(response.Region)),
		ChunkSize: 5 << 21,
		Secure:    true,
	}

	ctx := context.Background()

	driver, err := s3.New(options)
	registry, err := storage.NewRegistry(ctx, driver)

	imageName := c.Args()[0]
	repo, tag := parsers.ParseRepositoryTag(imageName)

	fmt.Printf("repo: %s tag: %s\n", repo, tag)

	bundle, err := NewImageBundle(repo, tag)
	if err != nil {
		log.Panic("mikro-cli: push: cannot export image: ", err)
	}
	defer bundle.Close()

	privateKey, err := libtrust.GenerateECP256PrivateKey()

	dgst, err := pushImageToRegistry(ctx, response.Name,
		c.String("commit-sha"),
		repo, tag,
		bundle,
		privateKey,
		registry)
	fmt.Printf("Pushed image %s as %s@%s\n", imageName, response.Name, dgst)

	// FIXME: we want to use the dgst here, but we can't since ECS doesn't
	// support it yet.
	registerCommit(c, c.String("deploy-key"), c.String("commit-sha"),
		fmt.Sprintf("private:%s:%s", response.Name,
			c.String("commit-sha")))
}