0

With reference to the document below, I am trying to create a secret at a repository level for GitHub actions.

https://docs.github.com/en/rest/reference/actions (Create or update a repository secret)

So far I have written the following code and I am getting 500 error. Not sure what I am missing

    SodiumJava sodiumJava = new SodiumJava();
    LazySodiumJava lazySodium = new LazySodiumJava(sodiumJava);

    Key key = lazySodium.keygen(AEAD.Method.CHACHA20_POLY1305);
    byte[] nPub = lazySodium.nonce(AEAD.CHACHA20POLY1305_NPUBBYTES);

    //Step 1 is password.
    String password = "password";

    //Step 2 is to encrypt value
    String encrypted_value = lazySodium.encrypt(
            password,
            null,
            nPub,
            key,
            AEAD.Method.CHACHA20_POLY1305);

   //Step 3 is to get the encoded value.
    String encodedValue = new String(Base64.encodeBase64(encrypted_value.getBytes()));

    Map<String, String> map = new HashMap<>();
    map.put("encrypted_value", encodedValue);
    map.put("key_id", "1");
    map.put("visibility", "all");
    final HttpEntity<?> bodyThis = new HttpEntity<>(map, headers);
    String urlTest = "https://someurl***/repos/owner/repo_name/actions/secrets/secret_name";
    ResponseEntity<Object> demo = restTemplate.exchange(urlTest, HttpMethod.PUT, bodyThis, new ParameterizedTypeReference<Object>() {
    });
Kampassi
  • 123
  • 7
  • I've done something similar in python [here](https://github.com/GuillaumeFalourd/formulas-github/blob/master/github/add/secret/src/formula/formula.py) if you want to take a look (that's actually a CLI command line to add secrets to a github repository). – GuiFalourd Mar 30 '22 at 13:14
  • You can also do it using the Github CLI (as suggested [here](https://stackoverflow.com/questions/68967762/how-to-create-a-github-repository-secret-encrypt-it-using-bash-on-ubuntu)) – GuiFalourd Mar 30 '22 at 13:45

0 Answers0